]> git.rmz.io Git - dotfiles.git/blob - zsh/plugins/taskwarrior/_task
merge oh-my-zsh into subdir
[dotfiles.git] / zsh / plugins / taskwarrior / _task
1 #compdef task
2 # zsh completion for taskwarrior
3 #
4 # taskwarrior - a command line task list manager.
5 #
6 # Copyright 2010 - 2011 Johannes Schlatow
7 # Copyright 2009 P.C. Shyamshankar
8 #
9 # Permission is hereby granted, free of charge, to any person obtaining a copy
10 # of this software and associated documentation files (the "Software"), to deal
11 # in the Software without restriction, including without limitation the rights
12 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 # copies of the Software, and to permit persons to whom the Software is
14 # furnished to do so, subject to the following conditions:
15 #
16 # The above copyright notice and this permission notice shall be included
17 # in all copies or substantial portions of the Software.
18 #
19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 # SOFTWARE.
26 #
27 # http://www.opensource.org/licenses/mit-license.php
28 #
29 typeset -g _task_cmds _task_projects _task_tags _task_config _task_modifiers
30 _task_projects=($(task _projects))
31 _task_tags=($(task _tags))
32 _task_ids=($(task _ids))
33 _task_config=($(task _config))
34 _task_columns=($(task _columns))
35 _task_modifiers=(
36 'before' \
37 'after' \
38 'none' \
39 'any' \
40 'is' \
41 'isnt' \
42 'has' \
43 'hasnt' \
44 'startswith' \
45 'endswith' \
46 'word' \
47 'noword'
48 )
49 _task_conjunctions=(
50 'and' \
51 'or' \
52 'xor' \
53 '\)'
54 '\('
55 )
56 _task_cmds=($(task _commands))
57 _task_zshcmds=( ${(f)"$(task _zshcommands)"} )
58
59 _task() {
60 _arguments -s -S \
61 "*::task default:_task_default"
62 return 0
63 }
64
65 local -a reply args word
66 word=$'[^\0]#\0'
67
68 # priorities
69 local -a task_priorities
70 _regex_words values 'task priorities' \
71 'H:High' \
72 'M:Middle' \
73 'L:Low'
74 task_priorities=("$reply[@]")
75
76 # projects
77 local -a task_projects
78 task_projects=(
79 /"$word"/
80 ":values:task projects:compadd -a _task_projects"
81 )
82
83 local -a _task_dates
84 _regex_words values 'task dates' \
85 'tod*ay:Today' \
86 'yes*terday:Yesterday' \
87 'tom*orrow:Tomorrow' \
88 'sow:Start of week' \
89 'soww:Start of work week' \
90 'socw:Start of calendar week' \
91 'som:Start of month' \
92 'soy:Start of year' \
93 'eow:End of week' \
94 'eoww:End of work week' \
95 'eocw:End of calendar week' \
96 'eom:End of month' \
97 'eoy:End of year' \
98 'mon:Monday' \
99 'tue:Tuesday'\
100 'wed:Wednesday' \
101 'thu:Thursday' \
102 'fri:Friday' \
103 'sat:Saturday' \
104 'sun:Sunday'
105 _task_dates=("$reply[@]")
106
107 local -a _task_reldates
108 _regex_words values 'task reldates' \
109 'hrs:n hours' \
110 'day:n days' \
111 '1st:first' \
112 '2nd:second' \
113 '3rd:third' \
114 'th:4th, 5th, etc.' \
115 'wks:weeks'
116 _task_reldates=("$reply[@]")
117
118 task_dates=(
119 \( "$_task_dates[@]" \|
120 \( /$'[0-9][0-9]#'/- \( "$_task_reldates[@]" \) \)
121 \)
122 )
123
124 _regex_words values 'task frequencies' \
125 'daily:Every day' \
126 'day:Every day' \
127 'weekdays:Every day skipping weekend days' \
128 'weekly:Every week' \
129 'biweekly:Every two weeks' \
130 'fortnight:Every two weeks' \
131 + 'monthly:Every month' \
132 'quarterly:Every three months' \
133 'semiannual:Every six months' \
134 'annual:Every year' \
135 'yearly:Every year' \
136 'biannual:Every two years' \
137 'biyearly:Every two years'
138 _task_freqs=("$reply[@]")
139
140 local -a _task_frequencies
141 _regex_words values 'task frequencies' \
142 'd:days' \
143 'w:weeks' \
144 'q:quarters' \
145 'y:years'
146 _task_frequencies=("$reply[@]")
147
148 task_freqs=(
149 \( "$_task_freqs[@]" \|
150 \( /$'[0-9][0-9]#'/- \( "$_task_frequencies[@]" \) \)
151 \)
152 )
153
154 # attributes
155 local -a task_attributes
156 _regex_words -t ':' default 'task attributes' \
157 'pro*ject:Project name:$task_projects' \
158 'du*e:Due date:$task_dates' \
159 'wa*it:Date until task becomes pending:$task_dates' \
160 're*cur:Recurrence frequency:$task_freqs' \
161 'pri*ority:priority:$task_priorities' \
162 'un*til:Recurrence end date:$task_dates' \
163 'fg:Foreground color' \
164 'bg:Background color' \
165 'li*mit:Desired number of rows in report'
166 task_attributes=("$reply[@]")
167
168 args=(
169 \( "$task_attributes[@]" \|
170 \( /'(project|due|wait|recur|priority|until|fg|bg|limit).'/- \( /$'[^:]#:'/ ":default:modifiers:compadd -S ':' -a _task_modifiers" \) \) \|
171 \( /'(rc).'/- \( /$'[^:]#:'/ ":arguments:config:compadd -S ':' -a _task_config" \) \) \|
172 \( /'(+|-)'/- \( /"$word"/ ":values:remove tag:compadd -a _task_tags" \) \) \|
173 \( /"$word"/ \)
174 \) \#
175 )
176 _regex_arguments _task_attributes "${args[@]}"
177
178 ## task commands
179
180 # filter completion
181 (( $+functions[_task_filter] )) ||
182 _task_filter() {
183 _task_attributes "$@"
184
185 # TODO complete conjunctions only if the previous word is a filter expression, i.e. attribute, ID, any non-command
186 _describe -t default 'task conjunctions' _task_conjunctions
187 }
188
189 # merge completion
190 (( $+functions[_task_merge] )) ||
191 _task_merge() {
192 # TODO match URIs in .taskrc
193 _files
194 }
195
196 # push completion
197 (( $+functions[_task_push] )) ||
198 _task_push() {
199 # TODO match URIs in .taskrc
200 _files
201 }
202
203 # pull completion
204 (( $+functions[_task_pull] )) ||
205 _task_pull() {
206 # TODO match URIs in .taskrc
207 _files
208 }
209
210 # execute completion
211 (( $+functions[_task_execute] )) ||
212 _task_execute() {
213 _files
214 }
215
216 # id-only completion
217 (( $+functions[_task_id] )) ||
218 _task_id() {
219 _describe -t values 'task IDs' _task_zshids
220 }
221
222 ## first level completion => task sub-command completion
223 (( $+functions[_task_default] )) ||
224 _task_default() {
225 local cmd ret=1
226
227 integer i=1
228 while (( i < $#words ))
229 do
230 cmd="${_task_cmds[(r)$words[$i]]}"
231 if (( $#cmd )); then
232 _call_function ret _task_${cmd} ||
233 _call_function ret _task_filter ||
234 _message "No command remaining."
235 return ret
236 fi
237 (( i++ ))
238 done
239
240 # update IDs
241 _task_zshids=( ${(f)"$(task _zshids)"} )
242
243 _describe -t commands 'task command' _task_zshcmds
244 _describe -t values 'task IDs' _task_zshids
245 _call_function ret _task_filter
246
247 return ret
248 }