2022-03-07 20:03:46 +00:00
|
|
|
_my-app() {
|
|
|
|
local i cur prev opts cmds
|
|
|
|
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,some_cmd)
|
|
|
|
cmd="my__app__some_cmd"
|
2022-03-07 20:03:46 +00:00
|
|
|
;;
|
2022-09-29 04:10:45 +00:00
|
|
|
my__app,some_cmd_alias)
|
|
|
|
cmd="my__app__some_cmd"
|
|
|
|
;;
|
2022-09-28 21:33:59 +00:00
|
|
|
my__app,test)
|
|
|
|
cmd="my__app__test"
|
2022-03-07 20:03:46 +00:00
|
|
|
;;
|
2022-09-28 21:33:59 +00:00
|
|
|
my__app__help,help)
|
|
|
|
cmd="my__app__help__help"
|
|
|
|
;;
|
|
|
|
my__app__help,some_cmd)
|
|
|
|
cmd="my__app__help__some_cmd"
|
|
|
|
;;
|
|
|
|
my__app__help,test)
|
|
|
|
cmd="my__app__help__test"
|
|
|
|
;;
|
|
|
|
my__app__help__some_cmd,sub_cmd)
|
|
|
|
cmd="my__app__help__some_cmd__sub_cmd"
|
|
|
|
;;
|
|
|
|
my__app__some_cmd,help)
|
|
|
|
cmd="my__app__some_cmd__help"
|
|
|
|
;;
|
|
|
|
my__app__some_cmd,sub_cmd)
|
|
|
|
cmd="my__app__some_cmd__sub_cmd"
|
|
|
|
;;
|
|
|
|
my__app__some_cmd__help,help)
|
|
|
|
cmd="my__app__some_cmd__help__help"
|
|
|
|
;;
|
|
|
|
my__app__some_cmd__help,sub_cmd)
|
|
|
|
cmd="my__app__some_cmd__help__sub_cmd"
|
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 some_cmd 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 some_cmd 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__some_cmd)
|
|
|
|
opts="sub_cmd"
|
|
|
|
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__some_cmd__sub_cmd)
|
|
|
|
opts=""
|
|
|
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; 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__some_cmd)
|
|
|
|
opts="-h -V --help --version sub_cmd help"
|
|
|
|
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
|
|
|
|
;;
|
|
|
|
my__app__some_cmd__help)
|
2022-08-25 05:44:07 +00:00
|
|
|
opts="sub_cmd help"
|
2022-03-07 20:03:46 +00:00
|
|
|
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-08-25 05:44:07 +00:00
|
|
|
my__app__some_cmd__help__help)
|
|
|
|
opts=""
|
|
|
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
case "${prev}" in
|
|
|
|
*)
|
|
|
|
COMPREPLY=()
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
my__app__some_cmd__help__sub_cmd)
|
|
|
|
opts=""
|
|
|
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; 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__some_cmd__sub_cmd)
|
|
|
|
opts="-h -V --config --help --version"
|
|
|
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
case "${prev}" in
|
|
|
|
--config)
|
2022-09-02 12:37:37 +00:00
|
|
|
COMPREPLY=($(compgen -W "Lest quotes, aren't escaped. Second to trigger display of options" -- "${cur}"))
|
2022-03-07 20:03:46 +00:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
COMPREPLY=()
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
complete -F _my-app -o bashdefault -o default my-app
|