8 EDITOR
=${EDITOR:-/usr/bin/vim}
9 TERMINAL
=${TERMINAL:-/usr/bin/alacritty}
12 BASEDIR
=${BASEDIR:-~/.local/share/bash-notes}
13 RCFILE
=${RCFILE:-~/.bash-notes.rc}
15 NOTESDIR
=${BASEDIR}/notes
18 BASENAME
=$
( basename $0 )
21 echo "jq not found in your PATH"
22 echo "install jq to continue"
26 # IMPORT USER DEFINED OPTIONS IF ANY
27 if [[ -f $RCFILE ]]; then
31 # We prevent the program from running more than one instance:
32 PIDFILE
=/var
/tmp
/$
(basename $0 .sh
).pid
34 # Make sure the PID file is removed when we kill the process
35 trap 'rm -f $PIDFILE; exit 1' TERM INT
37 if [[ -r $PIDFILE ]]; then
38 # PIDFILE exists, so I guess there's already an instance running
39 # let's kill it and run again
40 kill -s 15 $
(cat $PIDFILE) > /dev
/null
2>&1
41 # should already be deleted by trap, but just to be sure
49 echo "Parameters are:"
50 echo " -h : This help text"
51 echo " -s <directory> : specify directory where to store all notes."
52 echo " -e <editor> : specify EDITOR for this session only."
53 echo " -l : List existing notes"
54 echo " -a : Add new note"
55 echo " -m <note> : Modify note"
56 echo " -d <note> : Modify date for note"
57 echo " -r <note> : Remove note"
58 echo " -v : Print version"
63 echo "adding new note - \"$NOTETITLE\""
65 LASTID
=$
($JQ '.notes[-1].id | tonumber' $DB)
66 [ null
== $LASTID ] && LASTID
=0
67 NOTEID
=$
(( $LASTID + 1 ))
68 touch ${NOTESDIR}/${NOW}
69 $JQ --arg i
"$NOTEID" --arg t
"$NOTETITLE" --arg f
"$NOW" '.notes += [{"id": $i, "title": $t, "file": $f}]' "$DB" > $TMPDB
71 $
(${TERMINAL} --class notes --title notes -e ${EDITOR} ${NOTESDIR}/${NOW})
74 function listnotes
() {
79 echo "edit note \"${1}\""
83 echo "edit date for note \"${1}\""
84 # FILEDATE=$(date -d @$NOW +%d/%m/%Y_%T)
90 echo "removing note $NOTE"
93 # we should expand on this function to add a sample note and explain a little bit
94 # how the program works.
96 [ -f $RCFILE ] && RC
=$RCFILE || RC
="none"
99 echo "${BASENAME} configuration:
101 base directory: ${BASEDIR}/
102 notes archive: ${NOTESDIR}/
103 notes database: ${DB}
105 text editor: ${EDITOR}
106 terminal: ${TERMINAL}
110 read -r -p "Do you wish to continue? (y/N) " ANSWER
114 cat << "__EOL__" > ${DB}
121 echo "No changes made. Exiting"
125 echo "No changes made. Exiting"
131 # check for notes dir existance and create it in case it doesn't exists
132 if [[ ! -d $NOTESDIR ]]; then
133 # we don't have a directory. FIRST RUN?
137 # NOTE: This requires GNU getopt. On Mac OS X and FreeBSD, you have to install this
138 # separately; see below.
139 GOPT
=`getopt -o hvla:m:d:r: --long help,version,list,add:,modify:,date:,remove:,editor:,storage: \
140 -n 'bash-notes' -- "$@"`
142 if [ $?
!= 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
144 # Note the quotes around `$GOPT': they are essential!
154 echo $BASENAME v
${VERSION}
184 echo "changed EDITOR TO \"$EDITOR\""
189 echo "changed BASEDIR TO \"$BASEDIR\""