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
LIB="${BASH_IT}/lib/*.bash"
APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash"
for config_file in $LIB
for _bash_it_config_file in $LIB
do
if [ "$config_file" != "$APPEARANCE_LIB" ]; then
if [ "$_bash_it_config_file" != "$APPEARANCE_LIB" ]; then
# shellcheck disable=SC1090
source "$config_file"
source "$_bash_it_config_file"
fi
done
# 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
for file_type in "aliases" "plugins" "completion"
do
_load_bash_it_files $file_type
# shellcheck source=./scripts/reloader.bash
source "${BASH_IT}/scripts/reloader.bash" "skip" "$file_type"
done
# Load theme, if a theme was set
@ -75,15 +78,15 @@ done
# Custom
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
if [ -e "${config_file}" ]; then
if [ -e "${_bash_it_config_file}" ]; then
# shellcheck disable=SC1090
source "$config_file"
source "$_bash_it_config_file"
fi
done
unset config_file
unset _bash_it_config_file
if [[ $PROMPT ]]; then
export PS1="\[""$PROMPT""\]"
fi

View File

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