notegrep: check if there are no matches
This commit is contained in:
parent
7644878de0
commit
bca9e2bcbf
1 changed files with 24 additions and 10 deletions
|
@ -96,16 +96,26 @@ function notegrep() {
|
||||||
echo -n "Enter regex: " && read regex
|
echo -n "Enter regex: " && read regex
|
||||||
echo -n "Enter note name: " && read notename
|
echo -n "Enter note name: " && read notename
|
||||||
else
|
else
|
||||||
notename=$2
|
if [ $# -eq 3 ]; then
|
||||||
|
option=$1
|
||||||
|
regex=$2
|
||||||
|
notename=$3
|
||||||
|
#check
|
||||||
|
return 0
|
||||||
|
else
|
||||||
regex=$1
|
regex=$1
|
||||||
|
notename=$2
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z $notename ]; then
|
if [ -z $notename ]; then
|
||||||
echo "Invalid input."
|
echo "Invalid input."
|
||||||
|
cd $DIR
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
elif [ -z $regex ]; then
|
elif [ -z $regex ]; then
|
||||||
echo "No pattern given."
|
echo "No pattern given."
|
||||||
|
cd $DIR
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -113,12 +123,16 @@ function notegrep() {
|
||||||
cd $DEFAULT_PATH
|
cd $DEFAULT_PATH
|
||||||
out="$(grep $regex $notename | wc -l)"
|
out="$(grep $regex $notename | wc -l)"
|
||||||
|
|
||||||
|
if [ "$(grep -c $regex $notename)" -eq 0 ]; then
|
||||||
|
echo "No matches found."
|
||||||
|
else
|
||||||
|
|
||||||
if [ $out -gt 20 ]; then
|
if [ $out -gt 20 ]; then
|
||||||
grep -i $regex $notename | less
|
grep -i $regex $notename | less
|
||||||
elif [ $out -le 20 ]; then
|
elif [ $out -le 20 ]; then
|
||||||
grep -i $regex $notename
|
grep -i $regex $notename
|
||||||
else
|
fi
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue