3 # Copyright 2010 - 2019 Johannes Schlatow
4 # Copyright 2009 P.C. Shyamshankar
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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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
24 # https://www.opensource.org/licenses/mit-license.php
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))
59 _task_cmds=($(task _commands; task _aliases))
60 _task_zshcmds=( ${(f)"$(task _zshcommands)"} sentinel:sentinel:sentinel )
62 _task_aliases=($(task _aliases))
66 "*::task default:_task_default"
70 local -a reply args word
74 local -a task_priorities
75 _regex_words values 'task priorities' \
79 task_priorities=("$reply[@]")
82 local -a task_projects
85 ":values:task projects:compadd -a _task_projects"
89 _regex_words values 'task dates' \
91 'yes*terday:Yesterday' \
92 'tom*orrow:Tomorrow' \
94 'soww:Start of work week' \
95 'socw:Start of calendar week' \
96 'som:Start of month' \
97 'soq:Start of quarter' \
100 'eoww:End of work week' \
101 'eocw:End of calendar week' \
103 'eoq:End of quarter' \
112 'good*friday:Good Friday' \
114 'eastermonday:Easter Monday' \
115 'ascension:Ascension' \
116 'pentecost:Pentecost' \
117 'midsommar:Midsommar' \
118 'midsommarafton:Midsommarafton' \
121 _task_dates=("$reply[@]")
123 local -a _task_reldates
124 _regex_words values 'task reldates' \
130 'th:4th, 5th, etc.' \
132 _task_reldates=("$reply[@]")
135 \( "$_task_dates[@]" \|
136 \( /$'[0-9][0-9]#'/- \( "$_task_reldates[@]" \) \)
141 if (( $#_task_zshids )); then
142 _regex_words values 'task IDs' $_task_zshids
143 task_zshids=("$reply[@]")
146 _regex_words values 'task frequencies' \
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[@]")
162 local -a _task_frequencies
163 _regex_words values 'task frequencies' \
168 _task_frequencies=("$reply[@]")
171 \( "$_task_freqs[@]" \|
172 \( /$'[0-9][0-9]#'/- \( "$_task_frequencies[@]" \) \)
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[@]")
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" \) \) \|
203 _regex_arguments _task_attributes "${args[@]}"
208 (( $+functions[_task_filter] )) ||
210 _task_attributes "$@"
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
217 (( $+functions[_task_execute] )) ||
223 (( $+functions[_task_id] )) ||
225 _describe -t values 'task IDs' _task_zshids
228 # subcommand-only function
229 (( $+functions[_task_subcommands] )) ||
230 _task_subcommands() {
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
239 category=${${_zshcmd#*:}%%:*}
242 # Present each category as soon as the first entry in the *next* category
244 if [[ $category != $lastcategory && -n $lastcategory ]]; then
245 _describe -t ${lastcategory}-commands "task ${lastcategory} command" subcommands
249 # Log the subcommand; we will process it in some future iteration.
250 subcommands+=( "$cmd:$desc" )
252 lastcategory=$category
256 ## first level completion => task sub-command completion
257 (( $+functions[_task_default] )) ||
262 while (( i < $#words ))
264 cmd="${_task_cmds[(r)$words[$i]]}"
266 _call_function ret _task_${cmd} ||
267 _call_function ret _task_filter ||
268 _message "No command remaining."
275 _task_zshids=( ${(f)"$(task _zshids)"} )
278 _describe -t tasks 'task IDs' _task_zshids
279 _describe -t aliases 'task aliases' _task_aliases
280 _call_function ret _task_filter