From bfc7fd6de6450557a729410b42da5375261d7157 Mon Sep 17 00:00:00 2001 From: dmarakom6 Date: Sun, 25 Apr 2021 13:23:38 +0300 Subject: [PATCH] Fix input bug A newline input doesn't result in an error anymore. --- uninstall.sh | 20 ++++++----- util/delnote.sh | 25 +++++++++----- util/findmisplacednote.sh | 10 ++++-- util/findnote.sh | 18 ++++++---- util/l/l.sh | 33 ++++++++++-------- util/newnote.sh | 18 +++++----- util/noteinfo.sh | 22 ++++++++---- util/quicknote.sh | 70 ++++++++++++++++++++++----------------- util/readnote.sh | 42 +++++++++++++---------- util/renamenote.sh | 41 +++++++++++++++-------- 10 files changed, 186 insertions(+), 113 deletions(-) diff --git a/uninstall.sh b/uninstall.sh index 76f77b6..d44ab62 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -13,7 +13,8 @@ echo "2.Disable shellnotes and all its commands, but keep the files in your syst echo "3.Enable shellnotes." echo "" echo -n "[1,2,3]: " && read option -if [ $option = "1" ]; then + +case $option in 1 ) if [ -e ~/.shellnotes/.shellnotes.sh ]; then echo -n "Are you sure you want to delete Shellnotes?[Y/N]: " && read delete case $delete in y|Y|YES|Yes|yes ) @@ -82,9 +83,9 @@ if [ $option = "1" ]; then ./uninfailed cd $DIR fi +esac - -elif [ $option = "2" ]; then +case $option in 2 ) if grep 'return' <~/.shellnotes/.shellnotes.sh >/dev/null; then echo "Shellnotes is already disabled." cd ~/.shellnotes/util/exec @@ -94,7 +95,9 @@ elif [ $option = "2" ]; then sed -i '2 i\return 0 #Shellnotes is disabled by the user. Do not change this line.' ~/.shellnotes/.shellnotes.sh echo "Shellnotes is now disabled. To enable, run this script again and choose option (3)." fi -elif [ $option = "3" ]; then +esac + +case $option in 3 ) if grep 'return' <~/.shellnotes/.shellnotes.sh >/dev/null; then sed -i '2d' ~/.shellnotes/.shellnotes.sh echo "Shellnotes is now enabled. Please restart your terminal." @@ -104,9 +107,10 @@ elif [ $option = "3" ]; then ./enfailed cd $DIR fi -else - echo "This is not an option." -fi +esac - \ No newline at end of file +case $option in + (*[a-zA-Z]* | "" ) + echo "Invalid input." +esac diff --git a/util/delnote.sh b/util/delnote.sh index 374be2b..b6b7dcc 100644 --- a/util/delnote.sh +++ b/util/delnote.sh @@ -11,16 +11,24 @@ function delnote() { else delete=$1 fi + + if [ -z $delete ]; then + echo "Invalid input." + return 0 + + else if [[ $1 == "-all" ]]; then - cd $DEFAULT_PATH - rm -f * - clear - cd $DIR - str="All files deleted from $DEFAULT_PATH" - underlines=$(echo "$str" | tr -c '\010' '-') - echo "$str\n$underlines" + cd $DEFAULT_PATH + rm -f * + clear + cd $DIR + str="All files deleted from $DEFAULT_PATH" + underlines=$(echo "$str" | tr -c '\010' '-') + echo "$str\n$underlines" + else cd $DEFAULT_PATH + if [ -e $delete ]; then rm $delete clear @@ -29,8 +37,9 @@ function delnote() { underlines=$(echo "$str" | tr -c '\010' '-') echo "$str\n$underlines" else - echo "No such file." + echo "Invalid argument or parameter given." cd $DIR fi fi +fi } \ No newline at end of file diff --git a/util/findmisplacednote.sh b/util/findmisplacednote.sh index 4ee8c7d..17ec22d 100644 --- a/util/findmisplacednote.sh +++ b/util/findmisplacednote.sh @@ -11,6 +11,12 @@ function findmisplacednote() { else notename=$1 fi - echo "Possible locations: " - find ~/ -iname $notename -print 2>/dev/null + + if [ -z $notename ]; then + echo "Invalid input." + return 0 + else + echo "Possible locations: " + find ~/ -iname $notename -print 2>/dev/null + fi } \ No newline at end of file diff --git a/util/findnote.sh b/util/findnote.sh index fca067d..1dad879 100644 --- a/util/findnote.sh +++ b/util/findnote.sh @@ -11,14 +11,20 @@ function findnote() { else notename=$1 fi - cd $DEFAULT_PATH - if [ -e $notename ]; then - echo "File was found in your Notes folder." + + if [ -z $notename ]; then + echo "Invalid input." + return 0 else - echo "File was not found in your Notes folder, must be misplaced or renamed." - echo "Try 'findmisplacednote' to find the original file." + cd $DEFAULT_PATH + if [ -e $notename ]; then + echo "File was found in your Notes folder." + else + echo "File was not found in your Notes folder, must be misplaced or renamed." + echo "Try 'findmisplacednote' to find the original file." + fi fi - cd $DIR + cd $DIR } diff --git a/util/l/l.sh b/util/l/l.sh index 81e5ff6..06d3e2b 100644 --- a/util/l/l.sh +++ b/util/l/l.sh @@ -16,22 +16,29 @@ case $1 in -l|--logs ) echo "4. update errors" echo "5. uninstallation errors" echo "6. set-defaults errors" + echo echo "For more info about which one to choose, read /docs/system/loggingsystem.txt" echo echo -n "[1,2,3,4,5]: " && read input - if [ $input = 1 ]; then - less ~/.shellnotes/logs/disfailed.txt - elif [ $input = 2 ]; then - less ~/.shellnotes/logs/enfailed.txt - elif [ $input = 3 ]; then - less ~/.shellnotes/logs/ifailed.txt - elif [ $input = 4 ]; then - less ~/.shellnotes/logs/ufailed.txt - elif [ $input = 5 ]; then - less ~/.shellnotes/logs/uninfailed.txt - elif [ $input = 6 ]; then - less ~/.shellnotes/logs/sdfailed.txt - else + if [ -z $input ]; then echo "Invalid input." + return 0 + else + + if [ $input = 1 ]; then + less ~/.shellnotes/logs/disfailed.txt + elif [ $input = 2 ]; then + less ~/.shellnotes/logs/enfailed.txt + elif [ $input = 3 ]; then + less ~/.shellnotes/logs/ifailed.txt + elif [ $input = 4 ]; then + less ~/.shellnotes/logs/ufailed.txt + elif [ $input = 5 ]; then + less ~/.shellnotes/logs/uninfailed.txt + elif [ $input = 6 ]; then + less ~/.shellnotes/logs/sdfailed.txt + else + echo "Invalid input." + fi fi esac \ No newline at end of file diff --git a/util/newnote.sh b/util/newnote.sh index 366cbd8..27d694c 100644 --- a/util/newnote.sh +++ b/util/newnote.sh @@ -5,12 +5,14 @@ Released under the "All rights reserved" category. See the RIGHTS.txt file in /docs/github/ for its full text. info -function newnote() { -cd $DEFAULT_PATH -$NOTES_EDITOR -clear -cd $DIR -str="Note created in $DEFAULT_PATH" -underlines=$(echo "$str" | tr -c '\010' '-') -echo "$str\n$underlines" +function newnote() { + + cd $DEFAULT_PATH + $NOTES_EDITOR + clear + cd $DIR + str="Note created in $DEFAULT_PATH" + underlines=$(echo "$str" | tr -c '\010' '-') + echo "$str\n$underlines" + } \ No newline at end of file diff --git a/util/noteinfo.sh b/util/noteinfo.sh index c672cb2..0ac082a 100644 --- a/util/noteinfo.sh +++ b/util/noteinfo.sh @@ -11,12 +11,20 @@ function noteinfo() { else notename=$1 fi - cd $DEFAULT_PATH - if [ -e $notename ]; then - wc $notename - echo "(lines/words/chars/name)" -else - echo "That note doesn't exist." -fi + + if [ -z $notename ]; then + echo "Invalid input." + return 0 + else + cd $DEFAULT_PATH + if [ -e $notename ]; then + wc $notename + echo "(lines/words/chars/name)" + else + echo "That note doesn't exist." + fi + fi + cd $DIR + } \ No newline at end of file diff --git a/util/quicknote.sh b/util/quicknote.sh index c231de7..4e9d1e8 100644 --- a/util/quicknote.sh +++ b/util/quicknote.sh @@ -6,37 +6,47 @@ in /docs/github/ for its full text. info function quicknote() { -if [ $# -eq 0 ]; then - echo -n "Enter note name: " && read notename -else - notename=$1 -fi -cd $DEFAULT_PATH -if [ -e $notename ]; then - clear - echo "This note already exists." - cd .. - echo -n "Do you want to read it?[Y/N]: " && read readquicknote - -else - touch $notename - $QUICK_NOTES_EDITOR $notename - cd $DIR - clear - str="Note created in $DEFAULT_PATH" - underlines=$(echo "$str" | tr -c '\010' '-') - echo "$str\n$underlines" - -fi - -case $readquicknote in y|Y|YES|Yes|yes ) - clear - cd $DEFAULT_PATH - if [[ -e $notename ]]; then - cat $notename + if [ $# -eq 0 ]; then + echo -n "Enter note name: " && read notename else - echo "This note is blank." + notename=$1 fi -esac + + if [ -z $notename ]; then + echo "Invalid input." + return 0 + + else + + cd $DEFAULT_PATH + if [ -e $notename ]; then + clear + echo "This note already exists." + cd .. + echo -n "Do you want to read it?[Y/N]: " && read readquicknote + + else + touch $notename + $QUICK_NOTES_EDITOR $notename + cd $DIR + clear + str="Note created in $DEFAULT_PATH" + underlines=$(echo "$str" | tr -c '\010' '-') + echo "$str\n$underlines" + + fi + + case $readquicknote in y|Y|YES|Yes|yes ) + clear + cd $DEFAULT_PATH + if [[ -e $notename ]]; then + cat $notename + else + echo "This note is blank." + fi + esac + + fi + cd $DIR } \ No newline at end of file diff --git a/util/readnote.sh b/util/readnote.sh index f8002b0..be5d19d 100644 --- a/util/readnote.sh +++ b/util/readnote.sh @@ -12,23 +12,29 @@ function readnote() { notename=$1 fi - cd $DEFAULT_PATH - if [ -e $notename ]; then - chmod 0444 $notename - $NOTES_EDITOR $notename - chmod +rw $notename - - else - clear - echo "No such note." - echo -n "Do you want to create one?[Y/N]: " && read create; - fi - - case $create in y|Y|YES|Yes|yes ) - $NOTES_EDITOR - esac - - clear - cd $DIR + if [ -z $notename ]; then + echo "Invalid input." + return 0 + else + + cd $DEFAULT_PATH + if [ -e $notename ]; then + chmod 0444 $notename + $NOTES_EDITOR $notename + chmod +rw $notename + + else + clear + echo "No such note." + echo -n "Do you want to create one?[Y/N]: " && read create; + fi + + case $create in y|Y|YES|Yes|yes ) + $NOTES_EDITOR + esac + + clear + cd $DIR + fi } \ No newline at end of file diff --git a/util/renamenote.sh b/util/renamenote.sh index 839071d..bc88073 100644 --- a/util/renamenote.sh +++ b/util/renamenote.sh @@ -15,20 +15,35 @@ function renamenote() { newnotename=$2 fi - if [ -e $notename ]; then - if [ -e $newnotename ]; then - echo "There is another note named '$newnotename' in your Notes folder." - else - mv $notename $newnotename - clear - str="Note renamed from $notename to $newnotename in $DEFAULT_PATH" - underlines=$(echo "$str" | tr -c '\010' '-') - echo "$str\n$underlines" - fi + + if [ -z $notename ]; then + echo "Invalid input." + cd $DIR + return 0 + + elif [ -z $newnotename ]; then + echo "Invalid input." + cd $DIR + return 0 else - echo "This note does not exist." - fi - + + if [ -e $notename ]; then + if [ -e $newnotename ]; then + echo "There is another note named '$newnotename' in your Notes folder." + else + mv $notename $newnotename + clear + str="Note renamed from $notename to $newnotename in $DEFAULT_PATH" + underlines=$(echo "$str" | tr -c '\010' '-') + echo "$str\n$underlines" + fi + + else + echo "This note does not exist." + fi + cd $DIR + + fi } \ No newline at end of file