Merge pull request #1283 from Bash-it/bugfix/bash_completion_debian

Bugfix - issue with sourced files (noted by @caguettaz)
pull/1285/head
Travis Swicegood 2018-12-05 22:07:07 -06:00 committed by GitHub
commit 1dadfc92ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 48 deletions

View File

@ -29,21 +29,24 @@ cite _about _param _example _group _author _version
# libraries, but skip appearance (themes) for now # libraries, but skip appearance (themes) for now
LIB="${BASH_IT}/lib/*.bash" LIB="${BASH_IT}/lib/*.bash"
APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash" APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash"
for config_file in $LIB for _bash_it_config_file in $LIB
do do
if [ "$config_file" != "$APPEARANCE_LIB" ]; then if [ "$_bash_it_config_file" != "$APPEARANCE_LIB" ]; then
# shellcheck disable=SC1090 # shellcheck disable=SC1090
source "$config_file" source "$_bash_it_config_file"
fi fi
done done
# Load the global "enabled" directory # Load the global "enabled" directory
_load_global_bash_it_files # "family" param is empty so that files get sources in glob order
# shellcheck source=./scripts/reloader.bash
source "${BASH_IT}/scripts/reloader.bash"
# Load enabled aliases, completion, plugins # Load enabled aliases, completion, plugins
for file_type in "aliases" "plugins" "completion" for file_type in "aliases" "plugins" "completion"
do do
_load_bash_it_files $file_type # shellcheck source=./scripts/reloader.bash
source "${BASH_IT}/scripts/reloader.bash" "skip" "$file_type"
done done
# Load theme, if a theme was set # Load theme, if a theme was set
@ -75,15 +78,15 @@ done
# Custom # Custom
CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash" CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash"
for config_file in $CUSTOM for _bash_it_config_file in $CUSTOM
do do
if [ -e "${config_file}" ]; then if [ -e "${_bash_it_config_file}" ]; then
# shellcheck disable=SC1090 # shellcheck disable=SC1090
source "$config_file" source "$_bash_it_config_file"
fi fi
done done
unset config_file unset _bash_it_config_file
if [[ $PROMPT ]]; then if [[ $PROMPT ]]; then
export PS1="\[""$PROMPT""\]" export PS1="\[""$PROMPT""\]"
fi fi

View File

@ -14,49 +14,21 @@ function _command_exists ()
type "$1" &> /dev/null ; type "$1" &> /dev/null ;
} }
# Helper function loading various enable-able files function _make_reload_alias() {
function _load_bash_it_files() { echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}"
subdirectory="$1"
if [ -d "${BASH_IT}/${subdirectory}/enabled" ]
then
FILES="${BASH_IT}/${subdirectory}/enabled/*.bash"
for config_file in $FILES
do
if [ -e "${config_file}" ]; then
source $config_file
fi
done
fi
} }
function _load_global_bash_it_files() { # Alias for reloading aliases
# In the new structure # shellcheck disable=SC2139
if [ -d "${BASH_IT}/enabled" ] alias reload_aliases="$(_make_reload_alias alias aliases)"
then
FILES="${BASH_IT}/enabled/*.bash"
for config_file in $FILES
do
if [ -e "${config_file}" ]; then
source $config_file
fi
done
fi
}
# Function for reloading aliases # Alias for reloading auto-completion
function reload_aliases() { # shellcheck disable=SC2139
_load_bash_it_files "aliases" alias reload_completion="$(_make_reload_alias completion completion)"
}
# Function for reloading auto-completion # Alias for reloading plugins
function reload_completion() { # shellcheck disable=SC2139
_load_bash_it_files "completion" alias reload_plugins="$(_make_reload_alias plugin plugins)"
}
# Function for reloading plugins
function reload_plugins() {
_load_bash_it_files "plugins"
}
bash-it () bash-it ()
{ {

View File

@ -0,0 +1,36 @@
#!/bin/bash
pushd "${BASH_IT}" >/dev/null || exit 1
# TODO: Add debugging output
if [ "$1" != "skip" ] && [ -d "./enabled" ]; then
_bash_it_config_type=""
if [[ "${1}" =~ ^(alias|completion|plugin)$ ]]; then
_bash_it_config_type=$1
fi
for _bash_it_config_file in $(sort <(compgen -G "./enabled/*${_bash_it_config_type}.bash")); do
if [ -e "${_bash_it_config_file}" ]; then
# shellcheck source=/dev/null
source $_bash_it_config_file
else
echo "Unable to read ${_bash_it_config_file}" > /dev/stderr
fi
done
fi
if [ ! -z "${2}" ] && [[ "${2}" =~ ^(aliases|completion|plugins)$ ]] && [ -d "${2}/enabled" ]; then
# TODO: We should warn users they're using legacy enabling
for _bash_it_config_file in $(sort <(compgen -G "./${2}/enabled/*.bash")); do
if [ -e "$_bash_it_config_file" ]; then
# shellcheck source=/dev/null
source "$_bash_it_config_file"
else
echo "Unable to locate ${_bash_it_config_file}" > /dev/stderr
fi
done
fi
unset _bash_it_config_file
unset _bash_it_config_type
popd >/dev/null || exit 1