]> 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-2020 Sergey Matveev <stargrave@stargrave.org>
4 # Invoke the script without any arguments to briefly print all notes.
5 # Otherwise you can specify the following ones:
6 # a   -- add new note (either starts an editor if not arguments are specified,
7 #        or save them inside the note silently)
8 # d N -- delete note N
9 # m N -- modify note N by starting an editor
10 # N   -- print out note's N contents
11
12 NOTES_DIR=$HOME/.t/$N
13
14 purge()
15 {
16     find $NOTES_DIR -size 0 -delete
17 }
18
19 get_note()
20 {
21     find $NOTES_DIR -maxdepth 1 -type f | sort | sed -n $(($1 + 1))p
22 }
23
24 if [ -z "$1" ]; then
25     purge
26     cnt=0
27     for n in $(find $NOTES_DIR -maxdepth 1 -type f | sort); do
28         echo "[$cnt]" "$(sed 's/^\(.\{1,70\}\).*$/\1/;q' $n)" "($(sed -n '$=' $n))"
29         cnt=$(($cnt + 1))
30     done
31     exit 0
32 fi
33
34 case "$1" in
35 a)
36     shift
37     note=$NOTES_DIR/$(date '+%s')
38     [ $# -gt 0 ] && echo "$@" > $note || $EDITOR $note
39     ;;
40 d)
41     rm -f $(get_note $2)
42     ;;
43 m)
44     $EDITOR $(get_note $2)
45     ;;
46 *)
47     note=$(get_note $1)
48     [ -e "$note" ] && cat $note || exit 1
49     ;;
50 esac
51 purge