Skip to content

Commit

Permalink
lib/utilities: List enabled/disabled components faster
Browse files Browse the repository at this point in the history
  • Loading branch information
tsiflimagas authored and gaelicWizard committed Feb 18, 2022
1 parent f2bad2a commit b028ac1
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions lib/utilities.bash
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,47 @@ function _bash-it-clean-component-cache() {

# Returns an array of items within each compoenent.
function _bash-it-component-list() {
local IFS=$'\n' component="$1"
_bash-it-component-help "${component}" | awk '{print $1}' | sort -u
local all component_dir

_bash-it-component-pluralize "$1" pluralized_component
component_dir="${pluralized_component/completions/completion}"
all=("$BASH_IT/$component_dir/available/"*.bash); all=("${all[@]##*/}"); all=("${all[@]%.*.bash}")
builtin printf '%s\n' "${all[@]}"
}

function _bash-it-component-list-matching() {
local component="$1"
shift
local term="$1"
_bash-it-component-help "${component}" | _bash-it-egrep -- "${term}" | awk '{print $1}' | sort -u
_bash-it-component-list "${component}" | _bash-it-egrep -- "${term}"
}

function _bash-it-component-list-enabled() {
local IFS=$'\n' component="$1"
_bash-it-component-help "${component}" | _bash-it-egrep '\[x\]' | awk '{print $1}' | sort -u
local component="${1/alias/aliases}" enabled

_bash-it-component-pluralize "$1" pluralized_component
component_dir="${pluralized_component/completions/completion}"
[[ -d "$BASH_IT/$component_dir/enabled" ]] &&
enabled=($(compgen -G "$BASH_IT/$component_dir/enabled/*.$component.bash")) ||
enabled=($(compgen -G "$BASH_IT/enabled/*.$component.bash"))
enabled=("${enabled[@]##*---}"); enabled=("${enabled[@]##*/}"); enabled=("${enabled[@]%.*.bash}")

builtin printf '%s\n' "${enabled[@]}"
}

function _bash-it-component-list-disabled() {
local IFS=$'\n' component="$1"
_bash-it-component-help "${component}" | _bash-it-egrep -v '\[x\]' | awk '{print $1}' | sort -u
local all component disabled enabled i

_bash-it-component-pluralize "$1" pluralized_component
component="${pluralized_component/completions/completion}"
disabled=($(compgen -G "$BASH_IT/$component/available/*.bash")); disabled=("${disabled[@]##*/}"); disabled=("${disabled[@]%.*.bash}")
enabled=($(_bash-it-component-list-enabled "$1"))

for i in "${enabled[@]}"; do
disabled=("${disabled[@]//"$i"}")
done

builtin printf '%s\n' "${disabled[@]}"
}

# Checks if a given item is enabled for a particular component/file-type.
Expand Down

0 comments on commit b028ac1

Please sign in to comment.