bashrc: checking if the environment is loaded before executing stuff that relies on it
This commit is contained in:
parent
abae11bfaf
commit
6b7f34f7f8
2 changed files with 47 additions and 5 deletions
48
.bashrc
48
.bashrc
|
@ -9,11 +9,49 @@ if (( BASH_VERSINFO[0] < 4 )); then
|
|||
echo "Please get a newer version of Bash."
|
||||
echo "Your bashrc won't work otherwise."
|
||||
else
|
||||
# Source .bashrc.d
|
||||
for file in ~/.bashrc.d/*.bashrc; do
|
||||
. "$file"
|
||||
done
|
||||
|
||||
unset -v file
|
||||
# Basic safe boolean evaluation. See this Gist for details:
|
||||
# https://gist.github.com/gliech/184dc7566821442202f21dfe15e2b7ff
|
||||
function truthy {
|
||||
if [[ "${1,,}" == @(y|yes|on|true|1) ]]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
function falsy {
|
||||
if [[ "${1,,}" == @(n|no|off|false|0) ]]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
function true_false_default {
|
||||
case "${1,,}" in
|
||||
y | yes | on | true | 1)
|
||||
return 0 ;;
|
||||
n | no | off | false | 0)
|
||||
return 1 ;;
|
||||
esac
|
||||
shift
|
||||
eval "$@"
|
||||
return 1
|
||||
}
|
||||
|
||||
export -f truthy falsy true_false_default
|
||||
|
||||
if truthy $DOTFILES_ACTIVE; then
|
||||
|
||||
# Source .bashrc.d
|
||||
for file in ~/.bashrc.d/*.bashrc; do
|
||||
. "$file"
|
||||
done
|
||||
|
||||
unset -v file
|
||||
|
||||
elif [[ ! -v DOTFILES_ACTIVE ]]; then
|
||||
echo "Dotfiles environment not found."
|
||||
echo "You should probably reload your login session before proceeding."
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
4
.environment.d/dotfiles.env
Normal file
4
.environment.d/dotfiles.env
Normal file
|
@ -0,0 +1,4 @@
|
|||
DOTFILES_ACTIVE=true
|
||||
DOTFILES_DIR="${HOME}/.dotfiles"
|
||||
DOTFILES_GITDIR="${HOME}/.dotgit"
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue