2 # t -- simple notes manager
3 # Copyright (C) 2013-2021 Sergey Matveev <stargrave@stargrave.org>
4 # Current version is written on zsh. 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 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 note=$NOTES_DIR/$(date "+%Y%m%d-%H%M%S")
61 [[ $# -gt 1 ]] && print -- ${@[2,-1]} > $note || $EDITOR $note
63 (d) get_note $2 ; rm -f $NOTE ;;
64 (m) get_note $2 ; $EDITOR $NOTE ;;
65 (*) get_note $1 ; cat $NOTE ;;