-
-
Save stobias123/588e7f0f01c59853c04e0ebf512ed16b to your computer and use it in GitHub Desktop.
Command line autocompletion for `govc`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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