completion/getopt: compat with v3.2
parent
9d4b23b992
commit
cd366fc8a5
|
|
@ -1,6 +1,10 @@
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
|
|
||||||
function _getopt() {
|
function _getopt() {
|
||||||
|
local IFS=$'\n'
|
||||||
|
local cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
|
local prev=${COMP_WORDS[COMP_CWORD-1]:-}
|
||||||
|
|
||||||
local OPTIONS=('-a' '--alternative'
|
local OPTIONS=('-a' '--alternative'
|
||||||
'-h' '--help'
|
'-h' '--help'
|
||||||
'-l' '--longoptions'
|
'-l' '--longoptions'
|
||||||
|
|
@ -15,18 +19,15 @@ function _getopt() {
|
||||||
|
|
||||||
local SHELL_ARGS=('sh' 'bash' 'csh' 'tcsh')
|
local SHELL_ARGS=('sh' 'bash' 'csh' 'tcsh')
|
||||||
|
|
||||||
local current=$2
|
case $prev in
|
||||||
local previous=$3
|
|
||||||
|
|
||||||
case $previous in
|
|
||||||
-s | --shell)
|
-s | --shell)
|
||||||
readarray -t COMPREPLY < <(compgen -W "${SHELL_ARGS[*]}" -- "$current")
|
read -d '' -ra COMPREPLY < <(compgen -W "${SHELL_ARGS[*]}" -- "$cur")
|
||||||
;;
|
;;
|
||||||
-n | --name)
|
-n | --name)
|
||||||
readarray -t COMPREPLY < <(compgen -A function -- "$current")
|
read -d '' -ra COMPREPLY < <(compgen -A function -- "$cur")
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
readarray -t COMPREPLY < <(compgen -W "${OPTIONS[*]}" -- "$current")
|
read -d '' -ra COMPREPLY < <(compgen -W "${OPTIONS[*]}" -- "$cur")
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue