Continue with grep if parameter is invalid

This commit is contained in:
dmarakom6 2021-06-14 19:56:37 +03:00
parent bca9e2bcbf
commit 4c92ad77fd

View file

@ -92,32 +92,10 @@ comment
function notegrep() {
if [ $# -eq 0 ]; then
echo -n "Enter regex: " && read regex
echo -n "Enter note name: " && read notename
else
if [ $# -eq 3 ]; then
option=$1
regex=$2
notename=$3
#check
return 0
else
regex=$1
notename=$2
fi
fi
if [ -z $notename ]; then
echo "Invalid input."
cd $DIR
return 0
DIR="$(pwd)"
elif [ -z $regex ]; then
echo "No pattern given."
cd $DIR
return 0
fi
do_grep() {
if [ -e ${DEFAULT_PATH}/${notename} ]; then
cd $DEFAULT_PATH
@ -139,6 +117,51 @@ function notegrep() {
echo "This note doesn't exist in $DEFAULT_PATH."
fi
}
check_params() {
case $option in
parameter)
#parameter script import...
;;
*)
echo "Invalid parameter. Proceeding in normal grep mode."
do_grep
;;
esac
}
if [ $# -eq 0 ]; then
echo -n "Enter regex: " && read regex
echo -n "Enter note name: " && read notename
else
if [ $# -eq 3 ]; then
option=$1
regex=$2
notename=$3
check_params
return 0
else
regex=$1
notename=$2
fi
fi
if [ -z $notename ]; then
echo "Invalid input."
cd $DIR
return 0
elif [ -z $regex ]; then
echo "No pattern given."
cd $DIR
return 0
fi
do_grep
unset GREP_OPTIONS
cd $DIR
return 0