c42e63dff831605c50b39ffdf0dcffb421c5fec5
[bash-notes.git] / SOURCE / CORE / core-edit.sh
1 function editnote() {
2 NOTE=$1
3 # shellcheck disable=SC2155
4 local OK=$(check_noteID "$NOTE")
5 if [ ! "$OK" ]; then
6 echo "invalid note \"$NOTE\""
7 echo "Use the note ID that you can fetch after listing your notes"
8 exit 1
9 fi
10
11 # shellcheck disable=SC2016,SC2086
12 TITLE=$($JQ --arg i $OK '.notes[] | select(.id == $i) | .title' $DB)
13 # shellcheck disable=SC2016,SC2086
14 FILE=$($JQ -r --arg i $OK '.notes[] | select(.id == $i) | .file' $DB)
15 if [ "$TITLE" ]; then
16 echo "editing note $TITLE"
17 # shellcheck disable=SC2086,SC2091
18 $(${TERMINAL} ${TERM_OPTS} ${EDITOR} ${NOTESDIR}/${FILE})
19 else
20 echo "note not found"
21 exit 1
22 fi
23 }