WIP: bash-it search
parent
b0f0909717
commit
7e417ca6d1
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"cmd": "test/run",
|
||||
"name": "Run All Tests",
|
||||
"args": [ ],
|
||||
"keymap": "ctrl-r",
|
||||
"sh": true,
|
||||
"errorMatch": [
|
||||
"rspec (?<file>[\\/0-9a-zA-Z\\._]+):(?<line>\\d+) #",
|
||||
"# (?<file>\\./.*):(?<line>\\d+)",
|
||||
"\\s+from (?<file>\\./.*):(?<line>\\d+)",
|
||||
"`(require|load)': (?<file>\\./.*):(?<line>\\d+)",
|
||||
"^(<file>/.*):(?<line>\\d+)"
|
||||
]
|
||||
}
|
||||
|
|
@ -9,3 +9,5 @@ lib/custom.bash
|
|||
plugins/custom.plugins.bash
|
||||
*.swp
|
||||
.*.un~
|
||||
bats
|
||||
.idea
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
sudo: false
|
||||
install: git clone --depth 1 https://github.com/sstephenson/bats.git
|
||||
script: PATH="./bats/bin:$PATH" test/run
|
||||
script: test/run
|
||||
language: c
|
||||
|
|
|
|||
|
|
@ -156,23 +156,42 @@ _bash-it_update() {
|
|||
#
|
||||
|
||||
_bash-it-search() {
|
||||
local terms=($@)
|
||||
_about 'searches for a '
|
||||
_param '1: subdirectory'
|
||||
_param '2: preposition'
|
||||
_param '3: file_type'
|
||||
_param '4: column_header'
|
||||
_example '$ _bash-it-describe "plugins" "a" "plugin" "Plugin"'
|
||||
|
||||
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
|
||||
_bash-it-search-category "${type}" "$*"
|
||||
done
|
||||
}
|
||||
|
||||
_bash-it-search-category() {
|
||||
type=$1
|
||||
local func=_bash-it-${type}
|
||||
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' ' '))
|
||||
[[ "${#term_match[@]}" -gt 0 ]] && {
|
||||
matches=(${matches[@]} ${term_match[@]})
|
||||
}
|
||||
done
|
||||
[[ -n "$NO_COLOR" && color_on="" ]] || color_on="\e[3;32m"
|
||||
[[ -n "$NO_COLOR" && color_off="" ]] || color_on="\e[0;0m"
|
||||
|
||||
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')"
|
||||
fi
|
||||
unset matches
|
||||
|
||||
}
|
||||
|
||||
_bash-it-describe ()
|
||||
{
|
||||
_about 'summarizes available bash_it components'
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load ../../lib/composure
|
||||
cite _about _param _example _group _author _version
|
||||
|
||||
load ../../lib/helpers
|
||||
load ../../plugins/available/base.plugin
|
||||
|
||||
export NO_COLOR=true
|
||||
|
||||
@test "helpers search aliases" {
|
||||
run _bash-it-search-category 'plugins' 'base'
|
||||
echo "the lines are: ${output[*]}"
|
||||
[[ "${lines[0]}" =~ 'plugins: base' ]]
|
||||
}
|
||||
Loading…
Reference in New Issue