]> Sergey Matveev's repositories - t.git/commitdiff
Initial revision
authorSergey Matveev <stargrave@stargrave.org>
Thu, 29 Oct 2015 08:36:06 +0000 (11:36 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 29 Oct 2015 08:36:06 +0000 (11:36 +0300)
t [new file with mode: 0755]

diff --git a/t b/t
new file mode 100755 (executable)
index 0000000..35a5e53
--- /dev/null
+++ b/t
@@ -0,0 +1,50 @@
+#!/bin/sh -e
+# t -- simple notes manager
+# Copyright (C) 2013-2015 Sergey Matveev <stargrave@stargrave.org>
+# Invoke the script without any arguments to briefly print all notes.
+# Otherwise you can specify the following ones:
+# a   -- add new note (either starts an editor if not arguments are specified,
+#        or save them inside the note silently)
+# d N -- delete note N
+# m N -- modify note N by starting an editor
+# N   -- print out note's N contents
+
+NOTES_DIR=$HOME/.t/$N
+
+purge()
+{
+    find $NOTES_DIR -size 0 -delete
+}
+
+get_note()
+{
+    find $NOTES_DIR -maxdepth 1 -type f | sort | sed -n $(($1 + 1))p
+}
+
+if [ -z "$1" ]; then
+    purge
+    cnt=0
+    for n in $(find $NOTES_DIR -maxdepth 1 -type f | sort); do
+        echo "[$cnt]" "$(sed 's/^\(.\{1,70\}\).*$/\1/;q' $n)" "($(sed -n '$=' $n))"
+        cnt=$(($cnt + 1))
+    done
+    exit 0
+fi
+
+case "$1" in
+a)
+    shift
+    note=$NOTES_DIR/$(date '+%s')
+    [ $# -gt 0 ] && echo "$@" > $note || $EDITOR $note
+    ;;
+d)
+    rm -f $(get_note $2)
+    ;;
+m)
+    $EDITOR $(get_note $2)
+    ;;
+*)
+    cat $(get_note $1)
+    ;;
+esac
+purge