!/bin/sh

todo - operate on a todo.txt file

SPDX-FileCopyrightText: 2023 Daniel Kalak

SPDX-License-Identifier: GPL-3.0-or-later

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

Proxy Information
Original URL
gemini://dkalak.de/software/todo.sh
Status Code
Success (20)
Meta
text/plain
Capsule Response Time
116.172546 milliseconds
Gemini-to-HTML Time
0.784513 milliseconds

This content has been proxied by September (ba2dc).