getopt completion

pull/1985/head
Emily Grace Seville 2021-11-23 17:13:52 +10:00 committed by GitHub
parent 447c89aa0e
commit 8cdd226cf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 0 deletions

View File

@ -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