Made changes to create and delete functions reflecting recent design decisions

This commit is contained in:
Jon-William Lewis
2016-02-15 01:18:44 -06:00
parent faab86dff2
commit 037fd9c2fa
3 changed files with 27 additions and 31 deletions

View File

@@ -1,18 +1,21 @@
function create(){
# Depends : p_header
# Requires: $NOTE, $NOTE_DIR, $NOTEBOOK, $SECTION, $NAME
# Requires: $NOTE, $NOTE_DIR,
# Optional: $ENCRYPTION, $SESSION_ID, $TMP_DIR encrypt
# Given a valid setup, create writes the standard note header as specified
# by p_header, to $NOTE.
# 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
if [ -e "$NOTE_DIR/$NOTE" ]; then
printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\
"Note already exists"\
"Hint: use -e to edit the note."
exit 200
fi
# If the note's notebook/section does not exist,
# create the appropriate folders.
mkdir -p "$NOTE_DIR"/$(dirname "$NOTE")
# Write the standard note header
if [ "$ENCRYPTION" == "TRUE" ]; then
@@ -20,12 +23,13 @@ function create(){
p_header > "$TMP_NOTE"
encrypt
else
p_header > "$NOTE"
p_header > "$NOTE_DIR/$NOTE"
fi
# Make sure the note exists, and inform the user.
if [ -e "$NOTE" ]; then
echo "Created note: $NOTEBOOK/$SECTION/$NAME."
# Make sure the note exists, and inform the user of the result.
if [ -e "$NOTE_DIR/$NOTE" ]; then
printf " - %s\n" "Created note: ${NOTE%.*}"
else
printf "%s\n" "Something went wrong."
printf " $RED_COLOR!$RESET_COLOR%s\n"\
"Something went wrong, and the note was not created."
fi
}

View File

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