From 8cdd226cf35e4e0b4afb7a9dd80a7bedd4237a34 Mon Sep 17 00:00:00 2001 From: Emily Grace Seville Date: Tue, 23 Nov 2021 17:13:52 +1000 Subject: [PATCH] getopt completion --- completion/available/getopt.completion.bash | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 completion/available/getopt.completion.bash diff --git a/completion/available/getopt.completion.bash b/completion/available/getopt.completion.bash new file mode 100644 index 00000000..45a10206 --- /dev/null +++ b/completion/available/getopt.completion.bash @@ -0,0 +1,32 @@ +__getopt() { + local OPTIONS=('-a' '--alternative' + '-h' '--help' + '-l' '--longoptions' + '-n' '--name' + '-o' '--options' + '-q' '--quiet' + '-Q' '--quiet-output' + '-s' '--shell' + '-T' '--test' + '-u' '--unquoted' + '-V' '--version') + + local SHELL_ARGS=('sh' 'bash' 'csh' 'tcsh') + + local current=$2 + local previous=$3 + + case $previous in + -s|--shell) + readarray -t COMPREPLY < <(compgen -W "${SHELL_ARGS[*]}" -- "$current") + ;; + -n|--name) + readarray -t COMPREPLY < <(compgen -A function -- "$current") + ;; + *) + readarray -t COMPREPLY < <(compgen -W "${OPTIONS[*]}" -- "$current") + ;; + esac +} + +complete -F __getopt getopt