From 5b29d3c6e6eade05aae8dc30fefaf4459a324e0d Mon Sep 17 00:00:00 2001 From: Kostas Giapis Date: Mon, 29 Nov 2021 16:55:37 +0200 Subject: [PATCH 1/7] Improve performance of 'bash-it enable' completions --- completion/available/bash-it.completion.bash | 23 ++++++-------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 4fdd72d65e..996ed772b7 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -10,20 +10,11 @@ _bash-it-comp-list-available-not-enabled() { subdirectory="$1" - local available_things + local enabled_components all_things available_things - available_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort -d`; - do - file_entity=$(basename $f) - - typeset enabled_component=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity,$file_entity} 2>/dev/null | head -1) - typeset enabled_component_global=$(command ls "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity 2>/dev/null | head -1) - - if [ -z "$enabled_component" ] && [ -z "$enabled_component_global" ] - then - basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g' - fi - done) + all_things=$(compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sed 's|^.*/||') + enabled_components=$(command ls "${BASH_IT}"/{"$subdirectory"/,}enabled/*.bash 2>/dev/null | sed 's|^.*/||; s/^[0-9]*---//g') + available_things=$(echo "$all_things" | sort -d | grep -Fxv "$enabled_components" | sed 's/\(.*\)\..*\.bash/\1/g') COMPREPLY=( $(compgen -W "all ${available_things}" -- ${cur}) ) } @@ -107,15 +98,15 @@ _bash-it-comp() fi case "${file_type}" in alias) - _bash-it-comp-list-${suffix} aliases + _bash-it-comp-list-"${suffix}" aliases return 0 ;; plugin) - _bash-it-comp-list-${suffix} plugins + _bash-it-comp-list-"${suffix}" plugins return 0 ;; completion) - _bash-it-comp-list-${suffix} completion + _bash-it-comp-list-"${suffix}" completion return 0 ;; *) From 9c4f7773b9a5614fc209fda48751f0d554da4eca Mon Sep 17 00:00:00 2001 From: Kostas Giapis Date: Mon, 29 Nov 2021 17:16:07 +0200 Subject: [PATCH 2/7] Improve performance for the rest of bash-it completions --- completion/available/bash-it.completion.bash | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 996ed772b7..56da384e47 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -24,12 +24,9 @@ _bash-it-comp-list-enabled() local subdirectory="$1" local suffix enabled_things - suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') + suffix="${subdirectory/plugins/plugin}" - enabled_things=$(for f in `sort -d <(compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash") <(compgen -G "${BASH_IT}/enabled/*.${suffix}.bash")`; - do - basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g' | sed -e "s/^[0-9]*---//g" - done) + enabled_things=$(sort -d <(compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash") <(compgen -G "${BASH_IT}/enabled/*.${suffix}.bash") | sed 's|^.*/||; s/\(.*\)\..*\.bash/\1/g; s/^[0-9]*---//g') COMPREPLY=( $(compgen -W "all ${enabled_things}" -- ${cur}) ) } @@ -40,10 +37,7 @@ _bash-it-comp-list-available() local enabled_things - enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort -d`; - do - basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g' - done) + enabled_things=$(sort -d <(compgen -G "${BASH_IT}/$subdirectory/available/*.bash") | sed 's|^.*/||; s/\(.*\)\..*\.bash/\1/g') COMPREPLY=( $(compgen -W "${enabled_things}" -- ${cur}) ) } From 4d821338a36f8ffd056024ff4fbe5f80f043beef Mon Sep 17 00:00:00 2001 From: Kostas Giapis Date: Tue, 30 Nov 2021 18:11:24 +0200 Subject: [PATCH 3/7] Double quote some variables --- completion/available/bash-it.completion.bash | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 56da384e47..9e6fa648bb 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -3,7 +3,7 @@ _bash-it-comp-enable-disable() { local enable_disable_args="alias completion plugin" - COMPREPLY=( $(compgen -W "${enable_disable_args}" -- ${cur}) ) + COMPREPLY=( $(compgen -W "${enable_disable_args}" -- "${cur}") ) } _bash-it-comp-list-available-not-enabled() @@ -16,7 +16,7 @@ _bash-it-comp-list-available-not-enabled() enabled_components=$(command ls "${BASH_IT}"/{"$subdirectory"/,}enabled/*.bash 2>/dev/null | sed 's|^.*/||; s/^[0-9]*---//g') available_things=$(echo "$all_things" | sort -d | grep -Fxv "$enabled_components" | sed 's/\(.*\)\..*\.bash/\1/g') - COMPREPLY=( $(compgen -W "all ${available_things}" -- ${cur}) ) + COMPREPLY=( $(compgen -W "all ${available_things}" -- "${cur}") ) } _bash-it-comp-list-enabled() @@ -28,7 +28,7 @@ _bash-it-comp-list-enabled() enabled_things=$(sort -d <(compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash") <(compgen -G "${BASH_IT}/enabled/*.${suffix}.bash") | sed 's|^.*/||; s/\(.*\)\..*\.bash/\1/g; s/^[0-9]*---//g') - COMPREPLY=( $(compgen -W "all ${enabled_things}" -- ${cur}) ) + COMPREPLY=( $(compgen -W "all ${enabled_things}" -- "${cur}") ) } _bash-it-comp-list-available() @@ -39,7 +39,7 @@ _bash-it-comp-list-available() enabled_things=$(sort -d <(compgen -G "${BASH_IT}/$subdirectory/available/*.bash") | sed 's|^.*/||; s/\(.*\)\..*\.bash/\1/g') - COMPREPLY=( $(compgen -W "${enabled_things}" -- ${cur}) ) + COMPREPLY=( $(compgen -W "${enabled_things}" -- "${cur}") ) } _bash-it-comp() @@ -54,7 +54,7 @@ _bash-it-comp() case "${chose_opt}" in show) local show_args="aliases completions plugins" - COMPREPLY=( $(compgen -W "${show_args}" -- ${cur}) ) + COMPREPLY=( $(compgen -W "${show_args}" -- "${cur}") ) return 0 ;; help) @@ -63,22 +63,22 @@ _bash-it-comp() return 0 else local help_args="aliases completions migrate plugins update" - COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) ) + COMPREPLY=( $(compgen -W "${help_args}" -- "${cur}") ) return 0 fi ;; doctor) local doctor_args="errors warnings all" - COMPREPLY=( $(compgen -W "${doctor_args}" -- ${cur}) ) + COMPREPLY=( $(compgen -W "${doctor_args}" -- "${cur}") ) return 0 ;; update) - if [[ ${cur} == -* ]];then + if [[ "${cur}" == -* ]];then local update_args="-s --silent" else local update_args="stable dev" fi - COMPREPLY=( $(compgen -W "${update_args}" -- ${cur}) ) + COMPREPLY=( $(compgen -W "${update_args}" -- "${cur}") ) return 0 ;; migrate | reload | search | version) @@ -111,7 +111,7 @@ _bash-it-comp() ;; esac - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 } From 15fe122c1f4636742d6f4ab2328b451247562ac3 Mon Sep 17 00:00:00 2001 From: Kostas Giapis Date: Tue, 30 Nov 2021 20:13:10 +0200 Subject: [PATCH 4/7] Make more variables local --- completion/available/bash-it.completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 9e6fa648bb..4bf9a8b066 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -8,7 +8,7 @@ _bash-it-comp-enable-disable() _bash-it-comp-list-available-not-enabled() { - subdirectory="$1" + local subdirectory="$1" local enabled_components all_things available_things @@ -33,7 +33,7 @@ _bash-it-comp-list-enabled() _bash-it-comp-list-available() { - subdirectory="$1" + local subdirectory="$1" local enabled_things From 476159eab93ce6b9eb53c62bc190f13c36eedf9c Mon Sep 17 00:00:00 2001 From: Kostas Giapis Date: Fri, 10 Dec 2021 04:46:19 +0200 Subject: [PATCH 5/7] Use bash features as much as possible --- completion/available/bash-it.completion.bash | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 4bf9a8b066..95b31b43bb 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -12,9 +12,14 @@ _bash-it-comp-list-available-not-enabled() local enabled_components all_things available_things - all_things=$(compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sed 's|^.*/||') - enabled_components=$(command ls "${BASH_IT}"/{"$subdirectory"/,}enabled/*.bash 2>/dev/null | sed 's|^.*/||; s/^[0-9]*---//g') - available_things=$(echo "$all_things" | sort -d | grep -Fxv "$enabled_components" | sed 's/\(.*\)\..*\.bash/\1/g') + all_things=( $(compgen -G "${BASH_IT}/$subdirectory/available/*.bash") ); all_things=( "${all_things[@]##*/}" ) + enabled_components=( $(command ls "${BASH_IT}"/{"$subdirectory"/,}enabled/*.bash 2>/dev/null) ) + enabled_components=( "${enabled_components[@]##*/}" ); enabled_components="${enabled_components[@]#*---}" + available_things=( $(sort -d <(for i in ${enabled_components} + do + all_things=( "${all_things[@]//$i}" ) + done + printf '%s\n' "${all_things[@]}")) ); available_things="${available_things[@]%.*.bash}" COMPREPLY=( $(compgen -W "all ${available_things}" -- "${cur}") ) } @@ -26,7 +31,8 @@ _bash-it-comp-list-enabled() suffix="${subdirectory/plugins/plugin}" - enabled_things=$(sort -d <(compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash") <(compgen -G "${BASH_IT}/enabled/*.${suffix}.bash") | sed 's|^.*/||; s/\(.*\)\..*\.bash/\1/g; s/^[0-9]*---//g') + enabled_things=( $(sort -d <(compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash") <(compgen -G "${BASH_IT}/enabled/*.${suffix}.bash")) ) + enabled_things=( "${enabled_things[@]##*/}" ); enabled_things=( "${enabled_things[@]#*---}" ); enabled_things="${enabled_things[@]%.*.bash}" COMPREPLY=( $(compgen -W "all ${enabled_things}" -- "${cur}") ) } @@ -37,7 +43,8 @@ _bash-it-comp-list-available() local enabled_things - enabled_things=$(sort -d <(compgen -G "${BASH_IT}/$subdirectory/available/*.bash") | sed 's|^.*/||; s/\(.*\)\..*\.bash/\1/g') + enabled_things=( $(sort -d <(compgen -G "${BASH_IT}/$subdirectory/available/*.bash")) ) + enabled_things=( "${enabled_things[@]##*/}" ); enabled_things="${enabled_things[@]%.*.bash}" COMPREPLY=( $(compgen -W "${enabled_things}" -- "${cur}") ) } From 2a2cc72541ccbce4b9ff39aca8e77fd4c49461de Mon Sep 17 00:00:00 2001 From: Kostas Giapis Date: Thu, 30 Dec 2021 17:01:22 +0200 Subject: [PATCH 6/7] Make parameter truncation greedy --- completion/available/bash-it.completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 95b31b43bb..5a15de0b7a 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -14,7 +14,7 @@ _bash-it-comp-list-available-not-enabled() all_things=( $(compgen -G "${BASH_IT}/$subdirectory/available/*.bash") ); all_things=( "${all_things[@]##*/}" ) enabled_components=( $(command ls "${BASH_IT}"/{"$subdirectory"/,}enabled/*.bash 2>/dev/null) ) - enabled_components=( "${enabled_components[@]##*/}" ); enabled_components="${enabled_components[@]#*---}" + enabled_components=( "${enabled_components[@]##*/}" ); enabled_components="${enabled_components[@]##*---}" available_things=( $(sort -d <(for i in ${enabled_components} do all_things=( "${all_things[@]//$i}" ) @@ -32,7 +32,7 @@ _bash-it-comp-list-enabled() suffix="${subdirectory/plugins/plugin}" enabled_things=( $(sort -d <(compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash") <(compgen -G "${BASH_IT}/enabled/*.${suffix}.bash")) ) - enabled_things=( "${enabled_things[@]##*/}" ); enabled_things=( "${enabled_things[@]#*---}" ); enabled_things="${enabled_things[@]%.*.bash}" + enabled_things=( "${enabled_things[@]##*/}" ); enabled_things=( "${enabled_things[@]##*---}" ); enabled_things="${enabled_things[@]%.*.bash}" COMPREPLY=( $(compgen -W "all ${enabled_things}" -- "${cur}") ) } From 45e8c4e3cdf60cedca1366bf20ddfd3a0f9a4d1b Mon Sep 17 00:00:00 2001 From: Kostas Giapis Date: Thu, 30 Dec 2021 17:02:51 +0200 Subject: [PATCH 7/7] Handle `restart` completions --- completion/available/bash-it.completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 5a15de0b7a..42ab44c851 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -88,7 +88,7 @@ _bash-it-comp() COMPREPLY=( $(compgen -W "${update_args}" -- "${cur}") ) return 0 ;; - migrate | reload | search | version) + migrate | reload | restart | search | version) return 0 ;; enable | disable)