From bca9e2bcbf29b1ba0733f8f07c733551ab3e41fa Mon Sep 17 00:00:00 2001 From: dmarakom6 Date: Sun, 13 Jun 2021 14:13:51 +0300 Subject: [PATCH] notegrep: check if there are no matches --- util/notegrep.sh | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/util/notegrep.sh b/util/notegrep.sh index 5a61749..cee49e8 100644 --- a/util/notegrep.sh +++ b/util/notegrep.sh @@ -94,18 +94,28 @@ comment function notegrep() { if [ $# -eq 0 ]; then echo -n "Enter regex: " && read regex - echo -n "Enter note name: " && read notename - else - notename=$2 - regex=$1 - fi + 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 elif [ -z $regex ]; then echo "No pattern given." + cd $DIR return 0 fi @@ -113,12 +123,16 @@ function notegrep() { cd $DEFAULT_PATH out="$(grep $regex $notename | wc -l)" - if [ $out -gt 20 ]; then - grep -i $regex $notename | less - elif [ $out -le 20 ]; then - grep -i $regex $notename + if [ "$(grep -c $regex $notename)" -eq 0 ]; then + echo "No matches found." else - return 0 + + if [ $out -gt 20 ]; then + grep -i $regex $notename | less + elif [ $out -le 20 ]; then + grep -i $regex $notename + fi + fi else