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,6 +11,12 @@ 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 *
@ -19,8 +25,10 @@ function delnote() {
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
if [ -z $notename ]; then
echo "Invalid input."
return 0
else
echo "Possible locations: " echo "Possible locations: "
find ~/ -iname $notename -print 2>/dev/null find ~/ -iname $notename -print 2>/dev/null
fi
} }

View file

@ -11,6 +11,11 @@ function findnote() {
else else
notename=$1 notename=$1
fi fi
if [ -z $notename ]; then
echo "Invalid input."
return 0
else
cd $DEFAULT_PATH cd $DEFAULT_PATH
if [ -e $notename ]; then if [ -e $notename ]; then
echo "File was found in your Notes folder." echo "File was found in your Notes folder."
@ -19,6 +24,7 @@ function findnote() {
echo "Try 'findmisplacednote' to find the original file." echo "Try 'findmisplacednote' to find the original file."
fi fi
cd $DIR fi
cd $DIR
} }

View file

@ -16,9 +16,15 @@ 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 [ -z $input ]; then
echo "Invalid input."
return 0
else
if [ $input = 1 ]; then if [ $input = 1 ]; then
less ~/.shellnotes/logs/disfailed.txt less ~/.shellnotes/logs/disfailed.txt
elif [ $input = 2 ]; then elif [ $input = 2 ]; then
@ -34,4 +40,5 @@ case $1 in -l|--logs )
else else
echo "Invalid input." 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
if [ -z $notename ]; then
echo "Invalid input."
return 0
else
cd $DEFAULT_PATH cd $DEFAULT_PATH
if [ -e $notename ]; then if [ -e $notename ]; then
wc $notename wc $notename
echo "(lines/words/chars/name)" echo "(lines/words/chars/name)"
else else
echo "That note doesn't exist." echo "That note doesn't exist."
fi fi
fi
cd $DIR cd $DIR
} }

View file

@ -6,19 +6,26 @@ 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 else
notename=$1 notename=$1
fi fi
cd $DEFAULT_PATH
if [ -e $notename ]; then if [ -z $notename ]; then
echo "Invalid input."
return 0
else
cd $DEFAULT_PATH
if [ -e $notename ]; then
clear clear
echo "This note already exists." echo "This note already exists."
cd .. cd ..
echo -n "Do you want to read it?[Y/N]: " && read readquicknote echo -n "Do you want to read it?[Y/N]: " && read readquicknote
else else
touch $notename touch $notename
$QUICK_NOTES_EDITOR $notename $QUICK_NOTES_EDITOR $notename
cd $DIR cd $DIR
@ -27,9 +34,9 @@ else
underlines=$(echo "$str" | tr -c '\010' '-') underlines=$(echo "$str" | tr -c '\010' '-')
echo "$str\n$underlines" echo "$str\n$underlines"
fi fi
case $readquicknote in y|Y|YES|Yes|yes ) case $readquicknote in y|Y|YES|Yes|yes )
clear clear
cd $DEFAULT_PATH cd $DEFAULT_PATH
if [[ -e $notename ]]; then if [[ -e $notename ]]; then
@ -37,6 +44,9 @@ case $readquicknote in y|Y|YES|Yes|yes )
else else
echo "This note is blank." echo "This note is blank."
fi fi
esac esac
fi
cd $DIR cd $DIR
} }

View file

@ -12,6 +12,12 @@ function readnote() {
notename=$1 notename=$1
fi fi
if [ -z $notename ]; then
echo "Invalid input."
return 0
else
cd $DEFAULT_PATH cd $DEFAULT_PATH
if [ -e $notename ]; then if [ -e $notename ]; then
chmod 0444 $notename chmod 0444 $notename
@ -30,5 +36,5 @@ function readnote() {
clear clear
cd $DIR cd $DIR
fi
} }

View file

@ -15,6 +15,19 @@ function renamenote() {
newnotename=$2 newnotename=$2
fi fi
if [ -z $notename ]; then
echo "Invalid input."
cd $DIR
return 0
elif [ -z $newnotename ]; then
echo "Invalid input."
cd $DIR
return 0
else
if [ -e $notename ]; then if [ -e $notename ]; then
if [ -e $newnotename ]; then if [ -e $newnotename ]; then
echo "There is another note named '$newnotename' in your Notes folder." echo "There is another note named '$newnotename' in your Notes folder."
@ -31,4 +44,6 @@ function renamenote() {
fi fi
cd $DIR cd $DIR
fi
} }