dotfiles/.profile
Alexander Hess a89c4955c5
Add base configuration
- Follow XDG standard: ~/.config and ~/.local folders
- Set environment variables and define aliases within ~/.config/shell
- Add installation script for easy setup and maintenance
  (i.e., `dotfiles-install` and `dotfiles-update`)
- Add README.md with info on the installation and general notes
2026-09-22 11:59:28 +02:00

83 lines
1.9 KiB
Shell

#!/bin/sh
# Main setup file executed for all kinds of shells
# Prevent loading ~/.profile twice in `bash`
export 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"
[ -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
# Ensure ~/.profile is loaded each time `bash` starts
unset PROFILE_LOADED