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 itpull/1879/head^2
parent
bf2034d13d
commit
00062bfcb6
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env bash
|
# shellcheck shell=bash
|
||||||
#
|
#
|
||||||
# Bash completion support for Fabric (http://fabfile.org/)
|
# Bash completion support for Fabric (http://fabfile.org/)
|
||||||
#
|
#
|
||||||
|
|
@ -91,7 +91,7 @@ function __fab_completion() {
|
||||||
-*)
|
-*)
|
||||||
if [[ -z "${__FAB_COMPLETION_LONG_OPT}" ]]; then
|
if [[ -z "${__FAB_COMPLETION_LONG_OPT}" ]]; then
|
||||||
export __FAB_COMPLETION_LONG_OPT=$(
|
export __FAB_COMPLETION_LONG_OPT=$(
|
||||||
fab --help | egrep -o "\-\-[A-Za-z_\-]+\=?" | sort -u)
|
fab --help | grep -E -o "\-\-[A-Za-z_\-]+\=?" | sort -u)
|
||||||
fi
|
fi
|
||||||
opts="${__FAB_COMPLETION_LONG_OPT}"
|
opts="${__FAB_COMPLETION_LONG_OPT}"
|
||||||
;;
|
;;
|
||||||
|
|
@ -101,7 +101,7 @@ function __fab_completion() {
|
||||||
# -*)
|
# -*)
|
||||||
# if [[ -z "${__FAB_COMPLETION_SHORT_OPT}" ]]; then
|
# if [[ -z "${__FAB_COMPLETION_SHORT_OPT}" ]]; then
|
||||||
# export __FAB_COMPLETION_SHORT_OPT=$(
|
# export __FAB_COMPLETION_SHORT_OPT=$(
|
||||||
# fab --help | egrep -o "^ +\-[A-Za-z_\]" | sort -u)
|
# fab --help | grep -E -o "^ +\-[A-Za-z_\]" | sort -u)
|
||||||
# fi
|
# fi
|
||||||
# opts="${__FAB_COMPLETION_SHORT_OPT}"
|
# opts="${__FAB_COMPLETION_SHORT_OPT}"
|
||||||
# ;;
|
# ;;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# shellcheck shell=bash
|
||||||
|
|
||||||
# Copyright (c) 2017 Eric Wendelin
|
# Copyright (c) 2017 Eric Wendelin
|
||||||
|
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
|
@ -66,7 +68,7 @@ __gradle-generate-script-cache() {
|
||||||
|
|
||||||
if [[ ! $(find $cache_dir/$cache_name -mmin -$cache_ttl_mins 2>/dev/null) ]]; then
|
if [[ ! $(find $cache_dir/$cache_name -mmin -$cache_ttl_mins 2>/dev/null) ]]; then
|
||||||
# Cache all Gradle scripts
|
# Cache all Gradle scripts
|
||||||
local gradle_build_scripts=$(find $project_root_dir -type f -name "*.gradle" -o -name "*.gradle.kts" 2>/dev/null | egrep -v "$script_exclude_pattern")
|
local gradle_build_scripts=$(find $project_root_dir -type f -name "*.gradle" -o -name "*.gradle.kts" 2>/dev/null | grep -E -v "$script_exclude_pattern")
|
||||||
printf "%s\n" "${gradle_build_scripts[@]}" > $cache_dir/$cache_name
|
printf "%s\n" "${gradle_build_scripts[@]}" > $cache_dir/$cache_name
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# shellcheck shell=bash
|
||||||
|
|
||||||
# Bash completion for Makefile
|
# Bash completion for Makefile
|
||||||
# Loosely adapted from http://stackoverflow.com/a/38415982/1472048
|
# Loosely adapted from http://stackoverflow.com/a/38415982/1472048
|
||||||
|
|
||||||
|
|
@ -17,7 +19,7 @@ _makecomplete() {
|
||||||
for f in "${files[@]}" ; do
|
for f in "${files[@]}" ; do
|
||||||
while IFS='' read -r line ; do
|
while IFS='' read -r line ; do
|
||||||
targets+=("$line")
|
targets+=("$line")
|
||||||
done < <(grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' "$f" | cut -d':' -f1)
|
done < <(grep -E -o '^[a-zA-Z0-9_-]+:([^=]|$)' "$f" | cut -d':' -f1)
|
||||||
done
|
done
|
||||||
|
|
||||||
[ "${#targets[@]}" -eq 0 ] && return 0
|
[ "${#targets[@]}" -eq 0 ] && return 0
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,7 @@ function _is_function() {
|
||||||
_example '$ _is_function ls && echo exists'
|
_example '$ _is_function ls && echo exists'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
local msg="${2:-Function '$1' does not exist}"
|
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
|
return 0
|
||||||
else
|
else
|
||||||
_log_debug "$msg"
|
_log_debug "$msg"
|
||||||
|
|
|
||||||
|
|
@ -60,15 +60,21 @@ function _bash-it-array-dedup() {
|
||||||
printf '%s\n' "$@" | sort -u
|
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() {
|
function _bash-it-grep() {
|
||||||
: "${BASH_IT_GREP:=$(type -P egrep || type -P grep)}"
|
: "${BASH_IT_GREP:=$(type -P grep)}"
|
||||||
printf "%s" "${BASH_IT_GREP:-/usr/bin/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() {
|
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 "$@"
|
"${BASH_IT_GREP:-/usr/bin/grep}" -E "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,12 +156,12 @@ function _bash-it-component-list-matching() {
|
||||||
|
|
||||||
function _bash-it-component-list-enabled() {
|
function _bash-it-component-list-enabled() {
|
||||||
local IFS=$'\n' component="$1"
|
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() {
|
function _bash-it-component-list-disabled() {
|
||||||
local IFS=$'\n' component="$1"
|
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.
|
# Checks if a given item is enabled for a particular component/file-type.
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
# shellcheck disable=SC2002 # Prefer 'cat' for cleaner script
|
# shellcheck disable=SC2002 # Prefer 'cat' for cleaner script
|
||||||
mapfile -t FILES < <(
|
mapfile -t FILES < <(
|
||||||
cat clean_files.txt \
|
cat clean_files.txt \
|
||||||
| grep -v -E '^\s*$' \
|
| grep -E -v '^\s*$' \
|
||||||
| grep -v -E '^\s*#' \
|
| grep -E -v '^\s*#' \
|
||||||
| xargs -n1 -I{} find "{}" -type f
|
| xargs -n1 -I{} find "{}" -type f
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
# shellcheck shell=bash
|
||||||
cite about-plugin
|
cite about-plugin
|
||||||
about-plugin 'AWS helper functions'
|
about-plugin 'AWS helper functions'
|
||||||
|
|
||||||
|
|
@ -40,13 +41,13 @@ function __awskeys_help {
|
||||||
function __awskeys_get {
|
function __awskeys_get {
|
||||||
local ln=$(grep -n "\[ *$1 *\]" "${AWS_SHARED_CREDENTIALS_FILE}" | cut -d ":" -f 1)
|
local ln=$(grep -n "\[ *$1 *\]" "${AWS_SHARED_CREDENTIALS_FILE}" | cut -d ":" -f 1)
|
||||||
if [[ -n "${ln}" ]]; then
|
if [[ -n "${ln}" ]]; then
|
||||||
tail -n +${ln} "${AWS_SHARED_CREDENTIALS_FILE}" | egrep -m 2 "aws_access_key_id|aws_secret_access_key"
|
tail -n +${ln} "${AWS_SHARED_CREDENTIALS_FILE}" | grep -F -m 2 -e "aws_access_key_id" -e "aws_secret_access_key"
|
||||||
tail -n +${ln} "${AWS_SHARED_CREDENTIALS_FILE}" | egrep -m 1 "aws_session_token"
|
tail -n +${ln} "${AWS_SHARED_CREDENTIALS_FILE}" | grep -F -m 1 "aws_session_token"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function __awskeys_list {
|
function __awskeys_list {
|
||||||
local credentials_list="$((egrep '^\[ *[a-zA-Z0-9_-]+ *\]$' "${AWS_SHARED_CREDENTIALS_FILE}"; grep "\[profile" "${AWS_CONFIG_FILE}" | sed "s|\[profile |\[|g") | sort | uniq)"
|
local credentials_list="$((grep -E '^\[ *[a-zA-Z0-9_-]+ *\]$' "${AWS_SHARED_CREDENTIALS_FILE}"; grep "\[profile" "${AWS_CONFIG_FILE}" | sed "s|\[profile |\[|g") | sort | uniq)"
|
||||||
if [[ -n $"{credentials_list}" ]]; then
|
if [[ -n $"{credentials_list}" ]]; then
|
||||||
echo -e "Available credentials profiles:\n"
|
echo -e "Available credentials profiles:\n"
|
||||||
for profile in ${credentials_list}; do
|
for profile in ${credentials_list}; do
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@ function editpost() {
|
||||||
pushd "${SITE}/_posts" > /dev/null || return
|
pushd "${SITE}/_posts" > /dev/null || return
|
||||||
|
|
||||||
for POST in *; do
|
for POST in *; do
|
||||||
DATE="$(echo "${POST}" | grep -oE "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}")"
|
DATE="$(echo "${POST}" | grep -E -o "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}")"
|
||||||
TITLE="$(grep -oE "title: (.+)" < "${POST}")"
|
TITLE="$(grep -E -o "title: (.+)" < "${POST}")"
|
||||||
TITLE="${TITLE/title: /}"
|
TITLE="${TITLE/title: /}"
|
||||||
echo "${COUNTER}) ${DATE} ${TITLE}"
|
echo "${COUNTER}) ${DATE} ${TITLE}"
|
||||||
POSTS[COUNTER]="$POST"
|
POSTS[COUNTER]="$POST"
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
# shellcheck shell=bash
|
||||||
cite about-plugin
|
cite about-plugin
|
||||||
about-plugin 'postgres helper functions'
|
about-plugin 'postgres helper functions'
|
||||||
|
|
||||||
|
|
@ -50,7 +51,7 @@ function postgres_status {
|
||||||
|
|
||||||
|
|
||||||
function is_postgres_running {
|
function is_postgres_running {
|
||||||
$POSTGRES_BIN/pg_ctl -D $PGDATA status | egrep -o "no server running"
|
$POSTGRES_BIN/pg_ctl -D $PGDATA status | grep -F -o "no server running"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# shellcheck shell=bash
|
||||||
|
|
||||||
# port of zork theme
|
# port of zork theme
|
||||||
|
|
||||||
# set colors for use throughout the prompt
|
# set colors for use throughout the prompt
|
||||||
|
|
@ -50,7 +52,7 @@ function is_integer() { # helper function for todo-txt-count
|
||||||
|
|
||||||
todo_txt_count() {
|
todo_txt_count() {
|
||||||
if `hash todo.sh 2>&-`; then # is todo.sh installed
|
if `hash todo.sh 2>&-`; then # is todo.sh installed
|
||||||
count=`todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }'`
|
count=`todo.sh ls | grep -E "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }'`
|
||||||
if is_integer $count; then # did we get a sane answer back
|
if is_integer $count; then # did we get a sane answer back
|
||||||
echo "${BRACKET_COLOR}[${STRING_COLOR}T:$count${BRACKET_COLOR}]$normal"
|
echo "${BRACKET_COLOR}[${STRING_COLOR}T:$count${BRACKET_COLOR}]$normal"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue