From b02b97c7078a899220ab78348ef801fb5339bd54 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Wed, 31 Jul 2019 01:39:33 -0400 Subject: [PATCH] Delete prompt enhanced to handle encrypted notes. Decrypt note option added. --- notestorm | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/notestorm b/notestorm index 4e70f42..b15e729 100755 --- a/notestorm +++ b/notestorm @@ -86,18 +86,24 @@ menulist() { } more_menu() { - # Options for the submenu go in the options array. - declare -a options=( - "encrypt" "$(gettext "Encrypt")" + # Options for the submenu go in the options array, see options+= + declare -a options + if [[ "${1##*.}" == "gpg" ]]; then + options+=("decrypt" "$(gettext "Decrypt")") + else + options=("encrypt" "$(gettext "Encrypt")") + fi + options+=( "delete" "$(gettext "Delete")") local action="$(dialog --backtitle "$(gettext "Use the up and down arrow keys to find the option you want, then press enter to select it.")" \ --no-tags \ --menu "$(gettext "Please select one")" \ 0 0 0 ${options[@]} --stdout)" case "$action" in + "decrypt") decrypt_note "$1";; "delete") delete_note "$1";; "encrypt") encrypt_note "$1";; - "") return;; + *) return;; esac } @@ -116,9 +122,23 @@ add_note() { fi } +decrypt_note() { + #returns the note to its unencrypted state. + if gpg -o "${1%.gpg}" -d "$1" ; then + rm -f "$1" + infobox "$(gettext "Note decrypted and saved as: ") \"${1%.gpg}\"" + return + fi + infobox "$(gettext "Decryption failed.")" +} + delete_note() { local text="$(head -1 "$1")" - local answer="$(yesno "$(gettext "Really delete note starting with text") \"$text\"?")" + if [[ "${1##*.}" == "gpg" ]]; then + local answer="$(yesno "$(gettext "Really delete note named:") \"${1##*/}\"?")" + else + local answer="$(yesno "$(gettext "Really delete note starting with text:") \"$text\"?")" + fi if [ "$answer" == "Yes" ]; then rm -f "$1" infobox "$(gettext "Note deleted.")"