extensions-tool: Add bash completion

Completions are clearly helpful, in particular for extension UUIDs
that are often lengthy strings containing random usernames.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/1234
This commit is contained in:
Florian Müllner 2018-08-28 04:38:23 +02:00
parent 07fad38a50
commit 0de5209cf1
3 changed files with 59 additions and 0 deletions

View File

@ -132,6 +132,8 @@ else
have_systemd = false have_systemd = false
endif endif
bash_completion = dependency('bash-completion', required: false)
if get_option('man') if get_option('man')
xsltproc = find_program('xsltproc') xsltproc = find_program('xsltproc')

View File

@ -0,0 +1,51 @@
# Check for bash
[ -z "$BASH_VERSION" ] && return
################################################################################
__gnome_extensions() {
local commands="version enable disable info list create"
local COMMAND=${COMP_WORDS[1]}
_init_completion -s || return
case "${COMP_CWORD}" in
1)
COMPREPLY=($(compgen -W "help $commands" -- "$2"))
return 0
;;
2)
case "$COMMAND" in
help)
COMPREPLY=($(compgen -W "$commands" -- "$2"))
return 0
;;
disable)
local list_opt=--enabled
;;&
enable)
local list_opt=--disabled
;;&
enable|disable|info)
COMPREPLY=($(compgen -W "`gnome-extensions list $list_opt`" -- "$2"))
return 0
;;
esac
;;
esac
# Stop if we are currently waiting for an option value
$split && return
# Otherwise, get the supported options for ${COMMAND} (if any)
COMPREPLY=($(compgen -W "$(_parse_help $1 "help $COMMAND")" -- "$2"))
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
}
################################################################################
complete -F __gnome_extensions gnome-extensions

View File

@ -26,3 +26,9 @@ executable('gnome-extensions',
dependencies: [gio_dep, gio_unix_dep], dependencies: [gio_dep, gio_unix_dep],
install: true install: true
) )
if bash_completion.found()
install_data('completion/bash/gnome-extensions',
install_dir: bash_completion.get_pkgconfig_variable('completionsdir')
)
endif