-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash-completion.sh
71 lines (62 loc) · 1.52 KB
/
bash-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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# playlabs complete script
. /usr/share/bash-completion/completions/git
_playlabs_autocomplete()
{
if [ "$playlabs_path" == '' ]
then
export playlabs_path=`pip3 show playlabs | grep "^Location" | awk '{print $2}'`
fi
local cur prev action=""
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
prevm="${COMP_WORDS[COMP_CWORD-2]}"
local opts
opts=('deploy' 'init' 'scaffold' 'install' 'git ' 'backup' 'restore' 'log')
for i in ${opts[*]}
do
for j in ${COMP_WORDS[*]}; #=${COMP_WORDS}; $j >= 0; $j=$j + 1;
do
if [ $i == $j ]
then action="${i}"
fi
done
done
case "${cur:0:1}" in
@)
local hosts
[[ -f ${HOME}/.ssh/known_hosts ]] &&
hosts=`cat ${HOME}/.ssh/known_hosts | awk '{print "@"$1}'`
COMPREPLY=( $(compgen -W "${hosts}" -- ${cur} ) )
return 0
;;
esac
if [ "${action}" != "" ]
then
case "${action}" in
scaffold)
COMPREPLY=( $(compgen -d -- ${cur}) )
;;
install)
local roles_path="${playlabs_path}/playlabs/roles"
local running="`ls -l ${roles_path} | grep "^d" | awk '{print $9}'`"
local last=`awk '{b=split($0,a,",");print(a[b]);}' <<< ${cur}`
COMPREPLY=( $(compgen -W "${running}" -- "${last}") )
;;
deploy)
COMPREPLY=( $(compgen -P 'image=' -A file -- ${cur}) )
;;
git)
((COMP_CWORD -=1))
COMP_WORDS=(${COMP_WORDS[@]:1})
__git_func_wrap __git_main ;
return 0
;;
*)
;;
esac
else
COMPREPLY=($(compgen -W "${opts[*]}" -- ${cur}))
fi
}
complete -F _playlabs_autocomplete playlabs