From 35094aed04ac9cf91495b34ef1366835047f419c Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Sat, 19 Sep 2015 18:40:43 -0500 Subject: [PATCH] Fixed erroneous reference to former static ~/.sns BASEDIR Added hook to actually delete a note if requested Removed old, commented code Simplified create and delete logic by removing unnecessary checks that make no sense to me now Cleaned up output from create event --- sns.sh | 53 ++++++++++---------------------------- src/includes/create.sns.sh | 34 +++++------------------- src/includes/delete.sns.sh | 12 +++------ src/main/stage1.sns.sh | 4 +-- src/main/stage3.sns.sh | 3 ++- 5 files changed, 28 insertions(+), 78 deletions(-) diff --git a/sns.sh b/sns.sh index 2359cd7..4bc5972 100755 --- a/sns.sh +++ b/sns.sh @@ -71,34 +71,8 @@ function decrypt(){ TARGET="$ROOTDIR"/tmp/"$RANDOM" openssl enc -d -aes-256-cbc -in "$NOTE" -pass pass:"$ENC_KEY" > "$TARGET" } -#function create(){ -# -# #Check if note exists -# if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then -# echo "" -# echo "ERROR: Note already exists" -# echo "Hint: use -e to edit the note." -# echo "" -# exit -# else -# #Create any necessary folders -# mkdir -p $NOTEDIR -# -# #Fill in title -# echo "TITLE: $NAME" > $NOTE -# #Fill the second line with the date -# echo "DATE: $(date)" >> $NOTE -# -# if [ "$ENCRYPTION" == "TRUE" ]; then -# if [ "$EDIT" == "FALSE" ]; then -# echo " openssl enc -aes-256-cbc -salt -in $NOTE -out $NOTE.enc -pass pass:$ENC_KEY" -# fi -# fi -# fi -#} - function create(){ - if [ -e "$NOTE" ] || [ -e "${NOTE%.*}" ]; then + if [ -e "$NOTE" ]; then printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" exit else @@ -113,22 +87,22 @@ function create(){ p_header | openssl enc -aes-256-cbc -salt -out "$NOTE"\ -pass pass:"$ENC_KEY" fi - echo "$NOTE" + + if [ -e "$NOTE" ]; then + echo "Created note: $NOTEBOOK/$SECTION/$NAME." + fi + } function delete(){ if [ "$DELETE" == "TRUE" ]; then - if [ -e "$NOTE" ] || [ -e "${NOTE%.*}" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then - rm "${NOTE%.*}" - else - rm "$NOTE" - fi + if [ -e "$NOTE" ]; then + rm "$NOTE" echo "" - echo "Deleted note: $NOTEBOOK/$SECTION$NAME." + echo "Deleted note: $NOTEBOOK/$SECTION/$NAME." exit else echo "" - echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." + echo "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist." exit fi fi @@ -221,8 +195,8 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then PROD_STR="Simple Note System (Encryption Enabled)" EXT="$EXT" -if [ ! -d ~/.sns/tmp ]; then -mkdir -p ~/.sns/tmp +if [ ! -d "$BASEDIR"/tmp ]; then +mkdir -p "$BASEDIR"/tmp fi fi @@ -308,7 +282,8 @@ fi NOTEDIR="$BASEDIR"/"$NOTEBOOK"/"$SECTION"/ NOTE="$NOTEDIR""$NAME"."$EXT" -if [ "$ENCRYPTION" == "TRUE" ]; then NOTE=$NOTE.enc; fi +if [ "$ENCRYPTION" == "TRUE" ]; then NOTE="$NOTE".enc; fi if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi +if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi if [ "$CREATE" == "TRUE" ]; then create; fi if [ "$EDIT" == "TRUE" ]; then edit; fi \ No newline at end of file diff --git a/src/includes/create.sns.sh b/src/includes/create.sns.sh index 5559417..e4a9fbc 100644 --- a/src/includes/create.sns.sh +++ b/src/includes/create.sns.sh @@ -1,31 +1,5 @@ -#function create(){ -# -# #Check if note exists -# if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then -# echo "" -# echo "ERROR: Note already exists" -# echo "Hint: use -e to edit the note." -# echo "" -# exit -# else -# #Create any necessary folders -# mkdir -p $NOTEDIR -# -# #Fill in title -# echo "TITLE: $NAME" > $NOTE -# #Fill the second line with the date -# echo "DATE: $(date)" >> $NOTE -# -# if [ "$ENCRYPTION" == "TRUE" ]; then -# if [ "$EDIT" == "FALSE" ]; then -# echo " openssl enc -aes-256-cbc -salt -in $NOTE -out $NOTE.enc -pass pass:$ENC_KEY" -# fi -# fi -# fi -#} - function create(){ - if [ -e "$NOTE" ] || [ -e "${NOTE%.*}" ]; then + if [ -e "$NOTE" ]; then printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" exit else @@ -40,5 +14,9 @@ function create(){ p_header | openssl enc -aes-256-cbc -salt -out "$NOTE"\ -pass pass:"$ENC_KEY" fi - echo "$NOTE" + + if [ -e "$NOTE" ]; then + echo "Created note: $NOTEBOOK/$SECTION/$NAME." + fi + } diff --git a/src/includes/delete.sns.sh b/src/includes/delete.sns.sh index 2efdcd6..f0b47dc 100644 --- a/src/includes/delete.sns.sh +++ b/src/includes/delete.sns.sh @@ -1,17 +1,13 @@ function delete(){ if [ "$DELETE" == "TRUE" ]; then - if [ -e "$NOTE" ] || [ -e "${NOTE%.*}" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then - rm "${NOTE%.*}" - else - rm "$NOTE" - fi + if [ -e "$NOTE" ]; then + rm "$NOTE" echo "" - echo "Deleted note: $NOTEBOOK/$SECTION$NAME." + echo "Deleted note: $NOTEBOOK/$SECTION/$NAME." exit else echo "" - echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." + echo "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist." exit fi fi diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index 9a4b12d..45ea735 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -19,8 +19,8 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then PROD_STR="Simple Note System (Encryption Enabled)" EXT="$EXT" -if [ ! -d ~/.sns/tmp ]; then -mkdir -p ~/.sns/tmp +if [ ! -d "$BASEDIR"/tmp ]; then +mkdir -p "$BASEDIR"/tmp fi fi diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh index 1aa53e4..955713f 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -24,7 +24,8 @@ fi NOTEDIR="$BASEDIR"/"$NOTEBOOK"/"$SECTION"/ NOTE="$NOTEDIR""$NAME"."$EXT" -if [ "$ENCRYPTION" == "TRUE" ]; then NOTE=$NOTE.enc; fi +if [ "$ENCRYPTION" == "TRUE" ]; then NOTE="$NOTE".enc; fi if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi +if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi if [ "$CREATE" == "TRUE" ]; then create; fi if [ "$EDIT" == "TRUE" ]; then edit; fi \ No newline at end of file