_task 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. #compdef task
  2. #
  3. # zsh completion for taskwarrior
  4. #
  5. # Copyright 2010 - 2011 Johannes Schlatow
  6. # Copyright 2009 P.C. Shyamshankar
  7. # All rights reserved.
  8. #
  9. # This script is part of the taskwarrior project.
  10. #
  11. # This program is free software; you can redistribute it and/or modify it under
  12. # the terms of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. #
  16. # This program is distributed in the hope that it will be useful, but WITHOUT
  17. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  18. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  19. # details.
  20. #
  21. # You should have received a copy of the GNU General Public License along with
  22. # this program; if not, write to the
  23. #
  24. # Free Software Foundation, Inc.,
  25. # 51 Franklin Street, Fifth Floor,
  26. # Boston, MA
  27. # 02110-1301
  28. # USA
  29. #
  30. typeset -g _task_cmds _task_projects _task_tags _task_config _task_modifiers
  31. _task_projects=($(task _projects))
  32. _task_tags=($(task _tags))
  33. _task_ids=($(task _ids))
  34. _task_config=($(task _config))
  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_cmds=($(task _commands))
  50. _task_zshcmds=( ${(f)"$(task _zshcommands)"} )
  51. _task_idCmds=(
  52. 'append' \
  53. 'prepend' \
  54. 'annotate' \
  55. 'denotate' \
  56. 'edit' \
  57. 'duplicate' \
  58. 'info' \
  59. 'start' \
  60. 'stop' \
  61. 'done'
  62. )
  63. _task_idCmdsDesc=(
  64. 'append:Appends more description to an existing task.' \
  65. 'prepend:Prepends more description to an existing task.' \
  66. 'annotate:Adds an annotation to an existing task.' \
  67. 'denotate:Deletes an annotation of an existing task.' \
  68. 'edit:Launches an editor to let you modify a task directly.' \
  69. 'duplicate:Duplicates the specified task, and allows modifications.' \
  70. 'info:Shows all data, metadata for specified task.' \
  71. 'start:Marks specified task as started.' \
  72. 'stop:Removes the start time from a task.' \
  73. 'done:Marks the specified task as completed.'
  74. )
  75. _task() {
  76. _arguments -s -S \
  77. "*::task command:_task_commands"
  78. return 0
  79. }
  80. local -a reply args word
  81. word=$'[^\0]#\0'
  82. # priorities
  83. local -a task_priorities
  84. _regex_words values 'task priorities' \
  85. 'H:High' \
  86. 'M:Middle' \
  87. 'L:Low'
  88. task_priorities=("$reply[@]")
  89. # projects
  90. local -a task_projects
  91. task_projects=(
  92. /"$word"/
  93. ":values:task projects:compadd -a _task_projects"
  94. )
  95. local -a _task_dates
  96. _regex_words values 'task dates' \
  97. 'tod*ay:Today' \
  98. 'yes*terday:Yesterday' \
  99. 'tom*orrow:Tomorrow' \
  100. 'sow:Start of week' \
  101. 'soww:Start of work week' \
  102. 'socw:Start of calendar week' \
  103. 'som:Start of month' \
  104. 'soy:Start of year' \
  105. 'eow:End of week' \
  106. 'eoww:End of work week' \
  107. 'eocw:End of calendar week' \
  108. 'eom:End of month' \
  109. 'eoy:End of year' \
  110. 'mon:Monday' \
  111. 'tue:Tuesday'\
  112. 'wed:Wednesday' \
  113. 'thu:Thursday' \
  114. 'fri:Friday' \
  115. 'sat:Saturday' \
  116. 'sun:Sunday'
  117. _task_dates=("$reply[@]")
  118. local -a _task_reldates
  119. _regex_words values 'task reldates' \
  120. 'hrs:n hours' \
  121. 'day:n days' \
  122. '1st:first' \
  123. '2nd:second' \
  124. '3rd:third' \
  125. 'th:4th, 5th, etc.' \
  126. 'wks:weeks'
  127. _task_reldates=("$reply[@]")
  128. task_dates=(
  129. \( "$_task_dates[@]" \|
  130. \( /$'[0-9][0-9]#'/- \( "$_task_reldates[@]" \) \)
  131. \)
  132. )
  133. _regex_words values 'task frequencies' \
  134. 'daily:Every day' \
  135. 'day:Every day' \
  136. 'weekdays:Every day skipping weekend days' \
  137. 'weekly:Every week' \
  138. 'biweekly:Every two weeks' \
  139. 'fortnight:Every two weeks' \
  140. 'quarterly:Every three months' \
  141. 'semiannual:Every six months' \
  142. 'annual:Every year' \
  143. 'yearly:Every year' \
  144. 'biannual:Every two years' \
  145. 'biyearly:Every two years'
  146. _task_freqs=("$reply[@]")
  147. local -a _task_frequencies
  148. _regex_words values 'task frequencies' \
  149. 'd:days' \
  150. 'w:weeks' \
  151. 'q:quarters' \
  152. 'y:years'
  153. _task_frequencies=("$reply[@]")
  154. task_freqs=(
  155. \( "$_task_freqs[@]" \|
  156. \( /$'[0-9][0-9]#'/- \( "$_task_frequencies[@]" \) \)
  157. \)
  158. )
  159. # attributes
  160. local -a task_attributes
  161. _regex_words -t ':' default 'task attributes' \
  162. 'pro*ject:Project name:$task_projects' \
  163. 'du*e:Due date:$task_dates' \
  164. 'wa*it:Date until task becomes pending:$task_dates' \
  165. 're*cur:Recurrence frequency:$task_freqs' \
  166. 'pri*ority:priority:$task_priorities' \
  167. 'un*til:Recurrence end date:$task_dates' \
  168. 'fg:Foreground color' \
  169. 'bg:Background color' \
  170. 'li*mit:Desired number of rows in report'
  171. task_attributes=("$reply[@]")
  172. args=(
  173. \( "$task_attributes[@]" \|
  174. \( /'(project|due|wait|recur|priority|until|fg|bg|limit).'/- \( /$'[^:]#:'/ ":default:modifiers:compadd -S ':' -a _task_modifiers" \) \) \|
  175. \( /'(rc).'/- \( /$'[^:]#:'/ ":arguments:config:compadd -S ':' -a _task_config" \) \) \|
  176. \( /'(+|-)'/- \( /"$word"/ ":values:remove tag:compadd -a _task_tags" \) \) \|
  177. \( /"$word"/ \)
  178. \) \#
  179. )
  180. _regex_arguments _task_attributes "${args[@]}"
  181. ## task commands
  182. # default completion
  183. (( $+functions[_task_default] )) ||
  184. _task_default() {
  185. _task_attributes "$@"
  186. }
  187. # commands expecting an ID
  188. (( $+functions[_task_id] )) ||
  189. _task_id() {
  190. if (( CURRENT < 3 )); then
  191. # update IDs
  192. _task_zshids=( ${(f)"$(task _zshids)"} )
  193. _describe -t values 'task IDs' _task_zshids
  194. else
  195. _task_attributes "$@"
  196. fi
  197. }
  198. # merge completion
  199. (( $+functions[_task_merge] )) ||
  200. _task_merge() {
  201. # TODO match URIs in .taskrc
  202. _files
  203. }
  204. # push completion
  205. (( $+functions[_task_push] )) ||
  206. _task_push() {
  207. # TODO match URIs in .taskrc
  208. _files
  209. }
  210. # pull completion
  211. (( $+functions[_task_pull] )) ||
  212. _task_pull() {
  213. # TODO match URIs in .taskrc
  214. _files
  215. }
  216. # modify (task [0-9]* ...) completion
  217. (( $+functions[_task_modify] )) ||
  218. _task_modify() {
  219. _describe -t commands 'task command' _task_idCmdsDesc
  220. _task_attributes "$@"
  221. }
  222. ## first level completion => task sub-command completion
  223. (( $+functions[_task_commands] )) ||
  224. _task_commands() {
  225. local cmd ret=1
  226. if (( CURRENT == 1 )); then
  227. # update IDs
  228. _task_zshids=( ${(f)"$(task _zshids)"} )
  229. _describe -t commands 'task command' _task_zshcmds
  230. _describe -t values 'task IDs' _task_zshids
  231. # TODO match more than one ID
  232. elif [[ $words[1] =~ ^[0-9]*$ ]] then
  233. _call_function ret _task_modify
  234. return ret
  235. else
  236. # local curcontext="${curcontext}"
  237. # cmd="${_task_cmds[(r)$words[1]:*]%%:*}"
  238. cmd="${_task_cmds[(r)$words[1]]}"
  239. idCmd="${(M)_task_idCmds[@]:#$words[1]}"
  240. if (( $#cmd )); then
  241. # curcontext="${curcontext%:*:*}:task-${cmd}"
  242. if (( $#idCmd )); then
  243. _call_function ret _task_id
  244. else
  245. _call_function ret _task_${cmd} ||
  246. _call_function ret _task_default ||
  247. _message "No command remaining."
  248. fi
  249. else
  250. _message "Unknown subcommand ${cmd}"
  251. fi
  252. return ret
  253. fi
  254. }