Sweeping refinements and formatting changes

This commit is contained in:
Jon-William Lewis
2016-02-15 11:24:57 -06:00
parent 86fb0d2019
commit 7085a46ef3
16 changed files with 133 additions and 137 deletions

View File

@@ -4,29 +4,46 @@ function edit(){
# Verify an editor was specified
if [ -z "$EDITOR" ]; then
>&2 echo "Error no editor specified in environment."
>&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\
"No editor specified in environment."
exit
# Verify the note exists
elif [ ! -r "$NOTE" ]; then
echo "ERROR: Note cannot be opened for editing."
>&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\
"Note cannot be opened for editing."
exit 40;
fi
# When encryption is enabled, decrypt $NOTE to a temp file
# If encryption is enabled, decrypt $NOTE to a temp file, otherwise
# operate on the note directly.
if [ "$ENCRYPTION" == "TRUE" ]; then
cp "$NOTE" "$NOTE".bk #Insurance
if [ ! -d "$TMP_DIR" ]; then mkdir "$TMP_DIR"; fi
TMP_NOTE="$TMP_DIR/$SESSION_ID"
decrypt > "$TMP_NOTE"
else TMP_NOTE="$NOTE"; fi
else
TMP_NOTE="$NOTE";
fi
# Write an ammendment header
if [ -z "$CREATE" ]; then
printf "\n %s\n" "edit - $(date)" >> "$TMP_NOTE"
printf "\n %s\n" "===================================" >> "$TMP_NOTE"
fi
if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TMP_NOTE"; fi
# Call the editor
printf " - %s\n" "editing ${NOTE%.*}"
"$EDITOR" "$TMP_NOTE"
# If the file was previously decrypted, encrypt it back
if [ "$ENCRYPTION" == "TRUE" ]; then
rm "$NOTE"
encrypt;
if [ -r "$NOTE" ]; then rm "$NOTE".bk; fi
if [ ! -r "$NOTE" ]; then
>&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "error: note was not saved."
cp "$NOTE.bk" "$NOTE"
else
rm "$NOTE.bk";
fi
fi
}