Merge pull request #2387 from 1ace/feature/bash-completion

bash completion
This commit is contained in:
Drew DeVault 2018-07-30 13:11:20 -04:00 committed by GitHub
commit 878d1ddd07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 230 additions and 0 deletions

46
completions/bash/sway Normal file
View file

@ -0,0 +1,46 @@
# sway(1) completion
_sway()
{
local cur prev
_get_comp_words_by_ref cur prev
short=(
-h
-c
-C
-d
-v
-V
)
long=(
--help
--config
--validate
--debug
--version
--verbose
--get-socketpath
)
case $prev in
-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 _sway sway

48
completions/bash/swayidle Normal file
View file

@ -0,0 +1,48 @@
# swaymsg(1) completion
_swayidle()
{
local cur prev
_get_comp_words_by_ref -n : cur prev
local prev2=${COMP_WORDS[COMP_CWORD-2]}
local prev3=${COMP_WORDS[COMP_CWORD-3]}
events=(
'timeout'
'before-sleep'
)
short=(
-h
-d
)
if [ "$prev" = timeout ]; then
# timeout <timeout>
return
elif [ "$prev2" = timeout ]; then
# timeout <timeout> <timeout command>
COMPREPLY=($(compgen -c -- "$cur"))
return
elif [ "$prev3" = timeout ]; then
# timeout <timeout> <timeout command> [resume <resume command>]
COMPREPLY=(resume)
# optional argument; no return here as user may skip 'resume'
fi
case "$prev" in
resume)
COMPREPLY=($(compgen -c -- "$cur"))
return
;;
before-sleep)
COMPREPLY=($(compgen -c -- "$cur"))
return
;;
esac
COMPREPLY+=($(compgen -W "${events[*]}" -- "$cur"))
COMPREPLY+=($(compgen -W "${short[*]}" -- "$cur"))
} &&
complete -F _swayidle swayidle

66
completions/bash/swaylock Normal file
View file

@ -0,0 +1,66 @@
# swaylock(1) completion
_swaylock()
{
local cur prev
_get_comp_words_by_ref -n : cur prev
short=(
-h
-c
-s
-t
-v
-i
-u
-f
)
long=(
--help
--color
--scaling
--tiling
--version
--image
--no-unlock-indicator
--daemonize
)
scaling=(
'stretch'
'fill'
'fit'
'center'
'tile'
)
case $prev in
-c|--color)
return
;;
--scaling)
COMPREPLY=($(compgen -W "${scaling[*]}" -- "$cur"))
return
;;
-i|--image)
if grep -q : <<< "$cur"; then
output="${cur%%:*}:"
cur="${cur#*:}"
else
output=
fi
COMPREPLY=($(compgen -f -- "$cur"))
return
;;
esac
if [[ $cur == --* ]]; then
COMPREPLY=($(compgen -W "${long[*]}" -- "$cur"))
else
COMPREPLY=($(compgen -W "${short[*]}" -- "$cur"))
COMPREPLY+=($(compgen -W "${long[*]}" -- "$cur"))
fi
} &&
complete -F _swaylock swaylock

57
completions/bash/swaymsg Normal file
View file

@ -0,0 +1,57 @@
# swaymsg(1) completion
_swaymsg()
{
local cur prev
_get_comp_words_by_ref cur prev
types=(
'get_workspaces'
'get_seats'
'get_inputs'
'get_outputs'
'get_tree'
'get_marks'
'get_bar_config'
'get_version'
'get_clipboard'
)
short=(
-h
-q
-r
-s
-t
-v
)
long=(
--help
--quiet
--raw
--socket
--type
--verbose
)
case $prev in
-s|--socket)
_filedir
return
;;
-t|--type)
COMPREPLY=($(compgen -W "${types[*]}" -- "$cur"))
return
;;
esac
if [[ $cur == --* ]]; then
COMPREPLY=($(compgen -W "${long[*]}" -- "$cur"))
else
COMPREPLY=($(compgen -W "${short[*]}" -- "$cur"))
COMPREPLY+=($(compgen -W "${long[*]}" -- "$cur"))
fi
} &&
complete -F _swaymsg swaymsg

View file

@ -190,3 +190,15 @@ if (get_option('zsh_completions'))
install_data(zsh_files, install_dir: zsh_install_dir)
endif
if (get_option('bash_completions'))
bash_files = files(
'completions/bash/sway',
'completions/bash/swayidle',
'completions/bash/swaylock',
'completions/bash/swaymsg',
)
bash_install_dir = datadir + '/bash-completion/completions'
install_data(bash_files, install_dir: bash_install_dir)
endif

View file

@ -1,4 +1,5 @@
option('sway_version', type : 'string', description: 'The version string reported in `sway --version`.')
option('default_wallpaper', type: 'boolean', value: true, description: 'Install the default wallpaper.')
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('enable-xwayland', type: 'boolean', value: true, description: 'Enable support for X11 applications')