dotfiles/files/bashrc
Fernando Schauenburg 9b3bc72eaf bash: factor out profile and aliases
This is a preparation to start experimenting with zsh. The idea is to
share the aliases and environment setup between both shells to avoid
having a bunch of duplication. Even if I decide to stick with zsh it
would be nice to keep the bash configs around for systems where I might
not want to install zsh for some reason. We'll see how this goes...
2021-08-07 01:33:26 +02:00

67 lines
2.4 KiB
Bash

#!/bin/bash
# Set up bash for interactive use (options, prompt, aliases, etc.)
stty -ixon # disable ctrl-s and ctrl-q
shopt -s cdspell checkwinsize globstar histappend nocaseglob
set -o noclobber # Prevent overwriting files with output redirection.
# Eternal bash history (from https://stackoverflow.com/a/19533853)
HISTCONTROL=erasedups
HISTFILESIZE=
HISTSIZE=
HISTTIMEFORMAT="[%F %T] "
HISTFILE="$XDG_DATA_HOME/bash/history"
[ -f "${XDG_CONFIG_HOME}/shell/aliases.sh" ] && source "${XDG_CONFIG_HOME}/shell/aliases.sh"
[ -f "${XDG_CONFIG_HOME}/shell/solarized.sh" ] && source "${XDG_CONFIG_HOME}/shell/solarized.sh"
Reset="\[$(tput sgr0)\]"
PS1_EXIT="\[$(tput setaf "$Red" )\]" # color for last exit code if non-zero
PS1_ROOT="\[$(tput setaf "$Orange" )\]" # logged in as root
PS1_SSH="\[$(tput setaf "$Yellow" )\]" # hostname for SSH sessions
PS1_PWD="\[$(tput setaf "$Cyan" )\]" # PWD color
PS1_GIT="\[$(tput setaf "$Blue" )\]" # color for git branch
PS1_VENV="\[$(tput setaf "$Violet" )\]" # color for python virtual env
PS1_JOBS="\[$(tput setaf "$Magenta")\]" # color for background jobs
PS1_SEP_COLOR="\[$(tput setaf "$Base01" )\]"
PS1_SEP=" > " # separator between prompt parts
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWSTASHSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWUPSTREAM=verbose
PROMPT_COMMAND=__ps1_set
PS2="... "
__ps1_set() {
local exit=$?
local prompt=">>>>>>>>>>"
local sep_color="$PS1_SEP_COLOR"
local ps=()
[ $exit -ne 0 ] && ps+=("$PS1_EXIT$exit")
[ $EUID -eq 0 ] && { ps+=("$PS1_ROOT\u"); prompt="##########"; }
[ -n "$SSH_CONNECTION" ] && ps+=("$PS1_SSH\h")
ps+=("$PS1_PWD\w")
type __git_ps1 && __git_ps1 '' '' "$PS1_GIT%s" && [ -n "$PS1" ] && ps+=("$PS1")
[ -n "$VIRTUAL_ENV" ] && ps+=("$PS1_VENV${VIRTUAL_ENV##*/}")
local j="\j" && [ "${j@P}" -gt 0 ] && ps+=("$PS1_JOBS${j@P} bg")
local extra=""
[ ${#ps[@]} -gt 1 ] && printf -v extra "$sep_color$PS1_SEP%s" "${ps[@]:1}"
PS1="${ps[0]}$extra$sep_color ${prompt:0:$SHLVL}$Reset "
} &>/dev/null
_source_extra_configs() {
local configs=(
/usr/local/etc/profile.d/bash_completion.sh
/usr/share/bash-completion/bash_completion
$LOCAL_CONFIG/bash/*
)
local f
for f in ${configs[@]}; do [ -f "$f" ] && source "$f"; done
}
_source_extra_configs || true