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