-
Notifications
You must be signed in to change notification settings - Fork 1
/
_t_completion
60 lines (47 loc) · 1.25 KB
/
_t_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
#!/usr/bin/env bash
_e() { [[ -n "${DEBUG_COMPLETIONS}" ]] && echo "$1" >> "${HOME}/completions.log"; }
_main() {
local i=1 cmd
_e "comp_words = ${COMP_WORDS[*]}"
# find the subcommand
while [[ "$i" -lt "$COMP_CWORD" ]]
do
local s="${COMP_WORDS[i]}"
case "$s" in
-*) ;;
*)
cmd="$s"
break
;;
esac
(( i++ ))
done
_e "comp_cword = ${COMD_CWORD}"
_e "cmd = $cmd"
if [[ "$i" -eq "$COMP_CWORD" ]]
then
local cur="${COMP_WORDS[COMP_CWORD]}"
local nocolon
_get_comp_words_by_ref -n : -c nocolon
_e "cur = $cur"
_e "nocolon = ${nocolon}"
COMPREPLY=($(compgen -W "$(t actions)" -- "$cur"))
_e "COMPREPLY = ${COMPREPLY[*]}"
return # return early if we're still completing the 'current' command
fi
# we've completed the 'current' command and now need to call the next completion function
# subcommands have their own completion functions
case "$cmd" in
sw|switch|"in") _list_projects ;;
start) _list_projects;;
log) _list_projects;;
*) ;;
esac
}
_list_projects ()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=($(compgen -W "$(t projects)" -- "$cur"))
}
export COMP_WORDBREAKS="${COMP_WORDBREAKS//:}"
complete -o bashdefault -F _main t