Updating var names for consistency, adding cites

pull/681/head
Konstantin Gredeskoul 2016-03-21 00:05:43 -07:00
parent 7e417ca6d1
commit 7715cc9b6a
2 changed files with 21 additions and 18 deletions

View File

@ -156,22 +156,26 @@ _bash-it_update() {
# #
_bash-it-search() { _bash-it-search() {
_about 'searches for a ' _about 'searches for given terms amongst bash-it plugins, aliases and completions'
_param '1: subdirectory' _param '1: term1'
_param '2: preposition' _param '2: [ term2 ]...'
_param '3: file_type' _example '$ _bash-it-search ruby rvm rake bundler'
_param '4: column_header'
_example '$ _bash-it-describe "plugins" "a" "plugin" "Plugin"'
declare -a types=(aliases plugins completions) declare -a _components=(aliases plugins completions)
for type in "${types[@]}" ; do for _component in "${_components[@]}" ; do
_bash-it-search-category "${type}" "$*" _bash-it-search-component "${_component}" "$*"
done done
} }
_bash-it-search-category() { _bash-it-search-component() {
type=$1 _about 'searches for given terms amongst a given component'
local func=_bash-it-${type} _param '1: component type, one of: [ aliases | plugins | completions ]'
_param '2: term1'
_param '3: [ term2 ]...'
_example '$ _bash-it-search-component aliases rake bundler'
_component=$1
local func=_bash-it-${_component}
shift shift
declare -a terms=($@) declare -a terms=($@)
declare -a matches=() declare -a matches=()
@ -182,14 +186,13 @@ _bash-it-search-category() {
matches=(${matches[@]} ${term_match[@]}) matches=(${matches[@]} ${term_match[@]})
} }
done done
[[ -n "$NO_COLOR" && color_on="" ]] || color_on="\e[3;32m" [[ -n "$NO_COLOR" && color_on="" ]] || color_on="\e[1;32m"
[[ -n "$NO_COLOR" && color_off="" ]] || color_on="\e[0;0m" [[ -n "$NO_COLOR" && color_off="" ]] || color_off="\e[0;0m"
if [[ "${#matches[*]}" -gt 0 ]] ; then if [[ "${#matches[*]}" -gt 0 ]] ; then
printf "%15s: ${color_on}%s${color_off}\n" "${type}" "$(echo -n ${matches[*]} | tr ' ' '\n' | sort | uniq | tr '\n' ' ' | sed 's/ $//g')" printf "%15s: ${color_on}%s${color_off}\n" "${_component}" "$(echo -n ${matches[*]} | tr ' ' '\n' | sort | uniq | tr '\n' ' ' | sed 's/ $//g')"
fi fi
unset matches unset matches
} }
_bash-it-describe () _bash-it-describe ()

View File

@ -6,10 +6,10 @@ cite _about _param _example _group _author _version
load ../../lib/helpers load ../../lib/helpers
load ../../plugins/available/base.plugin load ../../plugins/available/base.plugin
export NO_COLOR=true NO_COLOR=true
@test "helpers search aliases" { @test "helpers search aliases" {
run _bash-it-search-category 'plugins' 'base' run _bash-it-search-component 'plugins' 'base'
echo "the lines are: ${output[*]}" echo "the lines are: ${output[*]}"
[[ "${lines[0]}" =~ 'plugins: base' ]] [[ "${lines[0]}" =~ 'plugins: base' ]]
} }