Fix input bug

A newline input doesn't result in an error anymore.
This commit is contained in:
dmarakom6 2021-04-25 13:23:38 +03:00
parent 79e9e6ed0d
commit bfc7fd6de6
10 changed files with 186 additions and 113 deletions

View file

@ -13,7 +13,8 @@ echo "2.Disable shellnotes and all its commands, but keep the files in your syst
echo "3.Enable shellnotes." echo "3.Enable shellnotes."
echo "" echo ""
echo -n "[1,2,3]: " && read option echo -n "[1,2,3]: " && read option
if [ $option = "1" ]; then
case $option in 1 )
if [ -e ~/.shellnotes/.shellnotes.sh ]; then if [ -e ~/.shellnotes/.shellnotes.sh ]; then
echo -n "Are you sure you want to delete Shellnotes?[Y/N]: " && read delete echo -n "Are you sure you want to delete Shellnotes?[Y/N]: " && read delete
case $delete in y|Y|YES|Yes|yes ) case $delete in y|Y|YES|Yes|yes )
@ -82,9 +83,9 @@ if [ $option = "1" ]; then
./uninfailed ./uninfailed
cd $DIR cd $DIR
fi fi
esac
case $option in 2 )
elif [ $option = "2" ]; then
if grep 'return' <~/.shellnotes/.shellnotes.sh >/dev/null; then if grep 'return' <~/.shellnotes/.shellnotes.sh >/dev/null; then
echo "Shellnotes is already disabled." echo "Shellnotes is already disabled."
cd ~/.shellnotes/util/exec 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 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)." echo "Shellnotes is now disabled. To enable, run this script again and choose option (3)."
fi fi
elif [ $option = "3" ]; then esac
case $option in 3 )
if grep 'return' <~/.shellnotes/.shellnotes.sh >/dev/null; then if grep 'return' <~/.shellnotes/.shellnotes.sh >/dev/null; then
sed -i '2d' ~/.shellnotes/.shellnotes.sh sed -i '2d' ~/.shellnotes/.shellnotes.sh
echo "Shellnotes is now enabled. Please restart your terminal." echo "Shellnotes is now enabled. Please restart your terminal."
@ -104,9 +107,10 @@ elif [ $option = "3" ]; then
./enfailed ./enfailed
cd $DIR cd $DIR
fi fi
else esac
echo "This is not an option."
fi
case $option in
(*[a-zA-Z]* | "" )
echo "Invalid input."
esac

View file

@ -11,16 +11,24 @@ function delnote() {
else else
delete=$1 delete=$1
fi fi
if [ -z $delete ]; then
echo "Invalid input."
return 0
else
if [[ $1 == "-all" ]]; then if [[ $1 == "-all" ]]; then
cd $DEFAULT_PATH cd $DEFAULT_PATH
rm -f * rm -f *
clear clear
cd $DIR cd $DIR
str="All files deleted from $DEFAULT_PATH" str="All files deleted from $DEFAULT_PATH"
underlines=$(echo "$str" | tr -c '\010' '-') underlines=$(echo "$str" | tr -c '\010' '-')
echo "$str\n$underlines" echo "$str\n$underlines"
else else
cd $DEFAULT_PATH cd $DEFAULT_PATH
if [ -e $delete ]; then if [ -e $delete ]; then
rm $delete rm $delete
clear clear
@ -29,8 +37,9 @@ function delnote() {
underlines=$(echo "$str" | tr -c '\010' '-') underlines=$(echo "$str" | tr -c '\010' '-')
echo "$str\n$underlines" echo "$str\n$underlines"
else else
echo "No such file." echo "Invalid argument or parameter given."
cd $DIR cd $DIR
fi fi
fi fi
fi
} }

View file

@ -11,6 +11,12 @@ function findmisplacednote() {
else else
notename=$1 notename=$1
fi 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
} }

View file

@ -11,14 +11,20 @@ function findnote() {
else else
notename=$1 notename=$1
fi fi
cd $DEFAULT_PATH
if [ -e $notename ]; then if [ -z $notename ]; then
echo "File was found in your Notes folder." echo "Invalid input."
return 0
else else
echo "File was not found in your Notes folder, must be misplaced or renamed." cd $DEFAULT_PATH
echo "Try 'findmisplacednote' to find the original file." 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 fi
cd $DIR
cd $DIR
} }

View file

@ -16,22 +16,29 @@ case $1 in -l|--logs )
echo "4. update errors" echo "4. update errors"
echo "5. uninstallation errors" echo "5. uninstallation errors"
echo "6. set-defaults errors" echo "6. set-defaults errors"
echo
echo "For more info about which one to choose, read /docs/system/loggingsystem.txt" echo "For more info about which one to choose, read /docs/system/loggingsystem.txt"
echo echo
echo -n "[1,2,3,4,5]: " && read input echo -n "[1,2,3,4,5]: " && read input
if [ $input = 1 ]; then if [ -z $input ]; 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." 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 fi
esac esac

View file

@ -6,11 +6,13 @@ in /docs/github/ for its full text.
info info
function newnote() { function newnote() {
cd $DEFAULT_PATH
$NOTES_EDITOR cd $DEFAULT_PATH
clear $NOTES_EDITOR
cd $DIR clear
str="Note created in $DEFAULT_PATH" cd $DIR
underlines=$(echo "$str" | tr -c '\010' '-') str="Note created in $DEFAULT_PATH"
echo "$str\n$underlines" underlines=$(echo "$str" | tr -c '\010' '-')
echo "$str\n$underlines"
} }

View file

@ -11,12 +11,20 @@ function noteinfo() {
else else
notename=$1 notename=$1
fi fi
cd $DEFAULT_PATH
if [ -e $notename ]; then if [ -z $notename ]; then
wc $notename echo "Invalid input."
echo "(lines/words/chars/name)" return 0
else else
echo "That note doesn't exist." cd $DEFAULT_PATH
fi if [ -e $notename ]; then
wc $notename
echo "(lines/words/chars/name)"
else
echo "That note doesn't exist."
fi
fi
cd $DIR cd $DIR
} }

View file

@ -6,37 +6,47 @@ in /docs/github/ for its full text.
info info
function quicknote() { function quicknote() {
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
echo -n "Enter note name: " && read notename 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
else else
echo "This note is blank." notename=$1
fi 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 cd $DIR
} }

View file

@ -12,23 +12,29 @@ function readnote() {
notename=$1 notename=$1
fi fi
cd $DEFAULT_PATH if [ -z $notename ]; then
if [ -e $notename ]; then echo "Invalid input."
chmod 0444 $notename return 0
$NOTES_EDITOR $notename
chmod +rw $notename
else 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 clear
echo "No such note." cd $DIR
echo -n "Do you want to create one?[Y/N]: " && read create;
fi fi
case $create in y|Y|YES|Yes|yes )
$NOTES_EDITOR
esac
clear
cd $DIR
} }

View file

@ -15,20 +15,35 @@ function renamenote() {
newnotename=$2 newnotename=$2
fi fi
if [ -e $notename ]; then
if [ -e $newnotename ]; then if [ -z $notename ]; then
echo "There is another note named '$newnotename' in your Notes folder." echo "Invalid input."
else cd $DIR
mv $notename $newnotename return 0
clear
str="Note renamed from $notename to $newnotename in $DEFAULT_PATH" elif [ -z $newnotename ]; then
underlines=$(echo "$str" | tr -c '\010' '-') echo "Invalid input."
echo "$str\n$underlines" cd $DIR
fi return 0
else 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 cd $DIR
fi
} }