From 09de7c2a1ca932d2a89389e4994860808bc76a3c Mon Sep 17 00:00:00 2001 From: dmarakom6 Date: Wed, 23 Jun 2021 19:27:44 +0300 Subject: [PATCH] notegrep: "cf" parameter --- util/notegrep.sh | 17 +++++++++++++++++ util/notegrep/cf.sh | 23 +++++++++++++++++++++++ util/notegrep/cl.sh | 9 ++++++++- util/notegrep/sc.sh | 8 -------- 4 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 util/notegrep/cf.sh diff --git a/util/notegrep.sh b/util/notegrep.sh index ffddca6..f0f913f 100644 --- a/util/notegrep.sh +++ b/util/notegrep.sh @@ -121,6 +121,8 @@ function notegrep() { check_params() { + #Function for checking notegrep parameters with three or more options. + case $option in -sc | --split-char) . ~/.shellnotes/util/notegrep/sc.sh @@ -128,6 +130,8 @@ function notegrep() { -cl | --count-lines ) . ~/.shellnotes/util/notegrep/cl.sh ;; + + *) echo "Invalid parameter. Proceeding in normal grep mode." do_grep @@ -152,6 +156,17 @@ function notegrep() { regex=$1 notename=$2 fi + + #Parameters without three or more options + case $regex in + -cf | --count-files ) + export regex=$2 + export option=$1 + . ~/.shellnotes/util/notegrep/cf.sh + ;; + esac + return 0 + fi if [ -z $notename ]; then @@ -165,6 +180,8 @@ function notegrep() { return 0 fi + + do_grep diff --git a/util/notegrep/cf.sh b/util/notegrep/cf.sh new file mode 100644 index 0000000..46381a6 --- /dev/null +++ b/util/notegrep/cf.sh @@ -0,0 +1,23 @@ +:<<'info' +shellnotes - cf.sh +(C) Dimitris Marakomihelakis +Released under the "All rights reserved" category. See the RIGHTS.txt file +in /docs/github/ for its full text. +info + +files="$(grep -rwl $regex $DEFAULT_PATH/* | wc -l)" + +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 + case $show in + yes | y | Y | YES | Yes ) + grep -rwl $regex $DEFAULT_PATH/* + ;; + esac +else + echo "No matching files found." +fi + diff --git a/util/notegrep/cl.sh b/util/notegrep/cl.sh index 622ed9e..6db29ca 100644 --- a/util/notegrep/cl.sh +++ b/util/notegrep/cl.sh @@ -6,4 +6,11 @@ in /docs/github/ for its full text. info out="$(grep $regex $DEFAULT_PATH/$notename | wc -l)" -echo "Compressed $out lines of grep output." \ No newline at end of file + +if [ $out -eq 1 ]; then + echo "Compressed $out line of grep output." +elif [ $out -gt 1 ]; then + echo "Compressed $out lines of grep output." +else + echo "No matching files found." +fi diff --git a/util/notegrep/sc.sh b/util/notegrep/sc.sh index afa58f0..cf37c62 100644 --- a/util/notegrep/sc.sh +++ b/util/notegrep/sc.sh @@ -5,14 +5,6 @@ Released under the "All rights reserved" category. See the RIGHTS.txt file in /docs/github/ for its full text. info -:<<'vars' -Used from main file: -$option -$regex -$notename -vars - - out="$(cat $DEFAULT_PATH/$notename | sed s/$regex/\\n/g | wc -l)" if [ $out -gt 20 ]; then