-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupervisor-completion.bash
More file actions
58 lines (50 loc) · 1.4 KB
/
Copy pathsupervisor-completion.bash
File metadata and controls
58 lines (50 loc) · 1.4 KB
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
_supervisor_sh() {
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}
local prev2=${COMP_WORDS[COMP_CWORD-2]}
local options="-c --config -h --help -n --no-color -v --version"
local commands="start stop restart status fix lint log logs convert"
local args="$options $commands"
if (( COMP_CWORD == 1 )); then
mapfile -t COMPREPLY < <(compgen -W "$args" -- "$cur")
elif [[ "$prev2" =~ ^(start|stop|restart)$ ]]; then
return 0
else
local app="supervisor.sh"
local pid_dir=${PID_DIR:-/run/$app}
local i basename name jobs
case "$prev" in
-c|--config)
mapfile -t COMPREPLY < <(compgen -f -- "$cur")
;;
-h|--help|-v|--version|status|fix|lint|log|logs|convert)
return 0
;;
start)
for i in "$pid_dir"/*.pid; do
basename=${i##*/}
name="${basename:0:-4}"
if [[ "$name" != "*" && "$name" != "$app" && -f "$i.stopped" ]]; then
jobs+="$name "
fi
done
mapfile -t COMPREPLY < <(compgen -W "$jobs" -- "$cur")
;;
stop|restart)
for i in "$pid_dir"/*.pid; do
basename=${i##*/}
name="${basename:0:-4}"
if [[ "$name" != "*" && "$name" != "$app" && ! -f "$i.stopped" ]]; then
jobs+="$name "
fi
done
mapfile -t COMPREPLY < <(compgen -W "$jobs" -- "$cur")
;;
*)
mapfile -t COMPREPLY < <(compgen -W "$args" -- "$cur")
;;
esac
fi
return 0
}
complete -F _supervisor_sh supervisor.sh