bash: restructured bashrc and bash_profile so they won't cause problems with scp
This commit is contained in:
parent
5ae5f29898
commit
3ea46d1f59
2 changed files with 64 additions and 50 deletions
|
@ -14,13 +14,16 @@ for file in ~/.environment.d/*.env; do
|
||||||
done
|
done
|
||||||
set +a
|
set +a
|
||||||
|
|
||||||
# Source the .bashrc if the Filedescriptor for stdin is opened. This is a very
|
unset -v file
|
||||||
|
|
||||||
|
# Source the .bashrc if the file descriptor for stdin is opened. This is a very
|
||||||
# simple test to determine if the .bash_profile was sourced from VT or SSH-login
|
# simple test to determine if the .bash_profile was sourced from VT or SSH-login
|
||||||
# where the .bashrc has to be sourced to provide a similar environment to a
|
# where the .bashrc has to be sourced to provide a similar environment to a
|
||||||
# terminal emulator. Found here:
|
# terminal emulator. Found here:
|
||||||
# https://eklitzke.org/effectively-using-bash-profile
|
# https://eklitzke.org/effectively-using-bash-profile
|
||||||
if [[ -t 0 && -r ~/.bashrc ]]; then
|
# I had to move the actual test '-t 0' over to the bashrc. More information as
|
||||||
|
# to why can be found there.
|
||||||
|
if [[ -r ~/.bashrc ]]; then
|
||||||
. ~/.bashrc
|
. ~/.bashrc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
unset -v file
|
|
||||||
|
|
45
.bashrc
45
.bashrc
|
@ -1,4 +1,14 @@
|
||||||
# .bashrc
|
# .bashrc
|
||||||
|
# Don't load the bashrc if the terminal is not interactive. More information
|
||||||
|
# on how this test works can be found at the end of the bash_profile. I had to
|
||||||
|
# move this test here, because in remote shells the bashrc is sourced directly,
|
||||||
|
# wether the shell is really interactive or not. A brief explanation of this
|
||||||
|
# behaviour can be found here:
|
||||||
|
# https://unix.stackexchange.com/questions/257571
|
||||||
|
if ! [[ -t 0 ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Source global definitions
|
# Source global definitions
|
||||||
if [[ -r /etc/bashrc ]]; then
|
if [[ -r /etc/bashrc ]]; then
|
||||||
. /etc/bashrc
|
. /etc/bashrc
|
||||||
|
@ -6,27 +16,28 @@ fi
|
||||||
|
|
||||||
# Bash 4 or bust
|
# Bash 4 or bust
|
||||||
if (( BASH_VERSINFO[0] < 4 )); then
|
if (( BASH_VERSINFO[0] < 4 )); then
|
||||||
echo "Please get a newer version of Bash."
|
echo "Please get a newer version of Bash." >&2
|
||||||
echo "Your bashrc won't work otherwise."
|
echo "Your bashrc won't work otherwise." >&2
|
||||||
else
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Basic safe boolean evaluation. See this Gist for details:
|
# Basic safe boolean evaluation. See this Gist for details:
|
||||||
# https://gist.github.com/gliech/184dc7566821442202f21dfe15e2b7ff
|
# https://gist.github.com/gliech/184dc7566821442202f21dfe15e2b7ff
|
||||||
function truthy {
|
function truthy {
|
||||||
if [[ "${1,,}" == @(y|yes|on|true|1) ]]; then
|
if [[ "${1,,}" == @(y|yes|on|true|1) ]]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function falsy {
|
function falsy {
|
||||||
if [[ "${1,,}" == @(n|no|off|false|0) ]]; then
|
if [[ "${1,,}" == @(n|no|off|false|0) ]]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function true_false_default {
|
function true_false_default {
|
||||||
case "${1,,}" in
|
case "${1,,}" in
|
||||||
y | yes | on | true | 1)
|
y | yes | on | true | 1)
|
||||||
return 0 ;;
|
return 0 ;;
|
||||||
|
@ -36,11 +47,11 @@ else
|
||||||
shift
|
shift
|
||||||
eval "$@"
|
eval "$@"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
export -f truthy falsy true_false_default
|
export -f truthy falsy true_false_default
|
||||||
|
|
||||||
if truthy $DOTFILES_ACTIVE; then
|
if truthy $DOTFILES_ACTIVE; then
|
||||||
|
|
||||||
# Source .bashrc.d
|
# Source .bashrc.d
|
||||||
for file in ~/.bashrc.d/*.sh; do
|
for file in ~/.bashrc.d/*.sh; do
|
||||||
|
@ -49,9 +60,9 @@ else
|
||||||
|
|
||||||
unset -v file
|
unset -v file
|
||||||
|
|
||||||
elif [[ ! -v DOTFILES_ACTIVE ]]; then
|
elif [[ ! -v DOTFILES_ACTIVE ]]; then
|
||||||
echo "Dotfiles environment not found."
|
echo "Dotfiles environment not found." >&2
|
||||||
echo "You should probably reload your login session before proceeding."
|
echo "You should probably reload your login session before proceeding." >&2
|
||||||
fi
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue