completion/getopt: `shfmt`

pull/1985/head^2
John D Pell 2022-01-16 11:28:59 -08:00
parent 8cdd226cf3
commit 9d4b23b992
1 changed files with 29 additions and 27 deletions

View File

@ -1,32 +1,34 @@
__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')
# shellcheck shell=bash
local SHELL_ARGS=('sh' 'bash' 'csh' 'tcsh')
function _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 current=$2
local previous=$3
local SHELL_ARGS=('sh' 'bash' 'csh' 'tcsh')
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
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
complete -F _getopt getopt