2022-03-07 20:03:46 +00:00
|
|
|
_my-app() {
|
2023-01-23 18:20:09 +00:00
|
|
|
local i cur prev opts cmd
|
2022-03-07 20:03:46 +00:00
|
|
|
COMPREPLY=()
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
cmd=""
|
|
|
|
opts=""
|
|
|
|
|
|
|
|
for i in ${COMP_WORDS[@]}
|
|
|
|
do
|
2022-09-28 14:33:31 +00:00
|
|
|
case "${cmd},${i}" in
|
|
|
|
",$1")
|
2022-03-07 20:03:46 +00:00
|
|
|
cmd="my__app"
|
|
|
|
;;
|
2022-09-28 21:33:59 +00:00
|
|
|
my__app,help)
|
|
|
|
cmd="my__app__help"
|
2022-03-07 20:03:46 +00:00
|
|
|
;;
|
2022-09-28 21:33:59 +00:00
|
|
|
my__app,test)
|
|
|
|
cmd="my__app__test"
|
|
|
|
;;
|
|
|
|
my__app__help,help)
|
|
|
|
cmd="my__app__help__help"
|
|
|
|
;;
|
|
|
|
my__app__help,test)
|
|
|
|
cmd="my__app__help__test"
|
2022-03-07 20:03:46 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case "${cmd}" in
|
|
|
|
my__app)
|
2022-08-29 20:09:06 +00:00
|
|
|
opts="-C -c -h -V --conf --config --help --version [file] first second test help"
|
2022-03-07 20:03:46 +00:00
|
|
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
case "${prev}" in
|
|
|
|
*)
|
|
|
|
COMPREPLY=()
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
my__app__help)
|
2022-08-25 05:44:07 +00:00
|
|
|
opts="test help"
|
2022-03-07 20:03:46 +00:00
|
|
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
case "${prev}" in
|
|
|
|
*)
|
|
|
|
COMPREPLY=()
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
|
|
return 0
|
|
|
|
;;
|
2022-08-25 05:44:07 +00:00
|
|
|
my__app__help__help)
|
|
|
|
opts=""
|
|
|
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
case "${prev}" in
|
|
|
|
*)
|
|
|
|
COMPREPLY=()
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
my__app__help__test)
|
|
|
|
opts=""
|
|
|
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
case "${prev}" in
|
|
|
|
*)
|
|
|
|
COMPREPLY=()
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
|
|
return 0
|
|
|
|
;;
|
2022-03-07 20:03:46 +00:00
|
|
|
my__app__test)
|
|
|
|
opts="-h -V --case --help --version"
|
|
|
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
case "${prev}" in
|
|
|
|
--case)
|
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
COMPREPLY=()
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-01-02 12:31:50 +00:00
|
|
|
if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
|
|
|
|
complete -F _my-app -o nosort -o bashdefault -o default my-app
|
|
|
|
else
|
|
|
|
complete -F _my-app -o bashdefault -o default my-app
|
|
|
|
fi
|