2026-06-11 18:28:00 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
# Main setup file executed for all kinds of shells
|
2026-06-11 18:28:02 +02:00
|
|
|
#
|
|
|
|
|
# For `bash`, if the following files exist,
|
|
|
|
|
# they have precedence over this file:
|
|
|
|
|
# - ~/.bash_login
|
|
|
|
|
# - ~/.bash_profile
|
|
|
|
|
#
|
|
|
|
|
# So, we make both source this file,
|
|
|
|
|
# and thus preserve the load order either way!
|
2026-06-11 18:28:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Prevent loading ~/.profile twice in `bash`
|
2026-06-11 18:28:02 +02:00
|
|
|
PROFILE_LOADED=1
|
2026-06-11 18:28:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Basic utilities
|
|
|
|
|
|
|
|
|
|
_command_exists() {
|
|
|
|
|
command -v "$1" 1>/dev/null 2>&1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_in_bash() {
|
|
|
|
|
[ -n "$BASH_VERSION" ]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_in_zsh() {
|
|
|
|
|
[ -n "$ZSH_VERSION" ]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_prepend_to_path () {
|
|
|
|
|
if [ -d "$1" ] ; then # Ignore non-existing directories
|
|
|
|
|
case :$PATH: in
|
|
|
|
|
*:"$1":*) ;; # Already in the `$PATH` => Do nothing
|
|
|
|
|
*) PATH=$1:$PATH ;; # Otherwise, prepend it
|
|
|
|
|
esac
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_remove_from_path () {
|
|
|
|
|
_rest=$PATH # Not yet processed `$PATH`s
|
|
|
|
|
_new= # `$PATH`s collected so far
|
|
|
|
|
|
|
|
|
|
while [ -n "$_rest" ]; do # Rebuild the `$PATH` entry by entry
|
|
|
|
|
|
|
|
|
|
_dir=${_rest%%:*} # First remaining entry
|
|
|
|
|
|
|
|
|
|
case $_rest in
|
|
|
|
|
*:*) _rest=${_rest#*:} ;; # Drop that entry and its colon
|
|
|
|
|
*) _rest= ;; # Last entry read => Stop
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
[ "$_dir" = "$1" ] && continue # Skip on an exact match
|
|
|
|
|
|
|
|
|
|
_new=${_new:+$_new:}$_dir # Append, avoiding a leading colon
|
|
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
PATH=$_new
|
|
|
|
|
|
|
|
|
|
unset _dir _new _rest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_remove_from_path "/usr/games"
|
|
|
|
|
_remove_from_path "/usr/local/games"
|
|
|
|
|
|
|
|
|
|
_prepend_to_path "$HOME/.local/bin"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Needs ~/.local/bin on the `$PATH` already
|
|
|
|
|
# because it checks existence of some binaries
|
|
|
|
|
[ -f "$HOME/.config/shell/env" ] && . "$HOME/.config/shell/env"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ -f "$HOME/.config/shell/aliases" ] && . "$HOME/.config/shell/aliases"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Source ~/.profile_local, which holds machine-specific ENV variables
|
|
|
|
|
[ -f "$HOME/.profile_local" ] && . "$HOME/.profile_local"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Load `bash`-specific configurations
|
|
|
|
|
if [ -n "$BASH_VERSION" ] && [ -f "$HOME/.bashrc" ]; then
|
|
|
|
|
. "$HOME/.bashrc"
|
|
|
|
|
fi
|
2026-06-11 18:28:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# `zsh`-specific configurations are automatically sourced from ~/.zshrc,
|
|
|
|
|
# which then also ensures that this file is sourced
|