| 1 |
# bash completion for doit |
| 2 |
# auto-generate by `doit tabcompletion` |
| 3 |
|
| 4 |
# to activate it you need to 'source' the generate script |
| 5 |
# $ source <generated-script> |
| 6 |
|
| 7 |
# reference => http://www.debian-administration.org/articles/317 |
| 8 |
# patch => http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=711879 |
| 9 |
|
| 10 |
_doit() |
| 11 |
{ |
| 12 |
local cur prev words cword basetask sub_cmds tasks i dodof |
| 13 |
COMPREPLY=() # contains list of words with suitable completion |
| 14 |
# remove colon from word separator list because doit uses colon on task names |
| 15 |
_get_comp_words_by_ref -n : cur prev words cword |
| 16 |
# list of sub-commands |
| 17 |
sub_cmds="auto clean dumpdb forget help ignore info list reset-dep run strace tabcompletion" |
| 18 |
|
| 19 |
|
| 20 |
# options that take file/dir as values should complete file-system |
| 21 |
if [[ "$prev" == "-f" || "$prev" == "-d" || "$prev" == "-o" ]]; then |
| 22 |
_filedir |
| 23 |
return 0 |
| 24 |
fi |
| 25 |
if [[ "$cur" == *=* ]]; then |
| 26 |
prev=${cur/=*/} |
| 27 |
cur=${cur/*=/} |
| 28 |
if [[ "$prev" == "--file=" || "$prev" == "--dir=" || "$prev" == "--output-file=" ]]; then |
| 29 |
_filedir -o nospace |
| 30 |
return 0 |
| 31 |
fi |
| 32 |
fi |
| 33 |
|
| 34 |
|
| 35 |
# get name of the dodo file |
| 36 |
for (( i=0; i < ${#words[@]}; i++)); do |
| 37 |
case "${words[i]}" in |
| 38 |
-f) |
| 39 |
dodof=${words[i+1]} |
| 40 |
break |
| 41 |
;; |
| 42 |
--file=*) |
| 43 |
dodof=${words[i]/*=/} |
| 44 |
break |
| 45 |
;; |
| 46 |
esac |
| 47 |
done |
| 48 |
# dodo file not specified, use default |
| 49 |
if [ ! $dodof ] |
| 50 |
then |
| 51 |
dodof="dodo.py" |
| 52 |
fi |
| 53 |
|
| 54 |
|
| 55 |
# get task list |
| 56 |
# if it there is colon it is getting a subtask, complete only subtask names |
| 57 |
if [[ "$cur" == *:* ]]; then |
| 58 |
# extract base task name (remove everything after colon) |
| 59 |
basetask=${cur%:*} |
| 60 |
# sub-tasks |
| 61 |
tasks=$(doit list --file="$dodof" --quiet --all ${basetask} 2>/dev/null) |
| 62 |
COMPREPLY=( $(compgen -W "${tasks}" -- ${cur}) ) |
| 63 |
__ltrim_colon_completions "$cur" |
| 64 |
return 0 |
| 65 |
# without colons get only top tasks |
| 66 |
else |
| 67 |
tasks=$(doit list --file="$dodof" --quiet 2>/dev/null) |
| 68 |
fi |
| 69 |
|
| 70 |
|
| 71 |
# match for first parameter must be sub-command or task |
| 72 |
# FIXME doit accepts options "-" in the first parameter but we ignore this case |
| 73 |
if [[ ${cword} == 1 ]] ; then |
| 74 |
COMPREPLY=( $(compgen -W "${sub_cmds} ${tasks}" -- ${cur}) ) |
| 75 |
return 0 |
| 76 |
fi |
| 77 |
|
| 78 |
case ${words[1]} in |
| 79 |
|
| 80 |
auto) |
| 81 |
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) ) |
| 82 |
return 0 |
| 83 |
;; |
| 84 |
clean) |
| 85 |
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) ) |
| 86 |
return 0 |
| 87 |
;; |
| 88 |
dumpdb) |
| 89 |
COMPREPLY=( $(compgen -f -- $cur) ) |
| 90 |
return 0 |
| 91 |
;; |
| 92 |
forget) |
| 93 |
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) ) |
| 94 |
return 0 |
| 95 |
;; |
| 96 |
help) |
| 97 |
COMPREPLY=( $(compgen -W "${tasks} ${sub_cmds}" -- $cur) ) |
| 98 |
return 0 |
| 99 |
;; |
| 100 |
ignore) |
| 101 |
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) ) |
| 102 |
return 0 |
| 103 |
;; |
| 104 |
info) |
| 105 |
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) ) |
| 106 |
return 0 |
| 107 |
;; |
| 108 |
list) |
| 109 |
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) ) |
| 110 |
return 0 |
| 111 |
;; |
| 112 |
reset-dep) |
| 113 |
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) ) |
| 114 |
return 0 |
| 115 |
;; |
| 116 |
run) |
| 117 |
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) ) |
| 118 |
return 0 |
| 119 |
;; |
| 120 |
strace) |
| 121 |
COMPREPLY=( $(compgen -W "${tasks}" -- $cur) ) |
| 122 |
return 0 |
| 123 |
;; |
| 124 |
tabcompletion) |
| 125 |
COMPREPLY=( $(compgen -f -- $cur) ) |
| 126 |
return 0 |
| 127 |
;; |
| 128 |
esac |
| 129 |
|
| 130 |
# if there is already one parameter match only tasks (no commands) |
| 131 |
COMPREPLY=( $(compgen -W "${tasks}" -- ${cur}) ) |
| 132 |
|
| 133 |
} |
| 134 |
complete -o filenames -F _doit doit |