todotxt="${TODOTXT:-"${HOME:?}/todo"}"
donetxt="${DONETXT:-"${HOME:?}/done"}"
editor="${EDITOR:-nano}"
usage() {
cat <<- EOF >&2
Usage:
$(basename "$0") COMMAND
Commands:
h|help: Show this information
[show]: Page todo, sorted
r|random [N]: Print N (5) random lines from todo, sorted
e|edit: Edit todo
s|sort: Sort todo in-place
d|done: Page x tasks (from todo and done), sorted
x|extract: Move x tasks from todo to done
p|projects: Print project tags in todo, sorted
c|contexts: Print context tags in todo, sorted
[--|search] PATTERN: Print lines in todo matching PATTERN, sorted
Environment:
todo: using "$todotxt", change with TODOTXT
done: using "$donetxt", change with DONETXT
editor: using "$editor", change with EDITOR
EOF
}
search() {
grep -e "$1" "$todotxt" | LC_ALL=C sort
}
case "$1" in
h|help)
usage
;;
''|show)
LC_ALL=C sort "$todotxt" | less
;;
r|random)
shuf -n "${2:-5}" "$todotxt" | LC_ALL=C sort
;;
e|edit)
exec $editor "$todotxt"
;;
s|sort)
temp="$(mktemp)"
LC_ALL=C sort "$todotxt" > "$temp"
mv -i "$temp" "$todotxt"
;;
d|'done')
if [ -f "$donetxt" ]
then grep '^x ' "$todotxt" | cat - "$donetxt" | LC_ALL=C sort | less
else grep '^x ' "$todotxt" | LC_ALL=C sort | less
fi
;;
x|extract)
grep '^x ' "$todotxt" >> "$donetxt"
temp="$(mktemp)"
grep -v '^x ' "$todotxt" > "$temp"
mv "$temp" "$todotxt"
;;
p|projects)
grep -o '+[^ ]*' "$todotxt" | LC_ALL=C sort | uniq
;;
c|contexts)
grep -o '@[^ ]*' "$todotxt" | LC_ALL=C sort | uniq
;;
--|search)
search "$2"
;;
search "$1"
;;
esac
text/plain
This content has been proxied by September (ba2dc).