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