-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_mq_completion.sh
52 lines (47 loc) · 1.48 KB
/
bash_mq_completion.sh
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
# bash completion for mq.sh
# source this file to use: . ./bash_mq_completion.sh
_mq_systems() {
mq.sh system-tsv | cut -f 1 | tail -n +2
mq.sh pool-tsv | cut -f 1
}
_mq_completion() {
local cur="${COMP_WORDS[$COMP_CWORD]}"
if [ "$COMP_CWORD" -eq "1" ]; then
COMPREPLY=($(compgen -W "run sem systems system-tsv pool-tsv" -- "${cur}"))
else
local prev="${COMP_WORDS[$(( $COMP_CWORD - 1 ))]}"
case "${COMP_WORDS[1]}" in
sem)
if [ "$COMP_CWORD" -eq "2" ]; then
COMPREPLY=($(compgen -W "-signal -wait -info -mr-info -cancel dumpall" -- "${cur}"))
elif [ "$COMP_CWORD" -eq "3" ]; then
COMPREPLY=($(compgen -W "$(_mq_systems)" -- "${cur}"))
elif [ "$COMP_CWORD" -eq "4" ]; then
COMPREPLY=($(compgen -W "-k -f" -- "${cur}"))
fi
;;
run)
local mq_run_flags="-r -n -a -c -e -d -k -l -s -f -w -t"
if [ "$COMP_CWORD" -eq "2" ]; then
COMPREPLY=($(compgen -W "${mq_run_flags}" -- "${cur}"))
else
case "$prev" in
'-s')
COMPREPLY=($(compgen -W "$(_mq_systems)" -- "${cur}"))
;;
'-k'|'-c'|'-e'|'-d'|'-k'|'-l'|'-w'|'-t'|'-f')
# will default to filename completion
COMPREPLY=()
;;
*)
COMPREPLY=($(compgen -W "${mq_run_flags}" -- "${cur}"))
;;
esac
fi
;;
*)
;;
esac
fi
}
complete -o default -F _mq_completion mq.sh