dotfiles/.profile
Alexander Hess 0e0c4c2e62
Add configuration for bash
- Add ~/.bashrc
  + Configure on how the `history` works
  + Enable nicer `cd` and globbing behavior
  + Enable tab completion, even for aliases
  + Add some more stuff from Debian's ~/.bashrc
- Add ~/.bash_logout clearing the screen
- Add stubs for ~/.bash_login and ~/.bash_profile
  that redirect to ~/.profile
- Add ~/.bash_completion
- Ensure ~/.local/state/bash/ exists
2026-09-22 11:59:45 +02:00

87 lines
2 KiB
Shell

#!/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"
[ -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