From e3f7e7414f7b1de62bfa4cbe00edf0d993518c62 Mon Sep 17 00:00:00 2001 From: dmarakom6 Date: Mon, 28 Jun 2021 13:42:57 +0300 Subject: [PATCH] Fix output bug Fix -cf and -sf returning "No such file" or proceeding in normal grep mode --- util/notegrep.sh | 36 ++++++++++++++++++++---------------- util/notegrep/cf.sh | 2 +- util/notegrep/sf.sh | 2 +- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/util/notegrep.sh b/util/notegrep.sh index 09e3b34..c495f80 100644 --- a/util/notegrep.sh +++ b/util/notegrep.sh @@ -130,8 +130,9 @@ function notegrep() { -cl | --count-lines ) . ~/.shellnotes/util/notegrep/cl.sh ;; - - + -sl | --show-lines ) + . ~/.shellnotes/util/notegrep/sl.sh + ;; *) echo "Invalid parameter. Proceeding in normal grep mode." do_grep @@ -145,6 +146,7 @@ function notegrep() { if [ $# -eq 0 ]; then echo -n "Enter regex: " && read regex echo -n "Enter note name: " && read notename + do_grep else if [ $# -eq 3 ]; then export option=$1 @@ -168,24 +170,26 @@ function notegrep() { export regex=$2 export option=$1 . ~/.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 - 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 unset GREP_OPTIONS diff --git a/util/notegrep/cf.sh b/util/notegrep/cf.sh index 46381a6..7c99fb4 100644 --- a/util/notegrep/cf.sh +++ b/util/notegrep/cf.sh @@ -11,7 +11,7 @@ if [ $files -eq 1 ]; then echo "Found $files matching file in $DEFAULT_PATH." elif [ $files -gt 1 ]; then 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 yes | y | Y | YES | Yes ) grep -rwl $regex $DEFAULT_PATH/* diff --git a/util/notegrep/sf.sh b/util/notegrep/sf.sh index f80010c..839bd46 100644 --- a/util/notegrep/sf.sh +++ b/util/notegrep/sf.sh @@ -11,4 +11,4 @@ if [ $files -ge 1 ]; then grep -rwl $regex $DEFAULT_PATH/* else echo "No matching files found." -fi \ No newline at end of file +fi