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"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case "${cmd}" in
|
|
|
|
my__app)
|
2022-08-29 20:09:06 +00:00
|
|
|
opts="-p -f -d -e -c -u -H -h --choice --unknown --other --path --file --dir --exe --cmd-name --cmd --user --host --url --email --help [command_with_args]..."
|
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
|
|
|
|
--choice)
|
2022-05-06 14:14:29 +00:00
|
|
|
COMPREPLY=($(compgen -W "bash fish zsh" -- "${cur}"))
|
2022-03-07 20:03:46 +00:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--unknown)
|
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--other)
|
2023-05-09 18:59:56 +00:00
|
|
|
COMPREPLY=("${cur}")
|
2023-12-03 08:27:00 +00:00
|
|
|
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
|
|
|
|
compopt -o nospace
|
|
|
|
fi
|
2022-03-07 20:03:46 +00:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--path)
|
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-p)
|
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--file)
|
2024-01-31 14:37:19 +00:00
|
|
|
local oldifs
|
2024-04-07 14:19:50 +00:00
|
|
|
if [ -n "${IFS+x}" ]; then
|
2024-01-31 14:37:19 +00:00
|
|
|
oldifs="$IFS"
|
|
|
|
fi
|
|
|
|
IFS=$'\n'
|
2022-03-07 20:03:46 +00:00
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
2024-04-07 14:19:50 +00:00
|
|
|
if [ -n "${oldifs+x}" ]; then
|
2024-01-31 14:37:19 +00:00
|
|
|
IFS="$oldifs"
|
|
|
|
fi
|
2023-12-03 08:13:57 +00:00
|
|
|
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
|
|
|
|
compopt -o filenames
|
|
|
|
fi
|
2022-03-07 20:03:46 +00:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-f)
|
2024-01-31 14:37:19 +00:00
|
|
|
local oldifs
|
2024-04-07 14:19:50 +00:00
|
|
|
if [ -n "${IFS+x}" ]; then
|
2024-01-31 14:37:19 +00:00
|
|
|
oldifs="$IFS"
|
|
|
|
fi
|
|
|
|
IFS=$'\n'
|
2022-03-07 20:03:46 +00:00
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
2024-04-07 14:19:50 +00:00
|
|
|
if [ -n "${oldifs+x}" ]; then
|
2024-01-31 14:37:19 +00:00
|
|
|
IFS="$oldifs"
|
|
|
|
fi
|
2023-12-03 08:13:57 +00:00
|
|
|
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
|
|
|
|
compopt -o filenames
|
|
|
|
fi
|
2022-03-07 20:03:46 +00:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--dir)
|
2023-12-03 08:20:38 +00:00
|
|
|
COMPREPLY=()
|
|
|
|
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
|
|
|
|
compopt -o plusdirs
|
|
|
|
fi
|
2022-03-07 20:03:46 +00:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-d)
|
2023-12-03 08:20:38 +00:00
|
|
|
COMPREPLY=()
|
|
|
|
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
|
|
|
|
compopt -o plusdirs
|
|
|
|
fi
|
2022-03-07 20:03:46 +00:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--exe)
|
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-e)
|
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--cmd-name)
|
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--cmd)
|
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-c)
|
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--user)
|
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-u)
|
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--host)
|
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
|
|
|
return 0
|
|
|
|
;;
|
2022-08-08 21:08:47 +00:00
|
|
|
-H)
|
2022-03-07 20:03:46 +00:00
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--url)
|
|
|
|
COMPREPLY=($(compgen -f "${cur}"))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--email)
|
|
|
|
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
|