notegrep: "cf" parameter

This commit is contained in:
dmarakom6 2021-06-23 19:27:44 +03:00
parent 2552a92a06
commit 09de7c2a1c
4 changed files with 48 additions and 9 deletions

View file

@ -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

23
util/notegrep/cf.sh Normal file
View file

@ -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

View file

@ -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."
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

View file

@ -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