chore: Use grep -E / grep -F instead of egrep / fgrep (#2164)

Ensures that the -E or -F option, when used, is the first option
* i.e. grep -oE => grep -E -o

Updates _bash-it-grep to invoke grep with just the provided arguments
* This function was (and still is) unused, but decided this new functionality was actually more useful

Introduces _bash-it-fgrep to invoke grep -F

Removes type -P egrep from the _bash-it-*grep functions

For usages that were already going to be modified, use -F if appropriate
* Does not touch grep usages that may have benefited from -F, but were not otherwise considered for this PR

Adds shellcheck header to modified .bash files that didn't already have it
This commit is contained in:
David Farrell
2022-10-13 10:34:57 -07:00
committed by GitHub
parent bf2034d13d
commit 00062bfcb6
10 changed files with 36 additions and 22 deletions

View File

@@ -211,7 +211,7 @@ function _is_function() {
_example '$ _is_function ls && echo exists'
_group 'lib'
local msg="${2:-Function '$1' does not exist}"
if LC_ALL=C type -t "$1" | _bash-it-egrep -q 'function'; then
if LC_ALL=C type -t "$1" | _bash-it-fgrep -q 'function'; then
return 0
else
_log_debug "$msg"

View File

@@ -60,15 +60,21 @@ function _bash-it-array-dedup() {
printf '%s\n' "$@" | sort -u
}
# Outputs a full path of the grep found on the filesystem
# Runs `grep` with *just* the provided arguments
function _bash-it-grep() {
: "${BASH_IT_GREP:=$(type -P egrep || type -P grep)}"
printf "%s" "${BASH_IT_GREP:-/usr/bin/grep}"
: "${BASH_IT_GREP:=$(type -P grep)}"
"${BASH_IT_GREP:-/usr/bin/grep}" "$@"
}
# Runs `grep` with extended regular expressions
# Runs `grep` with fixed-string expressions (-F)
function _bash-it-fgrep() {
: "${BASH_IT_GREP:=$(type -P grep)}"
"${BASH_IT_GREP:-/usr/bin/grep}" -F "$@"
}
# Runs `grep` with extended regular expressions (-E)
function _bash-it-egrep() {
: "${BASH_IT_GREP:=$(type -P egrep || type -P grep)}"
: "${BASH_IT_GREP:=$(type -P grep)}"
"${BASH_IT_GREP:-/usr/bin/grep}" -E "$@"
}
@@ -150,12 +156,12 @@ function _bash-it-component-list-matching() {
function _bash-it-component-list-enabled() {
local IFS=$'\n' component="$1"
_bash-it-component-help "${component}" | _bash-it-egrep '\[x\]' | awk '{print $1}' | sort -u
_bash-it-component-help "${component}" | _bash-it-fgrep '[x]' | awk '{print $1}' | sort -u
}
function _bash-it-component-list-disabled() {
local IFS=$'\n' component="$1"
_bash-it-component-help "${component}" | _bash-it-egrep -v '\[x\]' | awk '{print $1}' | sort -u
_bash-it-component-help "${component}" | _bash-it-fgrep -v '[x]' | awk '{print $1}' | sort -u
}
# Checks if a given item is enabled for a particular component/file-type.