about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2006-09-13 16:11:44 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2006-09-13 16:11:44 +0000
commitefd061cdc9bdc0ba692387ec25eb6d01616d0425 (patch)
treeb57e0b5f6f52c3aadd05cc0921cfc2903b49a12e
parent6371325fdf6ca71e5f9839d65267f1d7c9a8863d (diff)
downloadzsh-efd061cdc9bdc0ba692387ec25eb6d01616d0425.tar.gz
zsh-efd061cdc9bdc0ba692387ec25eb6d01616d0425.tar.xz
zsh-efd061cdc9bdc0ba692387ec25eb6d01616d0425.zip
22704: new completion for todo.sh
-rw-r--r--ChangeLog4
-rw-r--r--Completion/Unix/Command/_todo.sh106
2 files changed, 110 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 98ad613de..efb8f978f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2006-09-13  Peter Stephenson  <pws@csr.com>
+
+	* 22704: Completion/Unix/Command/_todo.sh: new completion.
+
 2006-09-12  Peter Stephenson  <pws@csr.com>
 
 	* 22689: Src/subst.c, Test/D04parameter.ztst: untokenize
diff --git a/Completion/Unix/Command/_todo.sh b/Completion/Unix/Command/_todo.sh
new file mode 100644
index 000000000..583aa008c
--- /dev/null
+++ b/Completion/Unix/Command/_todo.sh
@@ -0,0 +1,106 @@
+#compdef todo.sh
+
+# See http://todotxt.com for todo.sh.
+#
+# Featurettes:
+#  - "replace" will complete the original text for editing.
+#  - completing priorities will cycle through A to Z (even without
+#    menu completion).
+
+setopt localoptions braceccl
+
+local expl curcontext="$curcontext" state line pri nextstate
+local -a cmdlist itemlist
+
+_arguments -s \
+  '-d[alternate config file]:config file:_files' \
+  '-f[force, no confirmation]' \
+  '-h[display help]' \
+  '-p[plain mode, no colours]' \
+  '-v[verbose mode, confirmation messages]' \
+  '-V[display version etc.]' \
+  '1:command:->commands' \
+  '2:first argument:->firstarg' \
+  '3:second argument:->secondarg' && return 0
+
+local txtmsg="text, can include p:<project> and @<where>"
+
+case $state in
+  (commands)
+  cmdlist=(
+    "add:Add TODO ITEM to todo.txt."
+    "append:Adds to item on line NUMBER the text TEXT."
+    "archive:Moves done items from todo.txt to done.txt."
+    "del:Deletes the item on line NUMBER in todo.txt."
+    "do:Marks item on line NUMBER as done in todo.txt."
+    "list:Displays all todo items containing TERM(s), sorted by priority."
+    "listall:Displays items including done ones containing TERM(s)"
+    "listpri:Displays all items prioritized at PRIORITY."
+    "prepend:Adds to the beginning of the item on line NUMBER text TEXT."
+    "pri:Adds or replace in NUMBER the priority PRIORITY (upper case letter)."
+    "replace:Replace in NUMBER the TEXT."
+    "remdup:Remove exact duplicates from todo.txt."
+    "report:Adds the number of open and done items to report.txt."
+  )
+  _describe -t todo-commands 'todo.sh command' cmdlist
+  ;;
+
+  (firstarg)
+  case $words[CURRENT-1] in
+    (append|del|do|prepend|pri|replace)
+    itemlist=(${${(M)${(f)"$(todo.sh list)"}##<-> *}/(#b)(<->) (*)/${match[1]}:${match[2]}})
+    _describe -t todo-items 'todo item' itemlist
+    ;;
+
+    (add)
+    _message $txtmsg
+    ;;
+
+    (list|listall)
+    _message search term...
+    ;;
+
+    (listpri)
+    nextstate=pri
+    ;;
+
+    (*)
+    return 1
+    ;;
+  esac
+  ;;
+
+  (secondarg)
+  case $words[CURRENT-2] in
+    (append|prepend)
+    _message $txtmsg
+    ;;
+    (pri)
+    nextstate=pri
+    ;;
+    (replace)
+    compadd -Q -- "${(qq)$(todo.sh list "^0*${words[CURRENT-1]} ")##<-> }"
+    ;;
+    (*)
+    return 1
+    ;;
+  esac
+  ;;
+esac
+
+case $nextstate in
+  (pri)
+  if [[ $words[CURRENT] = (|[A-Z]) ]]; then
+    if [[ $words[CURRENT] = (|Z) ]]; then
+      pri=A
+    else
+      # cycle priority
+      pri=$words[CURRENT]
+      pri=${(#)$(( #pri + 1 ))}
+    fi
+    _wanted priority expl 'priority' compadd -U -S '' -- $pri
+  else
+    _wanted priority expl 'priority' compadd {A-Z}
+  fi
+  ;;
+esac