zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] ztodo: simple per-directory todo list manager (+completion)
@ 2009-11-21 17:30 Alexey I. Froloff
  2009-11-22 13:14 ` Panagiotis Atmatzidis
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey I. Froloff @ 2009-11-21 17:30 UTC (permalink / raw)
  To: Zsh list; +Cc: Zsh user list, Alexey I. Froloff

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@altlinux.org>
---
 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ztodo: simple per-directory todo list manager (+completion)
  2009-11-21 17:30 [PATCH] ztodo: simple per-directory todo list manager (+completion) Alexey I. Froloff
@ 2009-11-22 13:14 ` Panagiotis Atmatzidis
  0 siblings, 0 replies; 2+ messages in thread
From: Panagiotis Atmatzidis @ 2009-11-22 13:14 UTC (permalink / raw)
  To: Alexey I. Froloff; +Cc: Zsh list, Zsh user list


On 21 Νοε 2009, at 7:30 μ.μ., Alexey I. Froloff wrote:

> 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@altlinux.org>
> ---
> 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
> 


Uh that's a smart one!

Thanks for sharing. Now I need to find a way to drop into my mac mini running tiger. I'll patch the file and foce installation.

Does this work with prior 4.3.10 versions? (I know it should, just asking)

regads

Panagiotis (atmosx) Atmatzidis

email:	atma@convalesco.org
URL:	http://www.convalesco.org
GnuPG ID: 0xFC4E8BB4 
gpg --keyserver x-hkp://pgp.mit.edu --recv-keys 0xFC4E8BB4
--
The wise man said: "Never argue with an idiot. They bring you down to their level and beat you with experience."


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-11-22 13:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-21 17:30 [PATCH] ztodo: simple per-directory todo list manager (+completion) Alexey I. Froloff
2009-11-22 13:14 ` Panagiotis Atmatzidis

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).