diff options
| author | danix <danix@danix.xyz> | 2023-03-29 11:19:55 +0200 |
|---|---|---|
| committer | danix <danix@danix.xyz> | 2023-03-29 11:19:55 +0200 |
| commit | fb71118327216a21f6732161dc3721496a16370d (patch) | |
| tree | 96eddf131b1d802be87addd7faece45141e98a9a /SOURCE/CORE/core-remove.sh | |
| parent | ad818a9d1e26462bfb0c36d585dcbc33b38b37ca (diff) | |
| download | bash-notes-fb71118327216a21f6732161dc3721496a16370d.tar.gz bash-notes-fb71118327216a21f6732161dc3721496a16370d.zip | |
Separated script into multiple files for easier management. Added Makefile
Diffstat (limited to 'SOURCE/CORE/core-remove.sh')
| -rw-r--r-- | SOURCE/CORE/core-remove.sh | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/SOURCE/CORE/core-remove.sh b/SOURCE/CORE/core-remove.sh new file mode 100644 index 0000000..5776bbc --- /dev/null +++ b/SOURCE/CORE/core-remove.sh @@ -0,0 +1,51 @@ +function rmnote() { + # remove eventually existing temp DB file + if [[ -f $TMPDB ]]; then + rm $TMPDB + fi + + NOTE=$1 + if [ "all" == "$NOTE" ]; then + echo "You're going to delete all notes." + read -r -p "Do you wish to continue? (y/N) " ANSWER + case $ANSWER in + y|Y ) + # shellcheck disable=SC2086 + $JQ 'del(.notes[])' $DB > $TMPDB + # shellcheck disable=SC2086 + mv $TMPDB $DB + # shellcheck disable=SC2086 + rm $NOTESDIR/* + echo "Deleted all notes" + ;; + * ) + echo "Aborting, no notes were deleted." + exit 1 + ;; + esac + else + # shellcheck disable=SC2155 + local OK=$(check_noteID "$NOTE") + if [ ! "$OK" ]; then + echo "invalid note \"$NOTE\"" + echo "Use the note ID that you can fetch after listing your notes" + exit 1 + fi + + # shellcheck disable=SC2016,SC2086 + TITLE=$($JQ --arg i $OK '.notes[] | select(.id == $i) | .title' $DB) + # shellcheck disable=SC2016,SC2086 + FILE=$($JQ -r --arg i $OK '.notes[] | select(.id == $i) | .file' $DB) + if [ "$TITLE" ]; then + # shellcheck disable=SC2016,SC2086 + $JQ -r --arg i $OK 'del(.notes[] | select(.id == $i))' $DB > $TMPDB + # shellcheck disable=SC2086 + mv $TMPDB $DB + rm $NOTESDIR/$FILE + echo "Deleted note $TITLE" + else + echo "note not found" + exit 1 + fi + fi +} |
