_task 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. _task() {
  59. _arguments -s -S \
  60. "*::task default:_task_default"
  61. return 0
  62. }
  63. local -a reply args word
  64. word=$'[^\0]#\0'
  65. # priorities
  66. local -a task_priorities
  67. _regex_words values 'task priorities' \
  68. 'H:High' \
  69. 'M:Middle' \
  70. 'L:Low'
  71. task_priorities=("$reply[@]")
  72. # projects
  73. local -a task_projects
  74. task_projects=(
  75. /"$word"/
  76. ":values:task projects:compadd -a _task_projects"
  77. )
  78. local -a _task_dates
  79. _regex_words values 'task dates' \
  80. 'tod*ay:Today' \
  81. 'yes*terday:Yesterday' \
  82. 'tom*orrow:Tomorrow' \
  83. 'sow:Start of week' \
  84. 'soww:Start of work week' \
  85. 'socw:Start of calendar week' \
  86. 'som:Start of month' \
  87. 'soy:Start of year' \
  88. 'eow:End of week' \
  89. 'eoww:End of work week' \
  90. 'eocw:End of calendar week' \
  91. 'eom:End of month' \
  92. 'eoy:End of year' \
  93. 'mon:Monday' \
  94. 'tue:Tuesday'\
  95. 'wed:Wednesday' \
  96. 'thu:Thursday' \
  97. 'fri:Friday' \
  98. 'sat:Saturday' \
  99. 'sun:Sunday'
  100. _task_dates=("$reply[@]")
  101. local -a _task_reldates
  102. _regex_words values 'task reldates' \
  103. 'hrs:n hours' \
  104. 'day:n days' \
  105. '1st:first' \
  106. '2nd:second' \
  107. '3rd:third' \
  108. 'th:4th, 5th, etc.' \
  109. 'wks:weeks'
  110. _task_reldates=("$reply[@]")
  111. task_dates=(
  112. \( "$_task_dates[@]" \|
  113. \( /$'[0-9][0-9]#'/- \( "$_task_reldates[@]" \) \)
  114. \)
  115. )
  116. _regex_words values 'task frequencies' \
  117. 'daily:Every day' \
  118. 'day:Every day' \
  119. 'weekdays:Every day skipping weekend days' \
  120. 'weekly:Every week' \
  121. 'biweekly:Every two weeks' \
  122. 'fortnight:Every two weeks' \
  123. + 'monthly:Every month' \
  124. 'quarterly:Every three months' \
  125. 'semiannual:Every six months' \
  126. 'annual:Every year' \
  127. 'yearly:Every year' \
  128. 'biannual:Every two years' \
  129. 'biyearly:Every two years'
  130. _task_freqs=("$reply[@]")
  131. local -a _task_frequencies
  132. _regex_words values 'task frequencies' \
  133. 'd:days' \
  134. 'w:weeks' \
  135. 'q:quarters' \
  136. 'y:years'
  137. _task_frequencies=("$reply[@]")
  138. task_freqs=(
  139. \( "$_task_freqs[@]" \|
  140. \( /$'[0-9][0-9]#'/- \( "$_task_frequencies[@]" \) \)
  141. \)
  142. )
  143. # attributes
  144. local -a task_attributes
  145. _regex_words -t ':' default 'task attributes' \
  146. 'pro*ject:Project name:$task_projects' \
  147. 'du*e:Due date:$task_dates' \
  148. 'wa*it:Date until task becomes pending:$task_dates' \
  149. 're*cur:Recurrence frequency:$task_freqs' \
  150. 'pri*ority:priority:$task_priorities' \
  151. 'un*til:Recurrence end date:$task_dates' \
  152. 'fg:Foreground color' \
  153. 'bg:Background color' \
  154. 'li*mit:Desired number of rows in report'
  155. task_attributes=("$reply[@]")
  156. args=(
  157. \( "$task_attributes[@]" \|
  158. \( /'(project|due|wait|recur|priority|until|fg|bg|limit).'/- \( /$'[^:]#:'/ ":default:modifiers:compadd -S ':' -a _task_modifiers" \) \) \|
  159. \( /'(rc).'/- \( /$'[^:]#:'/ ":arguments:config:compadd -S ':' -a _task_config" \) \) \|
  160. \( /'(+|-)'/- \( /"$word"/ ":values:remove tag:compadd -a _task_tags" \) \) \|
  161. \( /"$word"/ \)
  162. \) \#
  163. )
  164. _regex_arguments _task_attributes "${args[@]}"
  165. ## task commands
  166. # filter completion
  167. (( $+functions[_task_filter] )) ||
  168. _task_filter() {
  169. _task_attributes "$@"
  170. # TODO complete conjunctions only if the previous word is a filter expression, i.e. attribute, ID, any non-command
  171. _describe -t default 'task conjunctions' _task_conjunctions
  172. }
  173. # merge completion
  174. (( $+functions[_task_merge] )) ||
  175. _task_merge() {
  176. # TODO match URIs in .taskrc
  177. _files
  178. }
  179. # push completion
  180. (( $+functions[_task_push] )) ||
  181. _task_push() {
  182. # TODO match URIs in .taskrc
  183. _files
  184. }
  185. # pull completion
  186. (( $+functions[_task_pull] )) ||
  187. _task_pull() {
  188. # TODO match URIs in .taskrc
  189. _files
  190. }
  191. # execute completion
  192. (( $+functions[_task_execute] )) ||
  193. _task_execute() {
  194. _files
  195. }
  196. # id-only completion
  197. (( $+functions[_task_id] )) ||
  198. _task_id() {
  199. _describe -t values 'task IDs' _task_zshids
  200. }
  201. ## first level completion => task sub-command completion
  202. (( $+functions[_task_default] )) ||
  203. _task_default() {
  204. local cmd ret=1
  205. integer i=1
  206. while (( i < $#words ))
  207. do
  208. cmd="${_task_cmds[(r)$words[$i]]}"
  209. if (( $#cmd )); then
  210. _call_function ret _task_${cmd} ||
  211. _call_function ret _task_filter ||
  212. _message "No command remaining."
  213. return ret
  214. fi
  215. (( i++ ))
  216. done
  217. # update IDs
  218. _task_zshids=( ${(f)"$(task _zshids)"} )
  219. _describe -t commands 'task command' _task_zshcmds
  220. _describe -t values 'task IDs' _task_zshids
  221. _call_function ret _task_filter
  222. return ret
  223. }
  224. _task