summaryrefslogtreecommitdiff
path: root/note
diff options
context:
space:
mode:
authortsxv478 <vt0451@yandex.ru>2022-09-21 04:14:01 +0300
committertsxv478 <vt0451@yandex.ru>2022-09-21 04:14:01 +0300
commitec464ea5e64998c0b55dad9b8dd77261cb580ad3 (patch)
treed109453b5b86d03c1f34609e01d023bdc94700a2 /note
parente5af6d63208376a7f1c5ac5636bcd6614cf78bf2 (diff)
note script
Diffstat (limited to 'note')
-rwxr-xr-xnote61
1 files changed, 61 insertions, 0 deletions
diff --git a/note b/note
new file mode 100755
index 0000000..eae8cf0
--- /dev/null
+++ b/note
@@ -0,0 +1,61 @@
+#!/bin/sh
+
+set -e
+notesdir="$HOME/.local/share/notes"
+
+print_usage() {
+ cat << EOF
+usage: note [option]
+ -h show this help message
+ -a append note to the main file
+ -d append using dmenu
+ -e edit the main file
+ -s show last 10 notes
+ -n create a new file
+ -l open file in pager
+EOF
+}
+
+append_note() {
+ echo -n "note: " && read -r note
+ printf "[$(date +'%d/%m/%Y, %H:%M')] %s\n\n" "$note" >> $notesdir/notes.txt
+}
+
+edit_file() {
+ $EDITOR $notesdir/notes.txt
+}
+
+show_last() {
+ tail -n 20 $notesdir/notes.txt
+}
+
+new_file() {
+ echo -n "title: " && read -r title
+ $EDITOR $notesdir/$title.txt
+}
+
+open_pager() {
+ find $notesdir -type f -printf "%p\n" |
+ fzf -e +s --reverse --with-nth -1 -d '/' --preview "cat {}" \
+ --preview-window=right:75%:sharp | xargs -ro less
+}
+
+dmenu_note() {
+ note="$(echo "\c" | dmenu -c -bw 3 -p 'Note:')"
+ printf "[$(date +'%d/%m/%Y, %H:%M')] %s\n\n" "$note" >> $notesdir/notes.txt
+}
+
+[ $# -eq 0 ] && print_usage
+
+while getopts "hadesnl" o; do
+ case "${o}" in
+ h) print_usage ;;
+ a) append_note ;;
+ d) dmenu_note ;;
+ e) edit_file ;;
+ s) show_last ;;
+ n) new_file ;;
+ l) open_pager ;;
+ *) print_usage ; exit 1 ;;
+ esac
+done