summaryrefslogtreecommitdiffstats
path: root/tools/bcfg2-completion.bash
blob: 2c2a19195846486fd0d0b80569f5e26d25fa42ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# TODO: Add completion for each admin mode
_bcfg2-admin() {
	local cur prev sedcmd possibles
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	sedcmd='sed -n -e s/^[[:space:]]\+\([[:alpha:]]\+\)[[:space:]]\+.*$/\1/p'

	if [[ ${COMP_CWORD} -eq 1 ]] || [[ -n "${prev}" && ${prev} == -* ]]
	then
		possibles="$(bcfg2-admin help | ${sedcmd})"
	#elif bcfg2-admin ${prev} help &>/dev/null ; then
	#	possibles=$(bcfg2-admin ${prev} help | ${sedcmd})
	fi

	[[ -n "${possibles}" ]] && \
		COMPREPLY=( $(compgen -W "${possibles}" -- ${cur}) )

	return 0
}
complete -F _bcfg2-admin bcfg2-admin