aboutsummaryrefslogtreecommitdiff
path: root/bash-completion
blob: 489b5dc9538b2e5e2e380c6f03d0548e3ebbb3b8 (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
# rc.d bash completion by Seblu <seblu@seblu.net>

_rc.d ()
{
	local action="help list start stop reload restart"
	local cur="${COMP_WORDS[COMP_CWORD]}"
	local caction="${COMP_WORDS[1]}"
	if ((COMP_CWORD == 1)); then
		COMPREPLY=($(compgen -W "${action}" -- "$cur"))
	elif [[ "$caction" == help ]]; then
		COMPREPLY=()
	elif [[ "$caction" == list ]]; then
		((COMP_CWORD == 2)) && COMPREPLY=($(compgen -W "started stopped" -- "$cur")) || COMPREPLY=()
	elif [[ "$caction" == start ]]; then
		COMPREPLY=($(comm -23 <(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort) <(cd /run/daemons/ && compgen -f "$cur"|sort)))
	elif [[ "$caction" =~ stop|restart|reload ]]; then
		COMPREPLY=($(cd /run/daemons/ && compgen -f "$cur"|sort))
	elif ((COMP_CWORD > 1)); then
		COMPREPLY=($(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort))
	fi
}
complete -F _rc.d rc.d

# vim: set ts=2 sw=2 ft=sh noet: