Skip to content

Instantly share code, notes, and snippets.

@stobias123
Last active April 3, 2020 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stobias123/588e7f0f01c59853c04e0ebf512ed16b to your computer and use it in GitHub Desktop.
Save stobias123/588e7f0f01c59853c04e0ebf512ed16b to your computer and use it in GitHub Desktop.
Command line autocompletion for `govc`
#compdef govc
_govc () {
local line
local -a top_level_cmds
top_level_cmds=$(_govc_top_level_commands)
_arguments -C \
'1: :_govc_top_level_commands' \
"*::arg:->args"
top_level_cmd=$(cut -f1 -d'.' <<< $line[1])
case $top_level_cmd in
vm)
_govc_vm
;;
ls)
_govc_ls
;;
esac
#echo "fucking line is --- $line"
}
_govc_vm () {
_describe 'Virtual Machines' _govc_basic_describe
}
# After
#
_govc_ls () {
local -a ls_results
ls_results=($(govc ls $line[2]))
_describe 'browse' ls_results
}
_govc_basic_describe () {
echo " wtf is this variable - $line[2]"
#local path
#path=_govc_get_subcommand_args
}
_govc_top_level_commands () {
local -a top_level_commands
top_level_commands=($(govc 2>&1 | tail -n +2 | cut -f1 -d'.' | uniq | sed 's/ //g'))
_describe 'commands' top_level_commands
}
_govc_get_subcommand_args () {
cut -f2- -d' ' <<< $line[1]
}
_govc_list_vms () {
local -a vm_list
vm_list=
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment