summaryrefslogtreecommitdiff
path: root/rtadm.bash_completion
blob: 15e3c7000320548d4e6da59f977f6a692770ff33 (plain)
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
44
45
46
47
48
49
50
51
52
53
# Bash completion for rtadm

_rtadm_ra_hosts_disabled() {
	awk '/^#DISABLED#/ {print $5}' .ssh/authorized_keys | cut -d- -f3
}

_rtadm_ra_hosts_enabled() {
	awk '/^[^#].* ra-/ {print $5}' .ssh/authorized_keys | cut -d- -f3
}

_rtadm_ra_hosts() {
	awk '/ ra-/ {print $5}' .ssh/authorized_keys | cut -d- -f3
}

_rtadm() {
	local cur commands command hosts

	COMPREPLY=()
	cur=`_get_cword`

	commands='create show enable disable disconnect delete'

	if [[ $COMP_CWORD -eq 1 ]] ; then
		COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
		return 0
	fi


	command=${COMP_WORDS[1]}
	case "$command" in
	create)
		# Fixme: some completion here.
		: #create [-e] port newname
		;;
	show) : # No parameters here
		;;
	enable)
		hosts=`_rtadm_ra_hosts_disabled`
		COMPREPLY=( $( compgen -W "$hosts" -- $cur ) )
		;;
	disable|disconnect)
		hosts=`_rtadm_ra_hosts_enabled`
		COMPREPLY=( $( compgen -W "$hosts" -- $cur ) )
		;;
	delete)
		hosts=`_rtadm_ra_hosts`
		COMPREPLY=( $( compgen -W "$hosts" -- $cur ) )
		;;
	esac
	return 0
}

complete -F _rtadm rtadm