Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] ztodo: simple per-directory todo list manager (+completion)



I'm doing a lot of packaging/development jobs in different git
repositories.  Sometimes certain things needs to be done, but it's not
time to commit anything yet.  I am too lazy to use other TODO list
managers and often I just fail to remember that should be done in this
repository.

ztodo keeps per-path todo lists.  Entries are kept in associative array
(key is path) and cached in ~/.ztodolist file.  I've added ztodo call to
chpwd() finction, so I get reminder whenever I chdir to a directory.

.zshrc:
autoload -Uz ztodo
chpwd() { ztodo }

Sample session:

~ $ cd src
~/src $ ztodo add 'Collect underpants'
~/src $ ztodo add '?'
~/src $ ztodo add 'PROFIT!'
~/src $ cd .
You have 3 things to do here.
~/src $ ztodo list
 1: Collect underpants
 2: ?
 3: PROFIT!
~/src $ ztodo del 2
~/src $ ztodo list
 1: Collect underpants
 2: PROFIT!
~/src $ ztodo clear
~/src $ ztodo list
~/src $

Signed-off-by: Alexey I. Froloff <raorn@xxxxxxxxxxxx>
---
 Completion/Zsh/Command/.distfiles |    1 +
 Completion/Zsh/Command/_ztodo     |   30 ++++++++++++++++++
 Functions/Misc/.distfiles         |    1 +
 Functions/Misc/ztodo              |   62 +++++++++++++++++++++++++++++++++++++
 4 files changed, 94 insertions(+), 0 deletions(-)
 create mode 100644 Completion/Zsh/Command/_ztodo
 create mode 100644 Functions/Misc/ztodo

diff --git a/Completion/Zsh/Command/.distfiles b/Completion/Zsh/Command/.distfiles
index 9e8e6ad..6feec49 100644
--- a/Completion/Zsh/Command/.distfiles
+++ b/Completion/Zsh/Command/.distfiles
@@ -46,4 +46,5 @@ _zmodload
 _zmv
 _zpty
 _zstyle
+_ztodo
 '
diff --git a/Completion/Zsh/Command/_ztodo b/Completion/Zsh/Command/_ztodo
new file mode 100644
index 0000000..73be91e
--- /dev/null
+++ b/Completion/Zsh/Command/_ztodo
@@ -0,0 +1,30 @@
+#compdef ztodo
+
+_ztodo_entries() {
+  local -a entries
+
+  entries=(${${${${(f)"$(_call_program ztodo-entry ztodo list)"}#[[:space:]]##}/:[[:space:]]##/:}%:[[:space:]]#})
+  _describe -t ztodo-entry 'todo entry' entries "$@"
+}
+
+local -a args reply
+args=(
+  /$'[^\0]#\0'/
+)
+
+local -a todo_entry
+todo_entry=(
+  /$'[^\0]#\0'/ ':ztodo-entry:todo entry:_ztodo_entries'
+)
+
+_regex_words \
+  commands "ztodo command" \
+  'add:add entry' \
+  'del:delete entry:$todo_entry' \
+  'clear:clear todo list' \
+  'list:show todo list'
+args+=("$reply[@]")
+
+_regex_arguments _ztodo "${args[@]}"
+
+_ztodo "$@"
diff --git a/Functions/Misc/.distfiles b/Functions/Misc/.distfiles
index 4c74bbe..4ffbec1 100644
--- a/Functions/Misc/.distfiles
+++ b/Functions/Misc/.distfiles
@@ -26,4 +26,5 @@ zmathfuncdef
 zmv
 zrecompile
 zstyle+
+ztodo
 '
diff --git a/Functions/Misc/ztodo b/Functions/Misc/ztodo
new file mode 100644
index 0000000..439f3c5
--- /dev/null
+++ b/Functions/Misc/ztodo
@@ -0,0 +1,62 @@
+# vim: set ft=zsh et sw=2 sts=2:
+
+emulate -L zsh
+setopt no_sh_word_split null_glob no_ksh_arrays
+typeset -gHA __ztodolist
+typeset -gH __ztodolastwrite
+local cachefile short_format list_format
+local tmp needupdate=0
+local -a todos
+
+zstyle -s ':ztodo:*' cache-file cachefile ||
+  cachefile="~/.ztodolist"
+zstyle -s ':ztodo:*' short-format short_format ||
+  short_format="You have %n thing%1(n..s) to do here."
+zstyle -s ':ztodo:*' list-format list_format ||
+  list_format="%-2n: %e"
+
+tmp=(${~tmp::=$cachefile(ms-$(( ${(%)tmp::="%D{%s}"} - ${__ztodolastwrite:-0} )))})
+(( $#tmp )) &&
+  . $~cachefile
+
+todos=( ${(ps:\0:)__ztodolist[$PWD]} )
+
+if (( $# )); then
+  case "$1" in
+    (add)
+      shift
+      todos=( $todos "$*" )
+      needupdate=1
+      ;;
+    (del)
+      shift
+      todos[$1]=()
+      needupdate=1
+      ;;
+    (clear)
+      shift
+      todos=()
+      needupdate=1
+      ;;
+    (list)
+      shift
+      local i
+      for (( i = 1; i <= $#todos; i++ )); do
+        zformat -f tmp $list_format n:$i e:"${todos[$i]//\%/%%}"
+        print -P "$tmp"
+      done
+      ;;
+  esac
+else
+  if [[ $#todos -gt 0 ]]; then
+    zformat -f tmp $short_format n:$#todos
+    print -P "$tmp"
+  fi
+fi
+
+(( $#todos )) &&
+  __ztodolist[$PWD]=${(pj:\0:)todos} ||
+  unset "__ztodolist[$PWD]"
+(( needupdate )) &&
+  print -r "__ztodolist=( ${(kv@qq)^^__ztodolist} )" > ${~cachefile}
+__ztodolastwrite="${(%)tmp::="%D{%s}"}"
-- 
1.6.5.3



Messages sorted by: Reverse Date, Date, Thread, Author