From 037fd9c2fa81e25ac37a236287ea7e1bcdc36e35 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 01:18:44 -0600 Subject: [PATCH] Made changes to create and delete functions reflecting recent design decisions --- src/includes/create.sns.sh | 30 +++++++++++++++++------------- src/includes/delete.sns.sh | 11 ++++++----- src/main/stage3.sns.sh | 17 ++++------------- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/includes/create.sns.sh b/src/includes/create.sns.sh index a0549ed..228bad0 100644 --- a/src/includes/create.sns.sh +++ b/src/includes/create.sns.sh @@ -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 } diff --git a/src/includes/delete.sns.sh b/src/includes/delete.sns.sh index 696d9d1..a8aefed 100644 --- a/src/includes/delete.sns.sh +++ b/src/includes/delete.sns.sh @@ -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 } diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh index 3f813f0..ca3c262 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -9,29 +9,20 @@ # All options not requiring a note to be specified have been dealt # with; if one isn't specified, exit on ERR_NO_NOTE. if [ -z "$NOTE" ]; then - printf " $RED_COLOR!$RESET_COLOR %s\n" "No note specified." - exit 30 -fi -# List is the only option requiring only a notebook. -# If list isn't the selected option and no note name was specified, throw code 30. -if [ "$LIST" == TRUE ]; then - list - exit 0 -elif [ -z "$NAME" ]; then - printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified" + printf " $RED_COLOR!$RESET_COLOR %s\n" "No note specified." exit 30 fi NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION" - if [ "$ENCRYPTION" == "TRUE" ]; then SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename - readonly NOTE="$NOTE_DIR/$NAME.$EXT.gpg" + readonly NOTE="$NOTE.$EXT.gpg" else - readonly NOTE="$NOTE_DIR/$NAME.$EXT" + readonly NOTE="$NOTE.$EXT" fi +if [ "$LIST" == "TRUE" ]; then list; exit 0; fi if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi if [ "$CREATE" == "TRUE" ]; then create; fi