diff --git a/.gitignore b/.gitignore index 5203dc2..da59f95 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,8 @@ pkg build SwayNotificationCenter -swaync -swaync* +./swaync +./swaync* +./src/swaync +./src/swaync* +swaync-git* diff --git a/completions/bash/swaync b/completions/bash/swaync new file mode 100644 index 0000000..7f88037 --- /dev/null +++ b/completions/bash/swaync @@ -0,0 +1,38 @@ +_swaync() { + local cur prev + _get_comp_words_by_ref cur prev + + short=( + -h + -s + -c + ) + + long=( + --help + --style + --config + ) + case $prev in + -s | --style) + _filedir + return + ;; + -c | --config) + _filedir + return + ;; + esac + + if [[ $cur == --* ]]; then + COMPREPLY=($(compgen -W "${long[*]}" -- "$cur")) + elif [[ $cur == -* ]]; then + COMPREPLY=($(compgen -W "${short[*]}" -- "$cur")) + COMPREPLY+=($(compgen -W "${long[*]}" -- "$cur")) + else + COMPREPLY=($(compgen -W "${short[*]}" -- "$cur")) + COMPREPLY+=($(compgen -W "${long[*]}" -- "$cur")) + COMPREPLY+=($(compgen -c -- "$cur")) + fi + +} && complete -F _swaync swaync diff --git a/completions/bash/swaync-client b/completions/bash/swaync-client new file mode 100644 index 0000000..a078262 --- /dev/null +++ b/completions/bash/swaync-client @@ -0,0 +1,52 @@ +_swaync-client() { + local cur prev + _get_comp_words_by_ref cur prev + + short=( + -h + -R + -rs + -t + -d + -D + -c + -C + -sw + -s + ) + + long=( + --help + --reload-config + --reload-css + --toggle-panel + --toggle-dnd + --get-dnd + --count + --close-all + --skip-wait + --subscribe + ) + case $prev in + -s | --style) + _filedir + return + ;; + -c | --config) + _filedir + return + ;; + esac + + if [[ $cur == --* ]]; then + COMPREPLY=($(compgen -W "${long[*]}" -- "$cur")) + elif [[ $cur == -* ]]; then + COMPREPLY=($(compgen -W "${short[*]}" -- "$cur")) + COMPREPLY+=($(compgen -W "${long[*]}" -- "$cur")) + else + COMPREPLY=($(compgen -W "${short[*]}" -- "$cur")) + COMPREPLY+=($(compgen -W "${long[*]}" -- "$cur")) + COMPREPLY+=($(compgen -c -- "$cur")) + fi + +} && complete -F _swaync-client swaync-client diff --git a/completions/fish/swaync-client.fish b/completions/fish/swaync-client.fish new file mode 100644 index 0000000..9a46b95 --- /dev/null +++ b/completions/fish/swaync-client.fish @@ -0,0 +1,11 @@ +complete -f -c swaync-client +complete -c swaync-client -s h -l help --description "Show help options" +complete -c swaync-client -s R -l reload-config --description "Reload the config file" -r +complete -c swaync-client -s rs -l reload-css --description "Reload the css file. Location change requires restart" -r +complete -c swaync-client -s t -l toggle-panel --description "Toggle the notificaion panel" -r +complete -c swaync-client -s d -l toggle-dnd --description "Toggle and print the current dnd state" -r +complete -c swaync-client -s D -l get-dnd --description "Print the current dnd state" -r +complete -c swaync-client -s c -l count --description "Print the current notificaion count" -r +complete -c swaync-client -s C -l close-all --description "Closes all notifications" -r +complete -c swaync-client -s sw -l skip-wait --description "Doesn't wait when swaync hasn't been started" -r +complete -c swaync-client -s s -l subscribe --description "Subscribe to notificaion add and close events" -r diff --git a/completions/fish/swaync.fish b/completions/fish/swaync.fish new file mode 100644 index 0000000..1534cb4 --- /dev/null +++ b/completions/fish/swaync.fish @@ -0,0 +1,4 @@ +complete -f -c swaync +complete -c swaync -s h -l help --description "Show help options" +complete -c swaync -s s -l style --description "Use a custom Stylesheet file" -r +complete -c swaync -s c -l config --description "Use a custom config file" -r diff --git a/completions/zsh/_swaync b/completions/zsh/_swaync new file mode 100644 index 0000000..d1cc73f --- /dev/null +++ b/completions/zsh/_swaync @@ -0,0 +1,6 @@ +#compdef swaync + +_arguments -s \ + '(-h --help)'{-h,--help}'[Show help options]' \ + '(-s --style)'{-s,--style}'[Use a custom Stylesheet file]:files:_files' \ + '(-c --config)'{-c,--config}'[Use a custom config file]:files:_files' \ diff --git a/completions/zsh/_swaync-client b/completions/zsh/_swaync-client new file mode 100644 index 0000000..f28e96d --- /dev/null +++ b/completions/zsh/_swaync-client @@ -0,0 +1,13 @@ +#compdef swaync-client + +_arguments -s \ + '(-h --help)'{-h,--help}'[Show help options]' \ + '(-R --reload-config)'{-R --reload-config}'[Reload the config file]' \ + '(-rs --reload-css)'{-rs --reload-css}'[Reload the css file. Location change requires restart]' \ + '(-t --toggle-panel)'{-t --toggle-panel}'[Toggle the notificaion panel]' \ + '(-d --toggle-dnd)'{-d --toggle-dnd}'[Toggle and print the current dnd state]' \ + '(-D --get-dnd)'{-D --get-dnd}'[Print the current dnd state]' \ + '(-c --count)'{-c --count}'[Print the current notificaion count]' \ + '(-C --close-all)'{-C --close-all}'[Closes all notifications]' \ + '(-sw --skip-wait)'{-sw --skip-wait}"[Doesn't wait when swaync hasn't been started]" \ + '(-s --subscribe)'{-s --subscribe}'[Subscribe to notificaion add and close events]' \ diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..b5a477e --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,3 @@ +option('zsh-completions', type: 'boolean', value: true, description: 'Install zsh shell completions.') +option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.') +option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions.') diff --git a/src/meson.build b/src/meson.build index 6309570..6903e89 100644 --- a/src/meson.build +++ b/src/meson.build @@ -59,3 +59,56 @@ executable('swaync-client', install_data('style.css', install_dir : join_paths(sysconfdir, 'xdg/swaync')) install_data('config.json', install_dir : join_paths(sysconfdir, 'xdg/swaync')) + +datadir = get_option('datadir') + +# Zsh completion +if get_option('zsh-completions') + zsh_files = files( + '../completions/zsh/_swaync', + '../completions/zsh/_swaync-client', + ) + zsh_install_dir = join_paths(datadir, 'zsh', 'site-functions') + + install_data(zsh_files, install_dir: zsh_install_dir) +endif + +# Bash completion +bash_comp = dependency('bash-completion', required: false) +if get_option('bash-completions') + bash_files = files( + '../completions/bash/swaync', + '../completions/bash/swaync-client', + ) + + if bash_comp.found() + bash_install_dir = bash_comp.get_variable( + pkgconfig: 'completionsdir', + pkgconfig_define: ['datadir', datadir] + ) + else + bash_install_dir = join_paths(datadir, 'bash-completion', 'completions') + endif + + install_data(bash_files, install_dir: bash_install_dir) +endif + +# Fish completion +fish_comp = dependency('fish', required: false) +if get_option('fish-completions') + fish_files = files( + '../completions/fish/swaync.fish', + '../completions/fish/swaync-client.fish', + ) + + if fish_comp.found() + fish_install_dir = fish_comp.get_variable( + pkgconfig: 'completionsdir', + pkgconfig_define: ['datadir', datadir] + ) + else + fish_install_dir = join_paths(datadir, 'fish', 'vendor_completions.d') + endif + + install_data(fish_files, install_dir: fish_install_dir) +endif