1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-01 05:16:05 +01:00

Alexey: users/14588: ztodo function and completion

This commit is contained in:
Peter Stephenson 2009-11-22 19:17:32 +00:00
parent 3d8115275f
commit b7e76da2ef
2 changed files with 92 additions and 0 deletions

View file

@ -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 "$@"

62
Functions/Misc/ztodo Normal file
View file

@ -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}"}"