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 note name: " && read notename
|
||||
else
|
||||
notename=$2
|
||||
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 [ "$(grep -c $regex $notename)" -eq 0 ]; then
|
||||
echo "No matches found."
|
||||
else
|
||||
|
||||
if [ $out -gt 20 ]; then
|
||||
grep -i $regex $notename | less
|
||||
elif [ $out -le 20 ]; then
|
||||
grep -i $regex $notename
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue