Skip to content

Instantly share code, notes, and snippets.

@timyates
Last active December 17, 2015 13:49
Show Gist options
  • Save timyates/5619924 to your computer and use it in GitHub Desktop.
Save timyates/5619924 to your computer and use it in GitHub Desktop.
Quick and dirty GVM bash autocompletion
_gvm_complete()
{
local CANDIDATES
COMPREPLY=()
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $(compgen -W "install uninstall rm list use current version default selfupdate broadcast offline help flush" -- ${COMP_WORDS[COMP_CWORD]}) )
elif [ $COMP_CWORD -eq 2 ]; then
case "${COMP_WORDS[COMP_CWORD-1]}" in
"install" | "uninstall" | "rm" | "list" | "use" | "current" )
CANDIDATES=$(curl -s "${GVM_SERVICE}/candidates" | tr ',' ' ')
COMPREPLY=( $(compgen -W "$CANDIDATES" -- ${COMP_WORDS[COMP_CWORD]}) )
;;
"offline" )
COMPREPLY=( $(compgen -W "enable disable" -- ${COMP_WORDS[COMP_CWORD]}) )
;;
"flush" )
COMPREPLY=( $(compgen -W "candidates broadcast archives temp" -- ${COMP_WORDS[COMP_CWORD]}) )
;;
*)
;;
esac
elif [ $COMP_CWORD -eq 3 ]; then
case "${COMP_WORDS[COMP_CWORD-2]}" in
"install" | "uninstall" | "rm" | "use" | "default" )
COMPREPLY=( $(compgen -W "$(curl -s "${GVM_SERVICE}/candidates/${COMP_WORDS[COMP_CWORD-1]}" | tr ',' ' ')" -- ${COMP_WORDS[COMP_CWORD]}) )
;;
*)
;;
esac
fi
return 0
}
complete -F _gvm_complete gvm
@timyates
Copy link
Author

Added flush (gvm 1.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment