Rudy’s OBTF Rudolf Adamkovič

Home / Unix / Bash / Configuration


.bashrc

# GNU Bash initialization file.
# https://www.gnu.org/software/bash/

DEFAULT_STYLE='\e[0m'

BLACK='\e[30m'
RED='\e[31m'
GREEN='\e[32m'
YELLOW='\e[33m'
BLUE='\e[34m'
MAGENTA='\e[35m'
CYAN='\e[36m'
GRAY='\e[90m'
LIGHT_GRAY='\e[37m'
LIGHT_RED='\e[91m'
LIGHT_GREEN='\e[92m'
LIGHT_YELLOW='\e[93m'
LIGHT_BLUE='\e[94m'
LIGHT_MAGENTA='\e[95m'
LIGHT_CYAN='\e[96m'
WHITE='\e[97m'

BOLD='\e[1m'
DIM='\e[2m'
ITALIC='\e[3m'
UNDERLINED='\e[4m'
BLINKING='\e[5m'
REVERSE='\e[7m'
INVISIBLE='\e[8m'

# Source shell configuration.
source ~/.profile

# Improve Bash completions.
source /opt/homebrew/etc/profile.d/bash_completion.sh

# Avoid duplicate entries in the shell history.
HISTCONTROL=ignoredups

# Avoid storing session histories.
SHELL_SESSION_HISTORY=0

# Use color to indicate file type.
# SEE ALSO: The analogous setting in ".inputrc".
alias ls="ls -Gha"

function _build_prompt() {
    local EXIT=$? # must be first

    # NOTE: Every escape sequence in PS1 must be wrapped in '\[' and
    # '\]' or else the GNU Readline library will compute an incorrect
    # visible length of the 'PS1' string resulting in glitchy redraws.

    # Clear the prompt.
    PS1=""

    # Add exit code, if non-zero.
    if [[ $EXIT -ne 0 ]]; then
        PS1+="\[${LIGHT_RED}\](${EXIT}) "
    fi

    # Add username and hostname.
    PS1+="\[${LIGHT_GREEN}\]\[${ITALIC}\]"
    PS1+="\u@\h"
    PS1+="\[${DEFAULT_STYLE}\]"

    # Add Git branch.
    PS1+="\[${LIGHT_MAGENTA}\]"
    PS1+="$(__git_ps1) "
    PS1+="\[${DEFAULT_STYLE}\]"

    # Add working directory.
    PS1+="\[${UNDERLINED}\]\[${LIGHT_YELLOW}\]"
    PS1+="\W"
    PS1+="\[${DEFAULT_STYLE}\]"

    # Add prompt symbol, `$' or `#'.
    PS1+=" \$ "
}

# Use a fancy prompt, if running in a fancy terminal.
if [[ "${TERM:0:5}" == "xterm" ]]
then
    PROMPT_COMMAND=_build_prompt
else
    PS1="$ "
fi

# Improve Emacs intergration.
source ~/.bashrc-emacs

# Activate Python virtual environment.
PYTHON_ACTIVATE=~/.venv/bin/activate
if [[ -f $PYTHON_ACTIVATE ]]
then
    source $PYTHON_ACTIVATE
fi

# Find programs installed with `cargo install'
export PATH=/Users/salutis/.cargo/bin:$PATH

© 2025 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.