lib/search: `shfmt`

My apologies to future `git blame` hunters ♥
pull/1932/head
John D Pell 2022-01-26 10:24:51 -08:00
parent 8939e943c5
commit b8694ee140
2 changed files with 189 additions and 191 deletions

View File

@ -83,6 +83,7 @@ completion/available/wpscan.completion.bash
lib/helpers.bash
lib/log.bash
lib/preexec.bash
lib/search.bash
lib/utilities.bash
# plugins

View File

@ -47,7 +47,7 @@
# completions: git
#
_bash-it-search() {
function _bash-it-search() {
_about 'searches for given terms amongst bash-it plugins, aliases and completions'
_param '1: term1'
_param '2: [ term2 ]...'
@ -90,7 +90,7 @@ _bash-it-search() {
return 0
}
_bash-it-search-help() {
function _bash-it-search-help() {
printf '%b' "${echo_normal-}
${echo_underline_yellow-}USAGE${echo_normal-}
@ -167,14 +167,15 @@ ${echo_underline_yellow-}SUMMARY${echo_normal-}
"
}
_bash-it-is-partial-match() {
function _bash-it-is-partial-match() {
local component="${1?}"
local term="${2?}"
_bash-it-component-help "${component}" | "_bash-it-egrep -i -q -- "${term}"
_bash-it-component-help "${component}" | _bash-it-egrep -i -q -- "${term}"
}
_bash-it-component-term-matches-negation() {
local match="$1"; shift
function _bash-it-component-term-matches-negation() {
local match="$1"
shift
local negative
for negative in "$@"; do
[[ "${match}" =~ ${negative} ]] && return 0
@ -183,7 +184,7 @@ _bash-it-component-term-matches-negation() {
return 1
}
_bash-it-search-component() {
function _bash-it-search-component() {
_about 'searches for given terms amongst a given component'
_param '1: component type, one of: [ aliases | plugins | completions ]'
_param '2: term1 term2 @term3'
@ -195,11 +196,10 @@ _bash-it-search-component() {
# if one of the search terms is --enable or --disable, we will apply
# this action to the matches further ` down.
local component_singular action action_func
local component_singular= action= action_func=
local -a search_commands=('enable' 'disable')
for search_command in "${search_commands[@]}"; do
if _bash-it-array-contains-element "--${search_command}" "$@"
then
if _bash-it-array-contains-element "--${search_command}" "$@"; then
component_singular="${component/es/}" # aliases -> alias
component_singular="${component_singular/ns/n}" # plugins -> plugin
@ -218,8 +218,7 @@ _bash-it-search-component() {
local term line
local -a component_list=()
while IFS='' read -r line
do
while IFS='' read -r line; do
component_list+=("$line")
done < <(_bash-it-component-list "${component}")
@ -230,13 +229,11 @@ _bash-it-search-component() {
elif [[ "${term:0:1}" == "-" ]]; then
negative_terms+=("${search_term}")
elif [[ "${term:0:1}" == "@" ]]; then
if _bash-it-array-contains-element "${search_term}" "${component_list[@]:-}"
then
if _bash-it-array-contains-element "${search_term}" "${component_list[@]:-}"; then
exact_terms+=("${search_term}")
fi
else
while IFS='' read -r line
do
while IFS='' read -r line; do
partial_terms+=("$line")
done < <(_bash-it-component-list-matching "${component}" "${term}")
@ -244,8 +241,7 @@ _bash-it-search-component() {
done
local -a total_matches=()
while IFS='' read -r line
do
while IFS='' read -r line; do
total_matches+=("$line")
done < <(_bash-it-array-dedup "${exact_terms[@]:-}" "${partial_terms[@]:-}")
@ -261,18 +257,20 @@ _bash-it-search-component() {
_bash-it-search-result "${component}" "${action}" "${action_func}" "${matches[@]:-}"
}
_bash-it-search-result() {
local component="$1"; shift
local action="$1"; shift
local action_func="$1"; shift
function _bash-it-search-result() {
local component="$1"
shift
local action="$1"
shift
local action_func="$1"
shift
local -a matches=("$@")
local color_component color_enable color_disable color_off
color_sep=':'
if ${BASH_IT_SEARCH_USE_COLOR}
then
if ${BASH_IT_SEARCH_USE_COLOR}; then
color_component='\e[1;34m'
color_enable='\e[1;32m'
suffix_enable=''
@ -341,26 +339,25 @@ _bash-it-search-result() {
fi
}
_bash-it-rewind() {
function _bash-it-rewind() {
local -i len="$1"
printf '%b' "\033[${len}D"
}
_bash-it-flash-term() {
function _bash-it-flash-term() {
local -i len="${1:-0}"
local match="${2:-}"
local delay=0.1
local color
for color in "${echo_black-}" "${echo_bold_blue-}" "${echo_bold_yellow-}" "${echo_bold_red-}" "${echo_bold_green-}" "${echo_normal-}"
do
for color in "${echo_black-}" "${echo_bold_blue-}" "${echo_bold_yellow-}" "${echo_bold_red-}" "${echo_bold_green-}" "${echo_normal-}"; do
sleep "${delay}"
_bash-it-rewind "${len}"
printf '%b' "${color}${match}"
done
}
_bash-it-erase-term() {
function _bash-it-erase-term() {
local -i len="${1:-0}"
_bash-it-rewind "${len}"
for a in {0..30}; do