From deaa3a0e2ff9d4e59273900f93fda128dc95e623 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Wed, 6 Jul 2011 23:28:16 -0500 Subject: [PATCH] Explicitly avoid loading self more than once, instead of relying on symlink detection --- bash-config/bash_profile.d/98-dot-bash-profile | 5 +++-- bash-config/bashrc.d/99-dot-bashrc | 5 +++-- bash-config/common | 16 +++++++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/bash-config/bash_profile.d/98-dot-bash-profile b/bash-config/bash_profile.d/98-dot-bash-profile index 78416f1..1942122 100644 --- a/bash-config/bash_profile.d/98-dot-bash-profile +++ b/bash-config/bash_profile.d/98-dot-bash-profile @@ -1,4 +1,5 @@ -# Source user's bash_profile, if it exists and isn't a symlink to myself +# Source user's bash_profile if it exists +# bash-config will only load itself once per config set, so this will not loop _prof="$(realpath "${HOME}/.bash_profile")" -[ -f "${_prof}" ] && echo "${_prof}" | grep -qv "^${_base}" && source "${_prof}" +[ -f "${_prof}" ] && source "${_prof}" unset _prof diff --git a/bash-config/bashrc.d/99-dot-bashrc b/bash-config/bashrc.d/99-dot-bashrc index eb47e67..344697c 100644 --- a/bash-config/bashrc.d/99-dot-bashrc +++ b/bash-config/bashrc.d/99-dot-bashrc @@ -1,4 +1,5 @@ -# Source user's bashrc, if it exists and isn't a symlink to myself +# Source user's bashrc if it exists +# bash-config will only load itself once per config set, so this will not loop _prof="$(realpath "${HOME}/.bashrc")" -[ -f "${_prof}" ] && echo "${_prof}" | grep -qv "^${_base}" && source "${_prof}" +[ -f "${_prof}" ] && source "${_prof}" unset _prof diff --git a/bash-config/common b/bash-config/common index 667dec9..fb63176 100644 --- a/bash-config/common +++ b/bash-config/common @@ -1,9 +1,15 @@ # Set up _base, _self first -# Interactive shell? -_i() { [[ $- == *i* ]]; return $?; } +# Keep track of which config set is loaded, to avoid loading a config set more than once +if [ -z "${__BASH_CONFIG_LOADED}" ] || echo "${__BASH_CONFIG_LOADED}" | grep -qv " ${_self} " +then + export __BASH_CONFIG_LOADED="${__BASH_CONFIG_LOADED} ${_self} " -# Include all subfiles, in lexicographical order -eval $(find "${_base}/${_self}.d/" -type f | sort | sed -e 's/^/source /; s/$/;/') + # Interactive shell? + _i() { [[ $- == *i* ]]; return $?; } -unset _base _self _i + # Include all subfiles, in lexicographical order + eval $(find "${_base}/${_self}.d/" -type f | sort | sed -e 's/^/source /; s/$/;/') + + unset _base _self _i +fi -- 2.45.0