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
This commit is contained in:
Jon-William Lewis
2015-09-19 18:40:43 -05:00
committed by Jon-William Lewis
parent 337a1bf3a3
commit 35094aed04
5 changed files with 28 additions and 78 deletions

51
sns.sh
View File

@@ -71,34 +71,8 @@ function decrypt(){
TARGET="$ROOTDIR"/tmp/"$RANDOM" TARGET="$ROOTDIR"/tmp/"$RANDOM"
openssl enc -d -aes-256-cbc -in "$NOTE" -pass pass:"$ENC_KEY" > "$TARGET" 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(){ 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" printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n"
exit exit
else else
@@ -113,22 +87,22 @@ function create(){
p_header | openssl enc -aes-256-cbc -salt -out "$NOTE"\ p_header | openssl enc -aes-256-cbc -salt -out "$NOTE"\
-pass pass:"$ENC_KEY" -pass pass:"$ENC_KEY"
fi fi
echo "$NOTE"
if [ -e "$NOTE" ]; then
echo "Created note: $NOTEBOOK/$SECTION/$NAME."
fi
} }
function delete(){ function delete(){
if [ "$DELETE" == "TRUE" ]; then if [ "$DELETE" == "TRUE" ]; then
if [ -e "$NOTE" ] || [ -e "${NOTE%.*}" ]; then if [ -e "$NOTE" ]; then
if [ "$ENCRYPTION" == "TRUE" ]; then
rm "${NOTE%.*}"
else
rm "$NOTE" rm "$NOTE"
fi
echo "" echo ""
echo "Deleted note: $NOTEBOOK/$SECTION$NAME." echo "Deleted note: $NOTEBOOK/$SECTION/$NAME."
exit exit
else else
echo "" echo ""
echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." echo "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist."
exit exit
fi fi
fi fi
@@ -221,8 +195,8 @@ fi
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
PROD_STR="Simple Note System (Encryption Enabled)" PROD_STR="Simple Note System (Encryption Enabled)"
EXT="$EXT" EXT="$EXT"
if [ ! -d ~/.sns/tmp ]; then if [ ! -d "$BASEDIR"/tmp ]; then
mkdir -p ~/.sns/tmp mkdir -p "$BASEDIR"/tmp
fi fi
fi fi
@@ -308,7 +282,8 @@ fi
NOTEDIR="$BASEDIR"/"$NOTEBOOK"/"$SECTION"/ NOTEDIR="$BASEDIR"/"$NOTEBOOK"/"$SECTION"/
NOTE="$NOTEDIR""$NAME"."$EXT" 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 [ "$PRINT" == "TRUE" ]; then print; exit 0; fi
if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi
if [ "$CREATE" == "TRUE" ]; then create; fi if [ "$CREATE" == "TRUE" ]; then create; fi
if [ "$EDIT" == "TRUE" ]; then edit; fi if [ "$EDIT" == "TRUE" ]; then edit; fi

View File

@@ -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(){ 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" printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n"
exit exit
else else
@@ -40,5 +14,9 @@ function create(){
p_header | openssl enc -aes-256-cbc -salt -out "$NOTE"\ p_header | openssl enc -aes-256-cbc -salt -out "$NOTE"\
-pass pass:"$ENC_KEY" -pass pass:"$ENC_KEY"
fi fi
echo "$NOTE"
if [ -e "$NOTE" ]; then
echo "Created note: $NOTEBOOK/$SECTION/$NAME."
fi
} }

View File

@@ -1,17 +1,13 @@
function delete(){ function delete(){
if [ "$DELETE" == "TRUE" ]; then if [ "$DELETE" == "TRUE" ]; then
if [ -e "$NOTE" ] || [ -e "${NOTE%.*}" ]; then if [ -e "$NOTE" ]; then
if [ "$ENCRYPTION" == "TRUE" ]; then
rm "${NOTE%.*}"
else
rm "$NOTE" rm "$NOTE"
fi
echo "" echo ""
echo "Deleted note: $NOTEBOOK/$SECTION$NAME." echo "Deleted note: $NOTEBOOK/$SECTION/$NAME."
exit exit
else else
echo "" echo ""
echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." echo "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist."
exit exit
fi fi
fi fi

View File

@@ -19,8 +19,8 @@ fi
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
PROD_STR="Simple Note System (Encryption Enabled)" PROD_STR="Simple Note System (Encryption Enabled)"
EXT="$EXT" EXT="$EXT"
if [ ! -d ~/.sns/tmp ]; then if [ ! -d "$BASEDIR"/tmp ]; then
mkdir -p ~/.sns/tmp mkdir -p "$BASEDIR"/tmp
fi fi
fi fi

View File

@@ -24,7 +24,8 @@ fi
NOTEDIR="$BASEDIR"/"$NOTEBOOK"/"$SECTION"/ NOTEDIR="$BASEDIR"/"$NOTEBOOK"/"$SECTION"/
NOTE="$NOTEDIR""$NAME"."$EXT" 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 [ "$PRINT" == "TRUE" ]; then print; exit 0; fi
if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi
if [ "$CREATE" == "TRUE" ]; then create; fi if [ "$CREATE" == "TRUE" ]; then create; fi
if [ "$EDIT" == "TRUE" ]; then edit; fi if [ "$EDIT" == "TRUE" ]; then edit; fi