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