| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | #compdef task | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2016-06-17 11:43:08 +02:00
										 |  |  | # Copyright 2010 - 2016 Johannes Schlatow | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | # Copyright 2009 P.C. Shyamshankar | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2012-01-18 20:29:31 -05:00
										 |  |  | # Permission is hereby granted, free of charge, to any person obtaining a copy | 
					
						
							|  |  |  | # of this software and associated documentation files (the "Software"), to deal | 
					
						
							|  |  |  | # in the Software without restriction, including without limitation the rights | 
					
						
							|  |  |  | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
					
						
							|  |  |  | # copies of the Software, and to permit persons to whom the Software is | 
					
						
							|  |  |  | # furnished to do so, subject to the following conditions: | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2012-01-18 20:29:31 -05:00
										 |  |  | # The above copyright notice and this permission notice shall be included | 
					
						
							|  |  |  | # in all copies or substantial portions of the Software. | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2012-01-18 20:29:31 -05:00
										 |  |  | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 
					
						
							|  |  |  | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | 
					
						
							|  |  |  | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
					
						
							|  |  |  | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 
					
						
							|  |  |  | # SOFTWARE. | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2012-01-18 20:29:31 -05:00
										 |  |  | # http://www.opensource.org/licenses/mit-license.php | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | # | 
					
						
							|  |  |  | typeset -g _task_cmds _task_projects _task_tags _task_config _task_modifiers | 
					
						
							|  |  |  | _task_projects=($(task _projects)) | 
					
						
							|  |  |  | _task_tags=($(task _tags)) | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  | _task_zshids=( ${(f)"$(task _zshids)"} ) | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | _task_config=($(task _config)) | 
					
						
							| 
									
										
										
										
											2012-01-18 20:29:31 -05:00
										 |  |  | _task_columns=($(task _columns)) | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | _task_modifiers=( | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   'before' \ | 
					
						
							|  |  |  |   'after' \ | 
					
						
							|  |  |  |   'none' \ | 
					
						
							|  |  |  |   'any' \ | 
					
						
							|  |  |  |   'is' \ | 
					
						
							|  |  |  |   'isnt' \ | 
					
						
							|  |  |  |   'has' \ | 
					
						
							|  |  |  |   'hasnt' \ | 
					
						
							|  |  |  |   'startswith' \ | 
					
						
							|  |  |  |   'endswith' \ | 
					
						
							|  |  |  |   'word' \ | 
					
						
							|  |  |  |   'noword' | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2012-01-18 20:29:31 -05:00
										 |  |  | _task_conjunctions=( | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   'and' \ | 
					
						
							|  |  |  |   'or' \ | 
					
						
							|  |  |  |   'xor' \ | 
					
						
							|  |  |  |   '\)' \ | 
					
						
							|  |  |  |   '\(' \ | 
					
						
							|  |  |  |   '<' \ | 
					
						
							|  |  |  |   '<=' \ | 
					
						
							|  |  |  |   '=' \ | 
					
						
							|  |  |  |   '!=' \ | 
					
						
							|  |  |  |   '>=' \ | 
					
						
							|  |  |  |   '>' | 
					
						
							| 
									
										
										
										
											2012-01-18 20:29:31 -05:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  | _task_cmds=($(task _commands; task _aliases)) | 
					
						
							|  |  |  | _task_zshcmds=( ${(f)"$(task _zshcommands)"} sentinel:sentinel:sentinel ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | _task_aliases=($(task _aliases)) | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | _task() { | 
					
						
							|  |  |  |     _arguments -s -S \ | 
					
						
							| 
									
										
										
										
											2012-01-18 20:29:31 -05:00
										 |  |  |         "*::task default:_task_default" | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  |     return 0 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | local -a reply args word | 
					
						
							|  |  |  | word=$'[^\0]#\0' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # priorities | 
					
						
							|  |  |  | local -a task_priorities | 
					
						
							|  |  |  | _regex_words values 'task priorities' \ | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   'H:High' \ | 
					
						
							|  |  |  |   'M:Middle' \ | 
					
						
							|  |  |  |   'L:Low' | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | task_priorities=("$reply[@]") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # projects | 
					
						
							|  |  |  | local -a task_projects | 
					
						
							|  |  |  | task_projects=( | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   /"$word"/ | 
					
						
							|  |  |  |   ":values:task projects:compadd -a _task_projects" | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | local -a _task_dates | 
					
						
							|  |  |  | _regex_words values 'task dates' \ | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   'tod*ay:Today' \ | 
					
						
							|  |  |  |   'yes*terday:Yesterday' \ | 
					
						
							|  |  |  |   'tom*orrow:Tomorrow' \ | 
					
						
							|  |  |  |   'sow:Start of week' \ | 
					
						
							|  |  |  |   'soww:Start of work week' \ | 
					
						
							|  |  |  |   'socw:Start of calendar week' \ | 
					
						
							|  |  |  |   'som:Start of month' \ | 
					
						
							|  |  |  |   'soq:Start of quarter' \ | 
					
						
							|  |  |  |   'soy:Start of year' \ | 
					
						
							|  |  |  |   'eow:End of week' \ | 
					
						
							|  |  |  |   'eoww:End of work week' \ | 
					
						
							|  |  |  |   'eocw:End of calendar week' \ | 
					
						
							|  |  |  |   'eom:End of month' \ | 
					
						
							|  |  |  |   'eoq:End of quarter' \ | 
					
						
							|  |  |  |   'eoy:End of year' \ | 
					
						
							|  |  |  |   'mon:Monday' \ | 
					
						
							|  |  |  |   'tue:Tuesday'\ | 
					
						
							|  |  |  |   'wed:Wednesday' \ | 
					
						
							|  |  |  |   'thu:Thursday' \ | 
					
						
							|  |  |  |   'fri:Friday' \ | 
					
						
							|  |  |  |   'sat:Saturday' \ | 
					
						
							|  |  |  |   'sun:Sunday' \ | 
					
						
							|  |  |  |   'good*friday:Good Friday' \ | 
					
						
							|  |  |  |   'easter:Easter' \ | 
					
						
							|  |  |  |   'eastermonday:Easter Monday' \ | 
					
						
							|  |  |  |   'ascension:Ascension' \ | 
					
						
							|  |  |  |   'pentecost:Pentecost' \ | 
					
						
							|  |  |  |   'midsommar:Midsommar' \ | 
					
						
							|  |  |  |   'midsommarafton:Midsommarafton' \ | 
					
						
							|  |  |  |   'later:Later' \ | 
					
						
							|  |  |  |   'someday:Some Day' | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | _task_dates=("$reply[@]") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | local -a _task_reldates | 
					
						
							|  |  |  | _regex_words values 'task reldates' \ | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   'hrs:n hours' \ | 
					
						
							|  |  |  |   'day:n days' \ | 
					
						
							|  |  |  |   '1st:first' \ | 
					
						
							|  |  |  |   '2nd:second' \ | 
					
						
							|  |  |  |   '3rd:third' \ | 
					
						
							|  |  |  |   'th:4th, 5th, etc.' \ | 
					
						
							|  |  |  |   'wks:weeks' | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | _task_reldates=("$reply[@]") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | task_dates=( | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   \( "$_task_dates[@]" \| | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  |     \( /$'[0-9][0-9]#'/- \( "$_task_reldates[@]" \) \) | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   \) | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  | local -a task_zshids | 
					
						
							| 
									
										
										
										
											2016-06-17 11:43:08 +02:00
										 |  |  | if (( $#_task_zshids )); then | 
					
						
							|  |  |  |   _regex_words values 'task IDs' $_task_zshids | 
					
						
							|  |  |  |   task_zshids=("$reply[@]") | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | _regex_words values 'task frequencies' \ | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   'daily:Every day' \ | 
					
						
							|  |  |  |   'day:Every day' \ | 
					
						
							|  |  |  |   'weekdays:Every day skipping weekend days' \ | 
					
						
							|  |  |  |   'weekly:Every week' \ | 
					
						
							|  |  |  |   'biweekly:Every two weeks' \ | 
					
						
							|  |  |  |   'fortnight:Every two weeks' \ | 
					
						
							|  |  |  |   'monthly:Every month' \ | 
					
						
							|  |  |  |   'quarterly:Every three months' \ | 
					
						
							|  |  |  |   'semiannual:Every six months' \ | 
					
						
							|  |  |  |   'annual:Every year' \ | 
					
						
							|  |  |  |   'yearly:Every year' \ | 
					
						
							|  |  |  |   'biannual:Every two years' \ | 
					
						
							|  |  |  |   'biyearly:Every two years' | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | _task_freqs=("$reply[@]") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | local -a _task_frequencies | 
					
						
							|  |  |  | _regex_words values 'task frequencies' \ | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   'd:days' \ | 
					
						
							|  |  |  |   'w:weeks' \ | 
					
						
							|  |  |  |   'q:quarters' \ | 
					
						
							|  |  |  |   'y:years' | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | _task_frequencies=("$reply[@]") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | task_freqs=( | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   \( "$_task_freqs[@]" \| | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  |      \( /$'[0-9][0-9]#'/- \( "$_task_frequencies[@]" \) \) | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   \) | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # attributes | 
					
						
							|  |  |  | local -a task_attributes | 
					
						
							|  |  |  | _regex_words -t ':' default 'task attributes' \ | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   'des*cription:Task description text' \ | 
					
						
							|  |  |  |   'status:Status of task - pending, completed, deleted, waiting' \ | 
					
						
							|  |  |  |   'pro*ject:Project name:$task_projects' \ | 
					
						
							|  |  |  |   'pri*ority:priority:$task_priorities' \ | 
					
						
							|  |  |  |   'du*e:Due date:$task_dates' \ | 
					
						
							|  |  |  |   're*cur:Recurrence frequency:$task_freqs' \ | 
					
						
							|  |  |  |   'un*til:Expiration date:$task_dates' \ | 
					
						
							|  |  |  |   'li*mit:Desired number of rows in report' \ | 
					
						
							|  |  |  |   'wa*it:Date until task becomes pending:$task_dates' \ | 
					
						
							|  |  |  |   'ent*ry:Date task was created:$task_dates' \ | 
					
						
							|  |  |  |   'end:Date task was completed/deleted:$task_dates' \ | 
					
						
							|  |  |  |   'st*art:Date task was started:$task_dates' \ | 
					
						
							|  |  |  |   'sc*heduled:Date task is scheduled to start:$task_dates' \ | 
					
						
							|  |  |  |   'dep*ends:Other tasks that this task depends upon:$task_zshids' | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | task_attributes=("$reply[@]") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | args=( | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   \( "$task_attributes[@]" \| | 
					
						
							|  |  |  |   \( /'(project|description|status|entry|end|start|scheduled|depends|due|wait|recur|priority|until|limit).'/- \( /$'[^:]#:'/ ":default:modifiers:compadd -S ':' -a _task_modifiers" \) \) \| | 
					
						
							|  |  |  |   \( /'(rc).'/- \( /$'[^:]#:'/ ":arguments:config:compadd -S ':' -a _task_config" \) \) \| | 
					
						
							|  |  |  |   \( /'(+|-)'/- \( /"$word"/ ":values:remove tag:compadd -a _task_tags" \) \) \| | 
					
						
							|  |  |  |   \( /"$word"/ \) | 
					
						
							|  |  |  |   \) \# | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | ) | 
					
						
							|  |  |  | _regex_arguments _task_attributes "${args[@]}" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## task commands | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-18 20:29:31 -05:00
										 |  |  | # filter completion | 
					
						
							|  |  |  | (( $+functions[_task_filter] )) || | 
					
						
							|  |  |  | _task_filter() { | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   _task_attributes "$@" | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   # TODO complete conjunctions only if the previous word is a filter expression, i.e. attribute, ID, any non-command | 
					
						
							|  |  |  |   _describe -t default 'task conjunctions' _task_conjunctions | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-18 20:29:31 -05:00
										 |  |  | # execute completion | 
					
						
							|  |  |  | (( $+functions[_task_execute] )) || | 
					
						
							|  |  |  | _task_execute() { | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   _files | 
					
						
							| 
									
										
										
										
											2012-01-18 20:29:31 -05:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-18 20:29:31 -05:00
										 |  |  | # id-only completion | 
					
						
							|  |  |  | (( $+functions[_task_id] )) || | 
					
						
							|  |  |  | _task_id() { | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   _describe -t values 'task IDs' _task_zshids | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # subcommand-only function | 
					
						
							|  |  |  | (( $+functions[_task_subcommands] )) || | 
					
						
							|  |  |  | _task_subcommands() { | 
					
						
							|  |  |  |   local -a subcommands | 
					
						
							|  |  |  |   local _zshcmd | 
					
						
							|  |  |  |   local cmd category desc | 
					
						
							|  |  |  |   local lastcategory='' | 
					
						
							|  |  |  |   # The list is sorted by category, in the right order. | 
					
						
							|  |  |  |   for _zshcmd in "$_task_zshcmds[@]"; do | 
					
						
							|  |  |  |     # Parse out the three fields | 
					
						
							|  |  |  |     cmd=${_zshcmd%%:*} | 
					
						
							|  |  |  |     category=${${_zshcmd#*:}%%:*} | 
					
						
							|  |  |  |     desc=${_zshcmd#*:*:} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Present each category as soon as the first entry in the *next* category | 
					
						
							|  |  |  |     # is seen. | 
					
						
							|  |  |  |     if [[ $category != $lastcategory && -n $lastcategory ]]; then | 
					
						
							|  |  |  |       _describe -t ${lastcategory}-commands "task ${lastcategory} command" subcommands | 
					
						
							|  |  |  |       subcommands=() | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Log the subcommand; we will process it in some future iteration. | 
					
						
							|  |  |  |     subcommands+=( "$cmd:$desc" ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     lastcategory=$category | 
					
						
							|  |  |  |   done | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## first level completion => task sub-command completion | 
					
						
							| 
									
										
										
										
											2012-01-18 20:29:31 -05:00
										 |  |  | (( $+functions[_task_default] )) || | 
					
						
							|  |  |  | _task_default() { | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  |     local cmd ret=1 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  |   integer i=1 | 
					
						
							|  |  |  |   while (( i < $#words )) | 
					
						
							|  |  |  |   do | 
					
						
							|  |  |  |     cmd="${_task_cmds[(r)$words[$i]]}" | 
					
						
							|  |  |  |     if (( $#cmd )); then | 
					
						
							|  |  |  |       _call_function ret _task_${cmd} || | 
					
						
							|  |  |  |         _call_function ret _task_filter || | 
					
						
							|  |  |  |           _message "No command remaining." | 
					
						
							|  |  |  |       return ret | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |     (( i++ )) | 
					
						
							|  |  |  |   done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # update IDs | 
					
						
							|  |  |  |   _task_zshids=( ${(f)"$(task _zshids)"} ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   _task_subcommands | 
					
						
							|  |  |  |   _describe -t tasks 'task IDs' _task_zshids | 
					
						
							|  |  |  |   _describe -t aliases 'task aliases' _task_aliases | 
					
						
							|  |  |  |   _call_function ret _task_filter | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ret | 
					
						
							| 
									
										
										
										
											2011-05-24 15:28:42 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-02-11 20:30:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 20:43:11 +02:00
										 |  |  | _task "$@" |