added function for chained grep commands

This commit is contained in:
pyr0ball 2023-05-09 12:11:56 -07:00
parent 87d3e369cd
commit 69b33fb9cf

View file

@ -2,7 +2,7 @@
# pyr0ball script functions library # pyr0ball script functions library
# Initial Vars # Initial Vars
functionsrev=1.1.14 functionsrev=1.1.15
#scriptname="${BASH_SOURCE[0]##*/}" #scriptname="${BASH_SOURCE[0]##*/}"
#rundir="${BASH_SOURCE[0]%/*}" #rundir="${BASH_SOURCE[0]%/*}"
#rundir_absolute=$(cd $rundir && pwd) #rundir_absolute=$(cd $rundir && pwd)
@ -524,6 +524,8 @@ install-dir() {
done < <(find "$_source" -type f -print0) done < <(find "$_source" -type f -print0)
} }
# Utilities
clone-repo(){ clone-repo(){
# git clone <source url> <destination> # git clone <source url> <destination>
local _url=$1 local _url=$1
@ -534,11 +536,33 @@ clone-repo(){
run git clone --recurse-submodules $_url $_destination run git clone --recurse-submodules $_url $_destination
} }
# Executes: grep "$1" | grep "$2" | grep "$3" | ...
chained-grep(){
local pattern="$1"
if [[ -z "$pattern" ]]; then
cat
return
fi
shift
grep -- "$pattern" | chained-grep "$@"
}
# Remove leading/trailing whitespace
trim() {
local var=$1
var="${var#"${var%%[![:space:]]*}"}"
var="${var%"${var##*[![:space:]]}"}"
printf '%s' "$var"
}
ctrl_c(){ ctrl_c(){
echo -e "\n" echo -e "\n"
fail "User interrupted with Ctrl-C" fail "User interrupted with Ctrl-C"
} }
# Cosmetics
prbl-logo(){ prbl-logo(){
echo -e \ echo -e \
" "
@ -678,7 +702,7 @@ spinstart() {
sstop=false sstop=false
tput civis tput civis
sc=0 sc=0
while [[ $sstop == false ]] ; do until [[ $sstop != false ]] ; do
for i in "${FRAME[@]}" ; do for i in "${FRAME[@]}" ; do
printf "\b${FRAME:sc++:1}" printf "\b${FRAME:sc++:1}"
((sc==${#FRAME})) && sc=0 ((sc==${#FRAME})) && sc=0
@ -711,6 +735,8 @@ printf "\rProgress : [${_done// /#}${_left// /-}] ${_progress}%%"
} }
# Menu functions
# Renders a text based list of options that can be selected by the # Renders a text based list of options that can be selected by the
# user using up, down and enter keys and returns the chosen option. # user using up, down and enter keys and returns the chosen option.
# #
@ -976,6 +1002,10 @@ vercomp() {
return 0 return 0
} }
check-prbl-version(){
vercomp
}
compare-versions() { compare-versions() {
vercomp $1 $2 vercomp $1 $2
case $? in case $? in