bash tab completion for launcher + discourse-setup ()

add tab completion for launcher and discourse-setup.

For launcher, offers command (e.g., rebuild, start) and then offers yml files from containers directory. After that switches (e.g., --run-image) are offered. (Will not offer switches except in final position, sorry.)

discourse-setup offers switches (e.g., --two-container).

discourse-docter has no command line arguments.
This commit is contained in:
Jay Pfaffman 2024-08-18 15:31:55 -07:00 committed by GitHub
parent 9f80d83b32
commit b7a6888a2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,44 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CONTAINER_DIR=$DIR/../containers/
_containers_compgen_filenames() {
local cur="$1"
compgen -G "$CONTAINER_DIR$cur*.yml" -- $CONTAINER_DIR"$cur" | xargs -n 1 basename -s .yml
}
_launcher ()
{
local cur
switches='--skip-prereqs --docker-args --skip-mac-address --run-image'
commands='start stop restart destroy enter logs bootstrap run rebuild cleanup start-cmd'
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
case $COMP_CWORD in
1)
COMPREPLY=( $( compgen -W "$commands" -- $cur ) );;
2)
COMPREPLY=( $(_containers_compgen_filenames "$cur") ) ;;
*)
COMPREPLY=( $( compgen -W "$switches" -- $cur ) );;
esac
return 0
}
_discourse_setup()
{
local cur
switches='--debug --skip-rebuild --two-container --skip-connection-test'
cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "$switches" -- $cur ) )
return 0
}
complete -F _launcher launcher
complete -F _launcher ./launcher
complete -F _discourse_setup discourse-setup
complete -F _discourse_setup ./discourse-setup