2 # t -- simple notes manager
3 # Copyright (C) 2013-2024 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)
28 setopt ERR_EXIT NULL_GLOB
30 NOTES_DIR=${NOTES_DIR%/}
33 local empties=($NOTES_DIR/*(.L0))
34 [[ $empties ]] && rm $empties || :
38 [[ "$1" = [0-9]* ]] || { print invalid note id ; exit 1 }
39 NOTE=($NOTES_DIR/*(.on[$(( $1 + 1 ))]))
40 [[ ${#NOTE} -eq 0 ]] && { print note not found >&2 ; exit 1 }
47 for note ($NOTES_DIR/*(.on)) {
49 print -n "[$ctr] ${line[1,70]} "
50 [[ ${#line} -le 70 ]] || print -n "... "
51 lines=$(wc -l < $note)
52 printf "(%d)\n" $lines
60 zmodload -F zsh/datetime b:strftime
61 note=$NOTES_DIR/$(strftime %Y%m%d-%H%M%S)
62 [[ $# -gt 1 ]] && print -- ${@[2,-1]} > $note || $EDITOR $note
64 (d) get_note $2 ; rm -f $NOTE ;;
65 (m) get_note $2 ; $EDITOR $NOTE ;;
66 (*) get_note $1 ; cat $NOTE ;;