Skip to content

Commit

Permalink
Terminal completions (#44)
Browse files Browse the repository at this point in the history
* Added ZSH completions

* Fixed single quote ending string

* Added Bash completions

* Added bash to meson.build

* Added bash variable to meson_options.txt

* Added fish shell completions
  • Loading branch information
ErikReider authored Dec 24, 2021
1 parent bf9309b commit e85c2f5
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 2 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
pkg
build
SwayNotificationCenter
swaync
swaync*
./swaync
./swaync*
./src/swaync
./src/swaync*
swaync-git*
38 changes: 38 additions & 0 deletions completions/bash/swaync
Original file line number Diff line number Diff line change
@@ -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
52 changes: 52 additions & 0 deletions completions/bash/swaync-client
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions completions/fish/swaync-client.fish
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions completions/fish/swaync.fish
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions completions/zsh/_swaync
Original file line number Diff line number Diff line change
@@ -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' \
13 changes: 13 additions & 0 deletions completions/zsh/_swaync-client
Original file line number Diff line number Diff line change
@@ -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]' \
3 changes: 3 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -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.')
53 changes: 53 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e85c2f5

Please sign in to comment.