From fd3d305fad1d8d8e347704275f67aecd2ec1f621 Mon Sep 17 00:00:00 2001 From: Konstantin Gredeskoul Date: Thu, 24 Mar 2016 02:54:30 -0700 Subject: [PATCH] Faster search, and cleaner completion --- completion/available/bash-it.completion.bash | 2 +- lib/helpers.bash | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 3cd8e84e..f4326a0a 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -65,7 +65,7 @@ _bash-it-comp() COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) ) return 0 ;; - update) + update | search) return 0 ;; enable | disable) diff --git a/lib/helpers.bash b/lib/helpers.bash index 84915b9f..6473d471 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -176,12 +176,14 @@ _bash-it-search-component() { _component=$1 local func=_bash-it-${_component} + local help=$($func) + shift declare -a terms=($@) declare -a matches=() local _grep=$(which egrep || which grep) for term in "${terms[@]}"; do - local term_match=($($func | ${_grep} -i -- ${term} | cut -d ' ' -f 1 | tr '\n' ' ')) + local term_match=($(echo "${help}"| ${_grep} -i -- ${term} | cut -d ' ' -f 1 | tr '\n' ' ')) [[ "${#term_match[@]}" -gt 0 ]] && { matches=(${matches[@]} ${term_match[@]}) }