-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtt_completion
executable file
·88 lines (76 loc) · 1.73 KB
/
tt_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
BASE_COMMANDS="browse check clone create dc destroy install ip pull recreate restart upgrade usage version workspace"
WORKSPACE_COMMANDS="init add edit rm ls use current upgrade"
tarantino() {
tt $@
}
tt_complete() {
local word=
local cmds=
if [ $1 == '-n' ]; then
shift;
word=
cmds=($@)
else
word=${@: -1}
cmds=(${@:1:$#-1})
fi
local basecmd=${cmds[0]}
local numcmds=${#cmds[@]}
if [ $numcmds -gt 1 ]; then
#multi cmd case
case "$basecmd" in
create)
completion_all_services $word ;;
destroy|recreate)
completion_running_services $word ;;
pull|clone|check)
completion_services $word ;;
workspace)
if [ $numcmds -eq 2 ]; then
case "${cmds[1]}" in
use|rm)
completion_available_workspaces $word ;;
esac
fi
esac
else
#single arg case
case "$basecmd" in
tt|"")
completion_base $word ;;
create|browse)
completion_all_services $word ;;
destroy|recreate|ip)
completion_running_services $word ;;
pull|clone|check)
completion_services $word ;;
workspace)
completion_workspace $word ;;
esac
fi
}
completion_base() {
echo "$BASE_COMMANDS"
}
completion_all_services() {
tarantino get_services 2> /dev/null
}
completion_services() {
tarantino get_services_with_source 2> /dev/null
}
completion_running_services() {
local running_ids=$(docker ps -q)
if [ ! -z "$running_ids" ]; then
docker inspect --format \
'{{index .Config.Labels "com.docker.compose.project"}} {{index .Config.Labels "com.docker.compose.service"}}' \
$running_ids | sed -n "s/^$(tarantino get_workspace) //p"
fi
}
completion_workspace() {
echo "$WORKSPACE_COMMANDS"
}
completion_available_workspaces() {
tarantino get_available_workspaces 2> /dev/null
}
tt_complete $@