notegrep: "cf" parameter
This commit is contained in:
parent
2552a92a06
commit
09de7c2a1c
4 changed files with 48 additions and 9 deletions
|
@ -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
|
||||
|
@ -166,6 +181,8 @@ function notegrep() {
|
|||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
do_grep
|
||||
|
||||
unset GREP_OPTIONS
|
||||
|
|
23
util/notegrep/cf.sh
Normal file
23
util/notegrep/cf.sh
Normal 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
|
||||
|
|
@ -6,4 +6,11 @@ in /docs/github/ for its full text.
|
|||
info
|
||||
|
||||
out="$(grep $regex $DEFAULT_PATH/$notename | wc -l)"
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue