Sweeping refinements and formatting changes
This commit is contained in:
@@ -7,7 +7,7 @@ function create(){
|
||||
|
||||
# Refuse to overwrite a note
|
||||
if [ -e "$NOTE_DIR/$NOTE" ]; then
|
||||
printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\
|
||||
>&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\
|
||||
"Note already exists"\
|
||||
"Hint: use -e to edit the note."
|
||||
exit 200
|
||||
@@ -29,7 +29,7 @@ function create(){
|
||||
if [ -e "$NOTE_DIR/$NOTE" ]; then
|
||||
printf " - %s\n" "Created note: ${NOTE%.*}"
|
||||
else
|
||||
printf " $RED_COLOR!$RESET_COLOR%s\n"\
|
||||
>&2 printf " $RED_COLOR!$RESET_COLOR%s\n"\
|
||||
"Something went wrong, and the note was not created."
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ function delete(){
|
||||
rm "$NOTE_DIR/$NOTE"
|
||||
printf " - %s\n" "Deleted note: ${NOTE%.*}."
|
||||
else
|
||||
printf " $RED_COLOR!$RESET_COLOR %s\n" "Note ${NOTE%.*} does not exist."
|
||||
>&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "Note ${NOTE%.*} does not exist."
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ EOF
|
||||
|
||||
chmod 600 "$CONFIG_FILE"
|
||||
|
||||
printf "\n - %s\n" "Rewrote Default Configuration"
|
||||
printf " - %s\n" "Rewrote Default Configuration"
|
||||
|
||||
if [ "$WILL_INIT" == "TRUE" ]; then
|
||||
printf " - %s %s\n" "Environment initialized in" "$ROOT_DIR"
|
||||
printf " - %s\n" "Environment initialized in $ROOT_DIR"
|
||||
else
|
||||
printf " - %s\n" "Store already initialized."
|
||||
printf " - %s\n" "Store already initialized."
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
function encrypt(){
|
||||
# This function, given a recipient, $PUBKEY; a file to encrypt, $TMP_NOTE; and an
|
||||
# output file, "$NOTE", will encrypt $TMP_NOTE to $NOTE against $PUBKEY's private
|
||||
# output file, $NOTE, will encrypt $TMP_NOTE to $NOTE against $PUBKEY's private
|
||||
# GPG key.
|
||||
|
||||
gpg -r "$PUBKEY" -o "$NOTE" -e "$TMP_NOTE"
|
||||
@@ -8,8 +8,8 @@ function encrypt(){
|
||||
}
|
||||
|
||||
function decrypt(){
|
||||
# This function, given a recipient, $PUBKEY; a file to decrypt, $TMP_NOTE; and an
|
||||
# output file, "$NOTE", will decrpyt $TMP_NOTE to $NOTE against $PUBKEY's private
|
||||
# GPG key.
|
||||
# This function, given a file to decrypt, will attempt to decrypt the file
|
||||
# against the specified recipient's private key, and print the result to
|
||||
# stdout.
|
||||
gpg -d "$NOTE"
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
function list(){
|
||||
if [ -d "$NOTES_DIR"/"$NOTEBOOK" ]; then
|
||||
printf "+%s\n" "$NOTEBOOK"
|
||||
find "$NOTES_DIR"/"$NOTEBOOK" -type f | while read -r NOTE; do
|
||||
printf " -%s\n" "$(basename \"$NOTE\" | cut -d . -f 1 )"
|
||||
done
|
||||
fi
|
||||
# This function, given a folder, $NOTE, will list the contents of $NOTE.
|
||||
ls "$NOTE"
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
function pause {
|
||||
read -rp " Press [Enter] to continue."
|
||||
echo ""
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
function print(){
|
||||
if [ -r "$NOTE" ]; then
|
||||
if [ -z "$CREATE" ]; then
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||
decrypt
|
||||
else
|
||||
cat "$NOTE"
|
||||
fi
|
||||
else
|
||||
printf "\nERROR: Note cannot be found.\n"
|
||||
fi
|
||||
fi
|
||||
# Given an existing file, $NOTE, print prints the contents of $NOTE to stdout.
|
||||
|
||||
if [ -r "$NOTE" ]; then
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then decrypt #to stdout
|
||||
else cat "$NOTE" fi
|
||||
else
|
||||
>&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\
|
||||
"Note cannot be found."
|
||||
exit 205 #ERR_NOTE_NO_READ
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
function verify_store {
|
||||
|
||||
ETC_DIR=$(dirname "$CONFIG_FILE")
|
||||
|
||||
STORE_DIRS=("$ROOT_DIR" "$NOTES_DIR" "$TMP_DIR" "$ETC_DIR")
|
||||
for DIR in "${STORE_DIRS[@]}"; do
|
||||
mkdir -p "$DIR"
|
||||
if [ ! -d "$DIR" ]; then
|
||||
mkdir -p "$DIR"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user