]> Sergey Matveev's repositories - t.git/blob - t
Raise copyright years
[t.git] / t
1 #!/bin/sh -e
2 # t -- simple notes manager
3 # Copyright (C) 2013-2021 Sergey Matveev <stargrave@stargrave.org>
4 #
5 # Usage:
6 # * t -- just briefly print all notes: their number and stripped first
7 #   line of content
8 # * t N -- print N note's contents
9 # * t a [X X X] -- add a new note to the end. If arguments are specified
10 #   then they will be the content. Otherwise $EDITOR is started
11 # * t d N -- delete note number N. Pay attention that other notes may
12 #   change their numbers!
13 # * t m N -- edit note N with $EDITOR
14 # Also you can specify $N environment variable that acts like some kind
15 # of namespace for the notes (prepare directory first!). For example:
16 #     $ N=work t a get job done
17 #     $ N=work t a # it starts $EDITOR
18 #     $ N=work t
19 #     [0] get job done (1)
20 #     [1] this is first line of 3-lines comment (3)
21 #     $ N=work t d 0
22 #     $ N=work t
23 #     [0] this is first line of 3-lines comment (3)
24 #     $ t
25 #     [0] some earlier default namespace note (1)
26
27 NOTES_DIR=$HOME/.t/$N
28
29 purge()
30 {
31     find $NOTES_DIR -size 0 -delete
32 }
33
34 get_note()
35 {
36     find $NOTES_DIR -maxdepth 1 -type f | sort | sed -n $(($1 + 1))p
37 }
38
39 if [ -z "$1" ]; then
40     purge
41     cnt=0
42     for n in $(find $NOTES_DIR -maxdepth 1 -type f | sort); do
43         echo "[$cnt]" "$(sed 's/^\(.\{1,70\}\).*$/\1/;q' $n)" "($(sed -n '$=' $n))"
44         cnt=$(($cnt + 1))
45     done
46     exit 0
47 fi
48
49 case "$1" in
50 a)
51     shift
52     note=$NOTES_DIR/$(date "+%Y%m%d-%H%M%S")
53     [ $# -gt 0 ] && echo "$@" > $note || $EDITOR $note
54     ;;
55 d)
56     rm -f $(get_note $2)
57     ;;
58 m)
59     $EDITOR $(get_note $2)
60     ;;
61 *)
62     note=$(get_note $1)
63     [ -e "$note" ] && cat $note || exit 1
64     ;;
65 esac
66 purge