Still heavily broken; moving computers again

This commit is contained in:
Jon-William Lewis
2016-08-27 15:08:15 -05:00
parent 704980fa2b
commit 4966351673
6 changed files with 634 additions and 37 deletions

View File

@@ -20,9 +20,10 @@ function create(){
# Optional: $ENCRYPTION, $SESSION_ID, $TMP_DIR encrypt
# Given a valid setup, create writes the standard note header as specified
# by p_header, to $NOTE.
declare -r FILE="$NOTES_DIR/$NOTE.$EXT"
echo "$FILE"
# Refuse to overwrite a note
if [ -e "$NOTES_DIR/$NOTE" ]; then
if [ -e "$FILE" ]; then
>&2 printf "$RED_COLOR!$RESET_COLOR %s\n\t%s\n"\
"Note already exists"\
"Hint: use -e to edit the note."
@@ -31,7 +32,7 @@ function create(){
# If the note's notebook/section does not exist,
# create the appropriate folders.
mkdir -p "$NOTES_DIR"/"$(dirname "$NOTE")"
mkdir -p "$NOTES_DIR"/"$(dirname "$FILE")"
# Write the standard note header
if [ "$ENCRYPTION" == "TRUE" ]; then
@@ -39,10 +40,10 @@ function create(){
p_header > "$TMP_NOTE"
encrypt
else
p_header > "$NOTES_DIR/$NOTE"
p_header > "$FILE"
fi
# Make sure the note exists, and inform the user of the result.
if [ -e "$NOTES_DIR/$NOTE" ]; then
if [ -e "$FILE" ]; then
printf "%s\n" "- Created note: ${NOTE%.*}"
else
>&2 printf "$RED_COLOR!$RESET_COLOR %s\n"\
@@ -52,13 +53,14 @@ function create(){
function delete(){
# Requires: $NOTE, $NOTE_DIR
# Given a valid $NOTE, delete removes $NOTE from sns.
declare -r FILE="$NOTES_DIR/$NOTE.$EXT"
if [ -e "$NOTES_DIR/$NOTE" ]; then
if [ -e "$FILE" ]; then
printf "$RED_COLOR!!$RESET_COLOR %s%s" "Delete " "${NOTE%.*}"
read -p " (y/N) " YN
case "$YN" in
Y|y)
rm "$NOTES_DIR/$NOTE"
rm "$FILE"
printf "%s\n" "- Deleted note: ${NOTE%.*}."
;;
*)
@@ -66,12 +68,12 @@ function delete(){
;;
esac
#Cleanup empty notebooks/sections]
find "$NOTES_DIR" -mindepth 1 -type d | tac |\
while read -r DIR ; do
if [ ! "$(ls -A "$DIR")" ]; then
rmdir "$DIR"
fi
done
#find "$NOTES_DIR" -mindepth 1 -type d | tac |\
# while read -r DIR ; do
# if [ ! "$(ls -A "$DIR")" ]; then
# rmdir "$DIR"
# fi
#done
else
>&2 printf "$RED_COLOR!$RESET_COLOR %s\n" "Note ${NOTE%.*} does not exist."
fi
@@ -79,6 +81,8 @@ function delete(){
function edit(){
# Requires: $EDITOR, $NOTE
# Optional: $ENCRYPTION, $TMP_DIR, $SESSION_ID, decrypt, encrypt
# Set filename
declare -r FILE="$NOTES_DIR/$NOTE.$EXT"
# Verify an editor was specified
if [ -z "$EDITOR" ]; then
@@ -86,7 +90,7 @@ if [ -z "$EDITOR" ]; then
"No editor specified in environment."
exit
# Verify the note exists
elif [ ! -r "$NOTES_DIR/$NOTE" ]; then
elif [ ! -r "$FILE" ]; then
>&2 printf "$RED_COLOR!$RESET_COLOR %s\n"\
"Note cannot be opened for editing."
exit 40;
@@ -95,11 +99,14 @@ fi
# If encryption is enabled, decrypt $NOTE to a temp file, otherwise
# operate on the note directly.
if [ "$ENCRYPTION" == "TRUE" ]; then
cp "$NOTES_DIR/$NOTE" "$NOTES_DIR/$NOTE.bk" #Insurance
cp "$FILE" "$FILE.bk" #Insurance
TMP_NOTE="$TMP_DIR/$SESSION_ID"
echo "$TMP_NOTE"
decrypt > "$TMP_NOTE"
else
TMP_NOTE="$NOTES_DIR/$NOTE";
TMP_NOTE="$FILE";
echo "$TMP_NOTE"
fi
# Write an ammendment header
@@ -115,21 +122,21 @@ printf "%s\n" "- editing ${NOTE%.*}"
# If the file was previously decrypted, encrypt it back
if [ "$ENCRYPTION" == "TRUE" ]; then
printf "%s\n" "- encrypting ${NOTE%.*}"
rm "$NOTES_DIR/$NOTE"
rm "$FILE"
encrypt;
rm "$TMP_NOTE"
if [ ! -r "$NOTES_DIR/$NOTE" ]; then
if [ ! -r "$FILE" ]; then
>&2 printf "$RED_COLOR!$RESET_COLOR %s\n" "error: note was not saved."
cp "$NOTES_DIR/$NOTE.bk" "$NOTES_DIR/$NOTE"
cp "$FILE.bk" "$FILE"
else
rm "$NOTES_DIR/$NOTE.bk";
rm "$FILE.bk";
fi
fi
# If $VCTL is defined, add the edited note to the repo.
if [ "$VCTL" ]; then
>&2 printf "%s %s %s\n" "- adding to" "$VCTL" "repo".
verctl "$VCTL" add ""$NOTES_DIR"/$NOTE"
verctl "$VCTL" add "$FILE"
verctl "$VCTL" commit -m "Added/Changed $NOTE" > /dev/null
fi
}
@@ -153,11 +160,11 @@ function help {
function list(){
# This function, given a folder, $NOTE, will list the contents of $NOTE.
# If not given a folder, it will list all notes in the store.
if [ -z "$NOTEBOOK" ]; then NOTEBOOK="."; fi
cd "$(dirname "$NOTES_DIR/$NOTEBOOK")"
find . -type f -name "*$EXT" | while read file; do
printf "%s\n" "$file"
if [ ! "$NOTEBOOK" ]; then NOTEBOOK="."; fi
cd "$NOTES_DIR" 2>/dev/null || exit 0
find "$NOTEBOOK" -type f -name "*$EXT" 2>/dev/null || exit 0 | while read file; do
printf "%s\n" "${file%.*}"
done