-
Notifications
You must be signed in to change notification settings - Fork 8
/
uwsgi-emperor.bash_completion
70 lines (64 loc) · 1.95 KB
/
uwsgi-emperor.bash_completion
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
[[ -n $(find /etc/init.d/ -name 'uwsgi-*' -executable) ]] && \
_uwsgi_index()
{
local index=0
for p in $@; do
[[ $p =~ "uwsgi-" ]] && return $index
((index++))
done
}
_uwsgi_init(){
local cur prev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case "$(basename $prev)" in
uwsgi-*)
local opts
opts="start stop restart reload force-reload status enable disable"
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
all)
return 0
;;
esac
local index version configs
index="$(_uwsgi_index ${COMP_WORDS[@]}; echo $?)"
version=$(basename ${COMP_WORDS[$index]})
case "${COMP_WORDS[$index + 1]}" in
enable)
local available enabled
available="/etc/uwsgi/$version/sites-available"
enabled="/etc/uwsgi/$version/sites-enabled"
configs=$(diff $available $enabled \
| grep $available \
| sed -re 's#.+: (.+)$#\1#')
;;
disable)
configs=$(cd /etc/uwsgi/$version/sites-enabled/; ls -1 *.*)
;;
*)
return 0
esac
configs=( $(echo $configs | xargs echo) )
if [[ COMP_CWORD -gt $(($index + 2)) ]]; then
local selected=( $(echo "${COMP_WORDS[@]:$(($index+2))}") )
local tmp=()
for i in "${configs[@]}"; do
local skip=
for j in "${selected[@]}"; do
[[ $i == $j ]] && { skip=1; break; }
done
[[ -n $skip ]] || tmp+=( "$i" )
done
configs=( ${tmp[@]} )
fi
[[ "enable disable" =~ $prev ]] && configs+=( "all" )
configs=$(echo "${configs[@]}")
COMPREPLY=( $(compgen -W "${configs}" -- ${cur}) )
return 0
} && \
for uwsgi_script in $(find /etc/init.d/ -name 'uwsgi-*' -executable); do
complete -F _uwsgi_init $uwsgi_script
done