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