dotfiles/.profile

116 lines
2.8 KiB
Text
Raw Normal View History

#!/bin/sh
# Main setup file executed for all kinds of shells
#
# 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!
# Prevent loading ~/.profile twice in `bash`
PROFILE_LOADED=1
# 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"
2026-08-03 04:00:21 +02:00
# Must be between sourcing ~/.config/shell/env and ~/.config/shell/aliases
# because the first defines the `pyenv` related environment variables
# while the second creates `pyenv` related aliases
[ -n "${PYENV_ROOT:-}" ] && _prepend_to_path "$PYENV_ROOT/bin"
[ -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
# `zsh`-specific configurations are automatically sourced from ~/.zshrc,
# which then also ensures that this file is sourced
2026-08-03 04:00:21 +02:00
if [ -z "${PYENV_SHELL:-}" ] && _command_exists pyenv; then
eval "$(pyenv init -)" || echo "WARN: pyenv init failed" >&2
case $- in
*i*)
if [ -d "$PYENV_ROOT/plugins/pyenv-virtualenv" ]; then
eval "$(pyenv virtualenv-init -)" || true
fi
;;
esac
fi
# When everything is loaded, show a little welcome message
case $- in *i*) [ -f "$HOME/.config/shell/welcome" ] && . "$HOME/.config/shell/welcome";; esac