Add bash-it search functionality
parent
5ec816342f
commit
b0f0909717
|
|
@ -53,7 +53,7 @@ _bash-it-comp()
|
||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
chose_opt="${COMP_WORDS[1]}"
|
chose_opt="${COMP_WORDS[1]}"
|
||||||
file_type="${COMP_WORDS[2]}"
|
file_type="${COMP_WORDS[2]}"
|
||||||
opts="help show enable disable update"
|
opts="help show enable disable update search"
|
||||||
case "${chose_opt}" in
|
case "${chose_opt}" in
|
||||||
show)
|
show)
|
||||||
local show_args="plugins aliases completions"
|
local show_args="plugins aliases completions"
|
||||||
|
|
|
||||||
|
|
@ -32,14 +32,15 @@ function reload_plugins() {
|
||||||
bash-it ()
|
bash-it ()
|
||||||
{
|
{
|
||||||
about 'Bash-it help and maintenance'
|
about 'Bash-it help and maintenance'
|
||||||
param '1: verb [one of: help | show | enable | disable | update ] '
|
param '1: verb [one of: help | show | enable | disable | update | search ] '
|
||||||
param '2: component type [one of: alias(es) | completion(s) | plugin(s) ]'
|
param '2: component type [one of: alias(es) | completion(s) | plugin(s) | - ]'
|
||||||
param '3: specific component [optional]'
|
param '3: specific component [optional]'
|
||||||
example '$ bash-it show plugins'
|
example '$ bash-it show plugins'
|
||||||
example '$ bash-it help aliases'
|
example '$ bash-it help aliases'
|
||||||
example '$ bash-it enable plugin git [tmux]...'
|
example '$ bash-it enable plugin git [tmux]...'
|
||||||
example '$ bash-it disable alias hg [tmux]...'
|
example '$ bash-it disable alias hg [tmux]...'
|
||||||
example '$ bash-it update'
|
example '$ bash-it update'
|
||||||
|
example '$ bash-it search ruby [rake]...'
|
||||||
typeset verb=${1:-}
|
typeset verb=${1:-}
|
||||||
shift
|
shift
|
||||||
typeset component=${1:-}
|
typeset component=${1:-}
|
||||||
|
|
@ -54,6 +55,9 @@ bash-it ()
|
||||||
func=_disable-$component;;
|
func=_disable-$component;;
|
||||||
help)
|
help)
|
||||||
func=_help-$component;;
|
func=_help-$component;;
|
||||||
|
search)
|
||||||
|
_bash-it-search $component $*
|
||||||
|
return;;
|
||||||
update)
|
update)
|
||||||
func=_bash-it_update;;
|
func=_bash-it_update;;
|
||||||
*)
|
*)
|
||||||
|
|
@ -139,6 +143,36 @@ _bash-it_update() {
|
||||||
cd - &> /dev/null
|
cd - &> /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# This function returns list of aliases, plugins and completions in bash-it,
|
||||||
|
# whose name or description matches one of the search terms provided as arguments.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# ❯ bash-it search term1 [term2]...
|
||||||
|
# Example:
|
||||||
|
# ❯ bash-it search ruby rbenv rvm gem rake
|
||||||
|
# aliases: bundler
|
||||||
|
# plugins: chruby chruby-auto rbenv ruby rvm
|
||||||
|
# completions: gem rake
|
||||||
|
#
|
||||||
|
|
||||||
|
_bash-it-search() {
|
||||||
|
local terms=($@)
|
||||||
|
declare -a types=(aliases plugins completions)
|
||||||
|
for type in "${types[@]}" ; do
|
||||||
|
declare -a matches=()
|
||||||
|
for term in "${terms[@]}"; do
|
||||||
|
local term_match=($(bash-it show ${type} | grep -i -- ${term} | cut -d ' ' -f 1 | tr '\n' ' '))
|
||||||
|
[[ "${#term_match[@]}" -gt 0 ]] && {
|
||||||
|
matches=(${matches[@]} ${term_match[@]})
|
||||||
|
}
|
||||||
|
done
|
||||||
|
if [[ "${#matches[*]}" -gt 0 ]] ; then
|
||||||
|
printf "${type}: \e[3;32m%s\e[0;0m\n" "$(echo -n ${matches[*]} | tr ' ' '\n' | sort | uniq | tr '\n' ' ' | sed 's/ $//g')"
|
||||||
|
fi
|
||||||
|
unset matches
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
_bash-it-describe ()
|
_bash-it-describe ()
|
||||||
{
|
{
|
||||||
_about 'summarizes available bash_it components'
|
_about 'summarizes available bash_it components'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue