From 1ba023c97a33c2ac87abb46ac75a9afdd585ba5b Mon Sep 17 00:00:00 2001 From: Christophe Aguettaz Date: Fri, 23 Nov 2018 22:25:14 +0100 Subject: [PATCH] [bugfix][wip] Fixed issue with Debian's bash-completion --- bash_it.sh | 10 +++++++++- lib/helpers.bash | 37 +++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/bash_it.sh b/bash_it.sh index e2b00de7..82b7e1b9 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -43,9 +43,17 @@ _load_global_bash_it_files # Load enabled aliases, completion, plugins for file_type in "aliases" "plugins" "completion" do - _load_bash_it_files $file_type + _bash_it_list_bash_it_files_return=() + _list_bash_it_files $file_type + + for config_file in "${_bash_it_list_bash_it_files_return[@]}" ; do + . "$config_file" + done done +unset _bash_it_list_bash_it_files_return +unset _bash_it_config_file + # Load theme, if a theme was set if [[ ! -z "${BASH_IT_THEME}" ]]; then # Load colors and helpers first so they can be used in base theme diff --git a/lib/helpers.bash b/lib/helpers.bash index 565173ed..bb592bab 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -14,16 +14,18 @@ function _command_exists () type "$1" &> /dev/null ; } -# Helper function loading various enable-able files -function _load_bash_it_files() { +# Helper function listing various enable-able files to be sourced +# The files need to be sourced in global scope to preserve scope of 'declare' +function _list_bash_it_files() { subdirectory="$1" if [ -d "${BASH_IT}/${subdirectory}/enabled" ] then FILES="${BASH_IT}/${subdirectory}/enabled/*.bash" - for config_file in $FILES + + for _bash_it_config_file in $FILES do - if [ -e "${config_file}" ]; then - source $config_file + if [ -e "${_bash_it_config_file}" ]; then + _bash_it_list_bash_it_files_return+=("$_bash_it_config_file") fi done fi @@ -43,20 +45,23 @@ function _load_global_bash_it_files() { fi } -# Function for reloading aliases -function reload_aliases() { - _load_bash_it_files "aliases" +function _make_reload_alias() { + printf %s '\ + _bash_it_list_bash_it_files_return=() ;\ + _list_bash_it_files '"$1"' ;\ + for _bash_it_config_file in "${_bash_it_list_bash_it_files_return[@]}"; do \ + . "$_bash_it_config_file" ;\ + done' } -# Function for reloading auto-completion -function reload_completion() { - _load_bash_it_files "completion" -} +# Alias for reloading aliases +alias reload_aliases="$(_make_reload_alias aliases)" -# Function for reloading plugins -function reload_plugins() { - _load_bash_it_files "plugins" -} +# Alias for reloading auto-completion +alias reload_completion="$(_make_reload_alias completion)" + +# Alias for reloading plugins +alias reload_plugins="$(_make_reload_alias plugins)" bash-it () {