Skip to content

Instantly share code, notes, and snippets.

@judaew
Created November 14, 2021 13:09
Show Gist options
  • Save judaew/76b3df37ca11c079506105ffc6fe1440 to your computer and use it in GitHub Desktop.
Save judaew/76b3df37ca11c079506105ffc6fe1440 to your computer and use it in GitHub Desktop.
Bash completion for go2port
_go2port () {
local cur
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
local -a opts=(
-d
-h
-v
--debug
--help
--version
)
local cmds="get update help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]]; then
COMPREPLY=( $(compgen -W "${opts[*]} ${cmds}" -- "${cur}") )
return 0
fi
case "${prev}" in
-d|--debug)
COMPREPLY=( $(compgen -W "${cmds}" -- "${cur}") )
return 0
;;
-v|--version)
COMPREPLY=()
return 0
;;
-h|--help)
COMPREPLY=()
return 0
;;
*)
COMPREPLY=()
;;
esac
}
complete -F _go2port go2port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment