Formatting changes

This commit is contained in:
Jon-William Lewis
2016-02-10 23:34:49 -06:00
parent be3871f859
commit 856b14242c
14 changed files with 267 additions and 282 deletions

View File

@@ -1,22 +1,31 @@
function create(){
if [ -e "$NOTE" ]; then
printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n"
exit
else
mkdir -p "$NOTE_DIR"
fi
# Depends : p_header
# Requires: $NOTE, $NOTE_DIR, $NOTEBOOK, $SECTION, $NAME
# Optional: $ENCRYPTION, $SESSION_ID, $TMP_DIR encrypt
# Given a valid setup, create writes the standard note header as specified
# by p_header, to $NOTE.
if [ -z "$ENCRYPTION" ]; then
echo "TITLE: $NAME" > "$NOTE"
echo "DATE: $(date)" >> "$NOTE"
elif [ "$ENCRYPTION" == "TRUE" ]; then
# Refuse to overwrite a note
if [ -e "$NOTE" ]; then
printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n"
exit 200
# If the notebook doesn't exist, create it.
elif [ ! -d "$NOTE_DIR" ]; then
mkdir -p "$NOTE_DIR"
fi
# Write the standard note header
if [ "$ENCRYPTION" == "TRUE" ]; then
TMP_NOTE="$TMP_DIR"/"$SESSION_ID"
p_header > "$TMP_NOTE"
encrypt
fi
if [ -e "$NOTE" ]; then
else
p_header > "$NOTE"
fi
# Make sure the note exists, and inform the user.
if [ -e "$NOTE" ]; then
echo "Created note: $NOTEBOOK/$SECTION/$NAME."
fi
else
printf "%s\n" "Something went wrong."
fi
}

View File

@@ -1,14 +1,10 @@
function delete(){
if [ "$DELETE" == "TRUE" ]; then
if [ -e "$NOTE" ]; then
rm "$NOTE"
echo ""
echo "Deleted note: $NOTEBOOK/$SECTION/$NAME."
exit
else
echo ""
echo "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist."
exit
fi
fi
#Requires: $NOTE, $NOTEBOOK, $SECTION, $NAME
# Given a valid $NOTE, delete removes $NOTE from sns.
if [ -e "$NOTE" ]; then
rm "$NOTE"
printf "\n%s\n" "Deleted note: $NOTEBOOK/$SECTION/$NAME."
else
printf "\n%s\n" "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist."
fi
}

View File

@@ -1,15 +1,20 @@
function edit(){
# Requires: $EDITOR, $NOTE
# Optional: $ENCRYPTION, $TMP_DIR, $SESSION_ID, decrypt, encrypt
# Verify an editor was specified
if [ -z "$EDITOR" ]; then
>&2 echo "Error no editor specified in environment."
exit
# Verify the note exists
elif [ ! -r "$NOTE" ]; then
echo "ERROR: Note cannot be opened for editing."
exit 40;
fi
# When encryption is enabled, decrypt $NOTE to a temp file
if [ "$ENCRYPTION" == "TRUE" ]; then
cp "$NOTE" "$NOTE".bk
if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi
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

View File

@@ -1,7 +1,6 @@
#!/bin/sh
# verify_store.sh
# sns
#
# Created by Jon-William Lewis on 1/31/16.
#
function verify_store {
STORE_DIRS=("$ROOT_DIR" "$NOTES_DIR" "$TMP_DIR")
for DIR in ${STORE_DIRS[]}; do
mkdir -p "$DIR"
done
}