Separated script into multiple files for easier management. Added Makefile
[bash-notes.git] / SOURCE / CORE / core-add.sh
1 function addnote() {
2 # remove eventually existing temp DB file
3 if [[ -f $TMPDB ]]; then
4 rm $TMPDB
5 fi
6
7 NOTETITLE="$1"
8 echo "adding new note - \"$NOTETITLE\""
9 # shellcheck disable=SC2086
10 LASTID=$($JQ '.notes[-1].id // 0 | tonumber' $DB)
11 # [ "" == $LASTID ] && LASTID=0
12 NOTEID=$(( LASTID + 1 ))
13 # shellcheck disable=SC2086
14 touch ${NOTESDIR}/${NOW}
15 # shellcheck disable=SC2016
16 $JQ --arg i "$NOTEID" --arg t "$NOTETITLE" --arg f "$NOW" '.notes += [{"id": $i, "title": $t, "file": $f}]' "$DB" > $TMPDB
17 # shellcheck disable=SC2086
18 mv $TMPDB $DB
19 # example for alacritty:
20 # alacritty --class notes --title notes -e /usr/bin/vim ...
21 # shellcheck disable=SC2086,SC2091
22 $(${TERMINAL} ${TERM_OPTS} ${EDITOR} ${NOTESDIR}/${NOW})
23 }