File: govc_bash_completion

package info (click to toggle)
golang-github-vmware-govmomi 0.24.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,848 kB
  • sloc: sh: 2,285; lisp: 1,560; ruby: 948; xml: 139; makefile: 54
file content (43 lines) | stat: -rw-r--r-- 1,318 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash

# govc Bash completion script
# place in etc/bash_completion.d/ or source on command line with "."

_govc_complete()
{
	local cur prev subcmd
	prev=${COMP_WORDS[COMP_CWORD-1]}
	cur=${COMP_WORDS[COMP_CWORD]}
	subcmd=${COMP_WORDS[1]}
	COMPREPLY=()

	if [[ ${prev} == "govc" ]] ; then # show subcommands, no options
		COMPREPLY=( $(compgen -W "$(govc -h | grep -v Usage | tr -s '\n' ' ')" -- ${cur}) )
		return 0

	elif [[ ${cur} == "-"* ]] ; then
		: # drop out and show options

	elif [[ ${subcmd} == "ls" ]] ; then # not completing an option, try for appropriate values
		if [[ ${prev} == "-t" ]] ; then
			COMPREPLY=( $(compgen -W "$(govc ls -l "/**" | awk '{print $2}' | \
				sort -u | tr -d '()' | tr '\n' ' '  )" -- ${cur}) )
		else
			COMPREPLY=( $(compgen -W "$(govc ls "${cur:-/*}*" | tr -s '\n' ' ' )" -- ${cur}) )
		fi

	elif [[ ${subcmd} == "vm."* || ${prev} == "-vm" ]] ; then  
		COMPREPLY=( $(compgen -W "$(govc ls -t VirtualMachine -l "${cur}*" | \
			awk '{print $1}' | tr -s '\n' ' ' )" -- ${cur}) )
	fi

	# did not hit any specifcs so show all options from help
	if [[ -z ${COMPREPLY} ]]; then
		COMPREPLY=( $(compgen -W "-h $(govc ${subcmd} -h | awk '{print $1}' | \
		   	grep "^-" | sed -e 's/=.*//g' | tr -s '\n' ' ' )" -- ${cur}) )
	fi

	return 0
}
complete -F _govc_complete govc