]> CyberLeo.Net >> Repos - CDN/bash-config.git/blob - bash-config/common
Avoid unsetting needed variables during recursive inclusion
[CDN/bash-config.git] / bash-config / common
1 # Set up _base, _self first
2
3 # Keep track of which config set is loaded, to avoid loading a config set more than once
4 if [ -z "${__BASH_CONFIG_LOADED}" ] || echo "${__BASH_CONFIG_LOADED}" | grep -qv " ${_self} "
5 then
6   __BASH_CONFIG_LOADED="${__BASH_CONFIG_LOADED} ${_self} "
7   __BASH_CONFIG_DEPTH=$(( ${__BASH_CONFIG_DEPTH:-0} + 1 ))
8
9   # Interactive shell?
10   _i() { [[ $- == *i* ]]; return $?; }
11
12   # Include all subfiles, in lexicographical order
13   eval "$(
14     (
15       [ -d "${_base}/${_self}.d/" ] && echo "${_base}/${_self}.d/"
16       [ -d "${HOME}/.${_self}.d/" ] && echo "${HOME}/.${_self}.d/"
17     ) | while read _path
18     do
19       find ${_path} -type f | sort
20     done | sed -e 's/^/source /; s/$/;/'
21   )"
22
23   __BASH_CONFIG_DEPTH=$(( ${__BASH_CONFIG_DEPTH} - 1 ))
24   [ "${__BASH_CONFIG_DEPTH}" -gt 0 ] || unset _base _self _i __BASH_CONFIG_DEPTH
25 fi