-
Notifications
You must be signed in to change notification settings - Fork 3
/
completion.bash
153 lines (133 loc) · 2.85 KB
/
completion.bash
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
_wenv_comp() {
COMPREPLY=( $(compgen -W "$1" -- ${word}) )
if [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} == "--"*"=" ]]; then
# If there's only one option, with =, then discard space
complete -o nospace
fi
}
_show_wenvs() {
find "$WENV_CFG/wenvs" ! -name ".gitignore" ! -path '*/\.git/*' ! -type d | perl -pe "s|$WENV_CFG/wenvs/||"
}
_wenv_start() {
if [[ $word == -* ]]; then
_wenv_comp "-i -d -h"
else
_show_wenvs
fi
}
_wenv_stop() {
_wenv_comp "-s -h -f"
}
_wenv_cd() {
if [[ $word == -* ]]; then
_wenv_comp "-r -h"
else
_show_wenvs
fi
}
_wenv_new() {
if [[ ${prev} == "-i" ]]; then
_show_wenvs
elif [[ ${word} == -* ]]; then
_wenv_comp "-i -d -h"
fi
}
_wenv_edit() {
_show_wenvs
}
_wenv_rm() {
_wenv_remove
}
_wenv_remove() {
if [[ $word == -* ]]; then
_wenv_comp "-h"
else
_show_wenvs
fi
}
_wenv_rename() {
if [[ $word == -* ]]; then
_wenv_comp "-h"
else
_show_wenvs
fi
}
_wenv_mv() {
_wenv_rename
}
_wenv_source() {
if [[ $word == -* ]]; then
_wenv_comp "-h"
else
_wenv_comp "load edit"
fi
}
_wenv_extension() {
if [[ $word == -* ]]; then
_wenv_comp "-h"
else
_wenv_comp "edit load rm"
fi
}
_wenv_extension_load() {
if [[ $word == -* ]]; then
_wenv_comp "-h"
else
ls "$WENV_CFG/extensions"
fi
}
_wenv_extension_edit() {
if [[ $word == -* ]]; then
_wenv_comp "-h"
else
ls "$WENV_CFG/extensions"
fi
}
_wenv_extension_remove() {
if [[ $word == -* ]]; then
_wenv_comp "-h"
else
ls "$WENV_CFG/extensions"
fi
}
_wenv_bootstrap() {
if [[ $word == -* ]]; then
_wenv_comp "-h"
else
_show_wenvs
fi
}
_wenv_exec() {
if [[ $word == -* ]]; then
_wenv_comp "-c -n -h"
else
_show_wenvs
fi
}
_wenv() {
COMPREPLY=()
complete +o default # Disable default to not deny completion, see: http://stackoverflow.com/a/19062943/1216348
local word="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
case "${COMP_CWORD}" in
1)
if [[ $word == -* ]]; then
_wenv_comp '-h'
else
local opts="start stop cd new edit rm mv source extension bootstrap exec"
COMPREPLY=( $(compgen -W "${opts}" -- ${word}) )
fi
;;
2)
local command="${COMP_WORDS[1]}"
eval "_wenv_$command" 2> /dev/null
;;
*)
local command="${COMP_WORDS[1]}"
local subcommand="${COMP_WORDS[2]}"
eval "_wenv_${command}_${subcommand}" 2> /dev/null && return
eval "_wenv_$command" 2> /dev/null
;;
esac
}
complete -F _wenv __wenv