Made changes to create and delete functions reflecting recent design decisions
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user