Revert "Formatting changes"
This reverts commit f156e9bbe5.
Restoring this commit pending a rewrite.
This commit is contained in:
@@ -20,9 +20,9 @@ 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"
|
||||
|
||||
# Refuse to overwrite a note
|
||||
if [ -e "$FILE" ]; then
|
||||
if [ -e "$NOTES_DIR/$NOTE" ]; then
|
||||
>&2 printf "$RED_COLOR!$RESET_COLOR %s\n\t%s\n"\
|
||||
"Note already exists"\
|
||||
"Hint: use -e to edit the note."
|
||||
@@ -31,9 +31,7 @@ function create(){
|
||||
|
||||
# If the note's notebook/section does not exist,
|
||||
# create the appropriate folders.
|
||||
if [ ! -d "$(dirname "$FILE")" ]; then
|
||||
mkdir -p "$(dirname "$FILE")"
|
||||
fi
|
||||
mkdir -p "$NOTES_DIR"/"$(dirname "$NOTE")"
|
||||
|
||||
# Write the standard note header
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||
@@ -41,10 +39,10 @@ function create(){
|
||||
p_header > "$TMP_NOTE"
|
||||
encrypt
|
||||
else
|
||||
p_header > "$FILE"
|
||||
p_header > "$NOTES_DIR/$NOTE"
|
||||
fi
|
||||
# Make sure the note exists, and inform the user of the result.
|
||||
if [ -e "$FILE" ]; then
|
||||
if [ -e "$NOTES_DIR/$NOTE" ]; then
|
||||
printf "%s\n" "- Created note: ${NOTE%.*}"
|
||||
else
|
||||
>&2 printf "$RED_COLOR!$RESET_COLOR %s\n"\
|
||||
@@ -54,14 +52,13 @@ 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 "$FILE" ]; then
|
||||
if [ -e "$NOTES_DIR/$NOTE" ]; then
|
||||
printf "$RED_COLOR!!$RESET_COLOR %s%s" "Delete " "${NOTE%.*}"
|
||||
read -rp " (y/N) " YN
|
||||
read -p " (y/N) " YN
|
||||
case "$YN" in
|
||||
Y|y)
|
||||
rm "$FILE"
|
||||
rm "$NOTES_DIR/$NOTE"
|
||||
printf "%s\n" "- Deleted note: ${NOTE%.*}."
|
||||
;;
|
||||
*)
|
||||
@@ -69,12 +66,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
|
||||
@@ -82,8 +79,6 @@ 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
|
||||
@@ -91,7 +86,7 @@ if [ -z "$EDITOR" ]; then
|
||||
"No editor specified in environment."
|
||||
exit
|
||||
# Verify the note exists
|
||||
elif [ ! -r "$FILE" ]; then
|
||||
elif [ ! -r "$NOTES_DIR/$NOTE" ]; then
|
||||
>&2 printf "$RED_COLOR!$RESET_COLOR %s\n"\
|
||||
"Note cannot be opened for editing."
|
||||
exit 40;
|
||||
@@ -100,15 +95,15 @@ fi
|
||||
# If encryption is enabled, decrypt $NOTE to a temp file, otherwise
|
||||
# operate on the note directly.
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||
cp "$FILE" "$FILE.bk" #Insurance
|
||||
cp "$NOTES_DIR/$NOTE" "$NOTES_DIR/$NOTE.bk" #Insurance
|
||||
TMP_NOTE="$TMP_DIR/$SESSION_ID"
|
||||
decrypt > "$TMP_NOTE"
|
||||
else
|
||||
TMP_NOTE="$FILE";
|
||||
TMP_NOTE="$NOTES_DIR/$NOTE";
|
||||
fi
|
||||
|
||||
# Write an ammendment header
|
||||
if [ -z "$NO_HEADER" ]; then
|
||||
if [ -z "$CREATE" ]; then
|
||||
printf "\n%s\n" "edit - $(date "$DATE_FMT")" >> "$TMP_NOTE"
|
||||
printf "%s\n" "===================================" >> "$TMP_NOTE"
|
||||
fi
|
||||
@@ -120,21 +115,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 "$FILE"
|
||||
rm "$NOTES_DIR/$NOTE"
|
||||
encrypt;
|
||||
rm "$TMP_NOTE"
|
||||
if [ ! -r "$FILE" ]; then
|
||||
if [ ! -r "$NOTES_DIR/$NOTE" ]; then
|
||||
>&2 printf "$RED_COLOR!$RESET_COLOR %s\n" "error: note was not saved."
|
||||
cp "$FILE.bk" "$FILE"
|
||||
cp "$NOTES_DIR/$NOTE.bk" "$NOTES_DIR/$NOTE"
|
||||
else
|
||||
rm "$FILE.bk";
|
||||
rm "$NOTES_DIR/$NOTE.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 "$FILE"
|
||||
verctl "$VCTL" add ""$NOTES_DIR"/$NOTE"
|
||||
verctl "$VCTL" commit -m "Added/Changed $NOTE" > /dev/null
|
||||
fi
|
||||
}
|
||||
@@ -157,18 +152,10 @@ 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 [ ! "$NOTEBOOK" ]; then NOTEBOOK="."; fi
|
||||
cd "$NOTES_DIR" 2>/dev/null || exit 0
|
||||
NOTES=$(find "$NOTEBOOK" -type f -name "*$EXT" 2>/dev/null)
|
||||
if [ "${NOTES[@]}" ]; then
|
||||
for file in "${NOTES[@]}"; do
|
||||
printf "%s\n" "${file%.*}"
|
||||
done
|
||||
else
|
||||
echo "No notes found."
|
||||
fi
|
||||
cd "$(dirname "$NOTES_DIR/$NOTE")"
|
||||
find . -type f -name "*$EXT" | while read file; do
|
||||
printf "%s\n" "$file"
|
||||
done
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user