Fix output bug

Fix -cf and -sf returning "No such file" or proceeding in normal grep mode
This commit is contained in:
dmarakom6 2021-06-28 13:42:57 +03:00
parent 25092fe9b4
commit e3f7e7414f
3 changed files with 22 additions and 18 deletions

View file

@ -130,8 +130,9 @@ function notegrep() {
-cl | --count-lines ) -cl | --count-lines )
. ~/.shellnotes/util/notegrep/cl.sh . ~/.shellnotes/util/notegrep/cl.sh
;; ;;
-sl | --show-lines )
. ~/.shellnotes/util/notegrep/sl.sh
;;
*) *)
echo "Invalid parameter. Proceeding in normal grep mode." echo "Invalid parameter. Proceeding in normal grep mode."
do_grep do_grep
@ -145,6 +146,7 @@ function notegrep() {
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
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
do_grep
else else
if [ $# -eq 3 ]; then if [ $# -eq 3 ]; then
export option=$1 export option=$1
@ -168,24 +170,26 @@ function notegrep() {
export regex=$2 export regex=$2
export option=$1 export option=$1
. ~/.shellnotes/util/notegrep/sf.sh . ~/.shellnotes/util/notegrep/sf.sh
;;
*)
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
;; ;;
esac esac
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
fi fi
unset GREP_OPTIONS unset GREP_OPTIONS

View file

@ -11,7 +11,7 @@ if [ $files -eq 1 ]; then
echo "Found $files matching file in $DEFAULT_PATH." echo "Found $files matching file in $DEFAULT_PATH."
elif [ $files -gt 1 ]; then elif [ $files -gt 1 ]; then
echo "Found $files matching files in $DEFAULT_PATH." echo "Found $files matching files in $DEFAULT_PATH."
echo -n "Show files? " && read show echo -n "Show files?(Y/N): " && read show
case $show in case $show in
yes | y | Y | YES | Yes ) yes | y | Y | YES | Yes )
grep -rwl $regex $DEFAULT_PATH/* grep -rwl $regex $DEFAULT_PATH/*

View file

@ -11,4 +11,4 @@ if [ $files -ge 1 ]; then
grep -rwl $regex $DEFAULT_PATH/* grep -rwl $regex $DEFAULT_PATH/*
else else
echo "No matching files found." echo "No matching files found."
fi fi