diff --git a/meson.build b/meson.build index e11618f03..2bd67399d 100644 --- a/meson.build +++ b/meson.build @@ -132,6 +132,8 @@ else have_systemd = false endif +bash_completion = dependency('bash-completion', required: false) + if get_option('man') xsltproc = find_program('xsltproc') diff --git a/src/extensions-tool/completion/bash/gnome-extensions b/src/extensions-tool/completion/bash/gnome-extensions new file mode 100644 index 000000000..e0286729b --- /dev/null +++ b/src/extensions-tool/completion/bash/gnome-extensions @@ -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 diff --git a/src/extensions-tool/meson.build b/src/extensions-tool/meson.build index 8e8f818cb..edd445a5e 100644 --- a/src/extensions-tool/meson.build +++ b/src/extensions-tool/meson.build @@ -26,3 +26,9 @@ executable('gnome-extensions', dependencies: [gio_dep, gio_unix_dep], install: true ) + +if bash_completion.found() + install_data('completion/bash/gnome-extensions', + install_dir: bash_completion.get_pkgconfig_variable('completionsdir') + ) +endif