2 # t -- simple notes manager
3 # Copyright (C) 2013-2023 Sergey Matveev <stargrave@stargrave.org>
4 # Current version is written on Z shell. Previous was on POSIX shell.
7 # * t -- just briefly print all notes: their number and stripped first
9 # * t N -- print N note's contents
10 # * t a [X X X] -- add a new note to the end. If arguments are specified
11 # then they will be the content. Otherwise $EDITOR is started
12 # * t d N -- delete note number N. Pay attention that other notes may
13 # change their numbers!
14 # * t m N -- edit note N with $EDITOR
15 # Also you can specify $N environment variable that acts like some kind
16 # of namespace for the notes (prepare directory first!). For example:
17 # $ N=work t a get job done
18 # $ N=work t a # it starts $EDITOR
20 # [0] get job done (1)
21 # [1] this is first line of 3-lines comment (3)
24 # [0] this is first line of 3-lines comment (3)
26 # [0] some earlier default namespace note (1)
31 NOTES_DIR=${NOTES_DIR%/}
34 local empties=($NOTES_DIR/*(.L0))
35 [[ $empties ]] && rm $empties || :
39 [[ "$1" = [0-9]* ]] || { print invalid note id ; exit 1 }
40 NOTE=($NOTES_DIR/*(.on[$(( $1 + 1 ))]))
41 [[ ${#NOTE} -eq 0 ]] && { print note not found >&2 ; exit 1 }
48 for note ($NOTES_DIR/*(.on)) {
50 print -n "[$ctr] ${line[1,70]} "
51 [[ ${#line} -le 70 ]] || print -n "... "
52 lines=$(wc -l < $note)
53 printf "(%d)\n" $lines
61 zmodload -F zsh/datetime b:strftime
62 note=$NOTES_DIR/$(strftime %Y%m%d-%H%M%S)
63 [[ $# -gt 1 ]] && print -- ${@[2,-1]} > $note || $EDITOR $note
65 (d) get_note $2 ; rm -f $NOTE ;;
66 (m) get_note $2 ; $EDITOR $NOTE ;;
67 (*) get_note $1 ; cat $NOTE ;;