diff options
Diffstat (limited to 'note')
-rwxr-xr-x | note | 61 |
1 files changed, 61 insertions, 0 deletions
@@ -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 |