7 EDITOR
=${EDITOR:-/usr/bin/vim}
8 BASEDIR
=${BASEDIR:-~/.bash-notes}
11 NOTESDIR
=${BASEDIR}/notes
12 BASENAME
=$
( basename $0 )
13 TERMINAL
=${TERMINAL:-/usr/bin/alacritty}
17 echo "jq not found in your PATH"
18 echo "install jq to continue"
22 # We prevent the program from running more than one instance:
23 PIDFILE
=/var
/tmp
/$
(basename $0 .sh
).pid
25 # Make sure the PID file is removed when we kill the process
26 trap 'rm -f $PIDFILE; exit 1' TERM INT
28 if [[ -r $PIDFILE ]]; then
29 # PIDFILE exists, so I guess there's already an instance running
30 # let's kill it and run again
31 kill -s 15 $
(cat $PIDFILE) > /dev
/null
2>&1
32 # should already be deleted by trap, but just to be sure
40 echo "Parameters are:"
41 echo " -h : This help text"
42 echo " -s <directory> : specify directory where to store all notes."
43 echo " -e <editor> : specify EDITOR for this session only."
44 echo " -l : List existing notes"
45 echo " -a : Add new note"
46 echo " -m <note> : Modify note"
47 echo " -d <note> : Modify date for note"
48 echo " -r <note> : Remove note"
49 echo " -v : Print version"
56 FILEDATE
=$
(date -d @
$NOW +%d
/%m
/%Y_
%T
)
57 LASTID
=$
($JQ '.notes[-1].id' $DB)
58 [ null
== $LASTID ] && LASTID
=0
59 NOTEID
=$
(( $LASTID + 1 ))
60 touch ${NOTESDIR}/${NOW}
61 $JQ --arg i
"$NOTEID" --arg t
"$NOTETITLE" --arg f
"$NOW" '.notes += [{"id": $i, "title": $t, "file": $f}]' "$DB" > $TMPDB
63 NEWNOTE
=$
(${TERMINAL} --class notes --title notes -e ${EDITOR} ${NOTESDIR}/${NOW})
64 if [[ $NEWNOTE ]]; then
65 echo "New note saved!"
69 function listnotes
() {
74 echo "edit note \"${1}\""
78 echo "edit date for note \"${1}\""
87 cat << "__EOL__" > $DB
94 # check for notes dir existance and create it in case it doesn't exists
95 if [[ ! -d $NOTESDIR ]]; then
96 # we don't have a directory. FIRST RUN?
100 # Command line parameter processing:
101 while getopts ":a:hlvm:s:n:e:r:d:" Option
123 s
) NOTESDIR
=${OPTARG}
125 v
) echo $BASENAME v
${VERSION}
127 * ) echo "You passed an illegal switch to the program!"
128 echo "Run '$0 -h' for more help."
134 # End of option parsing.
135 shift $
(($OPTIND - 1))
136 # $1 now references the first non option item supplied on the command line
138 # ---------------------------------------------------------------------------