forked from pydoit/doit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_completion_doit
134 lines (119 loc) · 3.79 KB
/
bash_completion_doit
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
# bash completion for doit
# auto-generate by `doit tabcompletion`
# to activate it you need to 'source' the generate script
# $ source <generated-script>
# reference => http://www.debian-administration.org/articles/317
# patch => http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=711879
_doit()
{
local cur prev words cword basetask sub_cmds tasks i dodof
COMPREPLY=() # contains list of words with suitable completion
# remove colon from word separator list because doit uses colon on task names
_get_comp_words_by_ref -n : cur prev words cword
# list of sub-commands
sub_cmds="auto clean dumpdb forget help ignore info list reset-dep run strace tabcompletion"
# options that take file/dir as values should complete file-system
if [[ "$prev" == "-f" || "$prev" == "-d" || "$prev" == "-o" ]]; then
_filedir
return 0
fi
if [[ "$cur" == *=* ]]; then
prev=${cur/=*/}
cur=${cur/*=/}
if [[ "$prev" == "--file=" || "$prev" == "--dir=" || "$prev" == "--output-file=" ]]; then
_filedir -o nospace
return 0
fi
fi
# get name of the dodo file
for (( i=0; i < ${#words[@]}; i++)); do
case "${words[i]}" in
-f)
dodof=${words[i+1]}
break
;;
--file=*)
dodof=${words[i]/*=/}
break
;;
esac
done
# dodo file not specified, use default
if [ ! $dodof ]
then
dodof="dodo.py"
fi
# get task list
# if it there is colon it is getting a subtask, complete only subtask names
if [[ "$cur" == *:* ]]; then
# extract base task name (remove everything after colon)
basetask=${cur%:*}
# sub-tasks
tasks=$(doit list --file="$dodof" --quiet --all ${basetask} 2>/dev/null)
COMPREPLY=( $(compgen -W "${tasks}" -- ${cur}) )
__ltrim_colon_completions "$cur"
return 0
# without colons get only top tasks
else
tasks=$(doit list --file="$dodof" --quiet 2>/dev/null)
fi
# match for first parameter must be sub-command or task
# FIXME doit accepts options "-" in the first parameter but we ignore this case
if [[ ${cword} == 1 ]] ; then
COMPREPLY=( $(compgen -W "${sub_cmds} ${tasks}" -- ${cur}) )
return 0
fi
case ${words[1]} in
auto)
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) )
return 0
;;
clean)
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) )
return 0
;;
dumpdb)
COMPREPLY=( $(compgen -f -- $cur) )
return 0
;;
forget)
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) )
return 0
;;
help)
COMPREPLY=( $(compgen -W "${tasks} ${sub_cmds}" -- $cur) )
return 0
;;
ignore)
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) )
return 0
;;
info)
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) )
return 0
;;
list)
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) )
return 0
;;
reset-dep)
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) )
return 0
;;
run)
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) )
return 0
;;
strace)
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) )
return 0
;;
tabcompletion)
COMPREPLY=( $(compgen -f -- $cur) )
return 0
;;
esac
# if there is already one parameter match only tasks (no commands)
COMPREPLY=( $(compgen -W "${tasks}" -- ${cur}) )
}
complete -o filenames -F _doit doit