diff --git a/.atom-build.json b/.atom-build.json new file mode 100644 index 00000000..dea01eda --- /dev/null +++ b/.atom-build.json @@ -0,0 +1,14 @@ +{ + "cmd": "test/run", + "name": "Run All Tests", + "args": [ ], + "keymap": "ctrl-r", + "sh": true, + "errorMatch": [ + "rspec (?[\\/0-9a-zA-Z\\._]+):(?\\d+) #", + "# (?\\./.*):(?\\d+)", + "\\s+from (?\\./.*):(?\\d+)", + "`(require|load)': (?\\./.*):(?\\d+)", + "^(/.*):(?\\d+)" + ] +} diff --git a/.editorconfig b/.editorconfig old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index dc868103..f12b3cf1 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ lib/custom.bash plugins/custom.plugins.bash *.swp .*.un~ +bats +.idea diff --git a/.travis.yml b/.travis.yml index a1745beb..34c38fe7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/lib/helpers.bash b/lib/helpers.bash old mode 100644 new mode 100755 index b5f15c8c..4a2f3906 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -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' diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats new file mode 100644 index 00000000..c601d692 --- /dev/null +++ b/test/lib/helpers.bats @@ -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' ]] +} diff --git a/test/run b/test/run index 1fb11518..2efc35d0 100755 --- a/test/run +++ b/test/run @@ -1,4 +1,6 @@ #!/usr/bin/env bash +PATH=$PATH:$(pwd)/bats/bin +set +e +[[ -z "$(which bats)" ]] && git clone --depth 1 https://github.com/sstephenson/bats.git set -e - exec bats ${CI:+--tap} test/{lib,plugins}