#{- ~/.bashrc -}# #{- PROMPT -}# if which tput &> /dev/null && tput bold &> /dev/null; then red="\001$(tput bold)$(tput setaf 1)\002" green="\001$(tput bold)$(tput setaf 2)\002" yellow="\001$(tput bold)$(tput setaf 3)\002" blue="\001$(tput bold)$(tput setaf 4)\002" magenta="\001$(tput bold)$(tput setaf 5)\002" cyan="\001$(tput bold)$(tput setaf 6)\002" no_color="\001$(tput sgr0)\002" else red="\[\033[1;31m\]" green="\[\033[1;32m\]" yellow="\[\033[1;33m\]" blue="\[\033[1;34m\]" magenta="\[\033[1;35m\]" cyan="\[\033[1;36m\]" no_color="\[\033[0m\]" fi export PS1="${green}"'\$'"${no_color} " export DIRENV_PS1="${red}"'\$'"${no_color} " export NIX_SHELL_PS1="${blue}"'λ'"${no_color} " if [ "${HOSTNAME}" != "crypt" ] && [ "${HOSTNAME}" != "tomb" ] || [ "${SSH_TTY}" != "" ]; then DIRENV_PS1="${DIRENV_PS1}${blue}${HOSTNAME} ${DIRENV_PS1}" NIX_SHELL_PS1="${NIX_SHELL_PS1}${green}${HOSTNAME} ${NIX_SHELL_PS1}" PS1="${PS1}${blue}${HOSTNAME} ${PS1}" fi export ORIG_PS1=${PS1} if which direnv &> /dev/null; then update_prompt() { if [ -n "${IN_NIX_SHELL}" ]; then PS1=${NIX_SHELL_PS1} elif direnv status | grep -iEq 'RC allowed (true|0)'; then PS1=${DIRENV_PS1} else PS1=${ORIG_PS1} fi } PROMPT_COMMAND="update_prompt; $PROMPT_COMMAND" fi # Continuation Prompt: "> " in cyan export PS2="${cyan}>${no_color} " # Debugging Prompt: "# " in blue export PS4="${blue}#${no_color} " #{- HISTORY -}# PROMPT_COMMAND="history -n; history -w; history -c; history -r; $PROMPT_COMMAND" # PROMPT_COMMAND="echo hist1; history; history -n; echo hist2; history; history -w; echo hist3; history; history -c; echo hist4; history; history -r; echo hist5; history; $PROMPT_COMMAND" export HISTFILE="$HOME/.history/bash" export HISTTIMEFORMAT="%F %T " export HISTCONTROL="erasedups:ignoreboth" export HISTFILESIZE=-1 export HISTSIZE=-1 export PERSISTENT_HISTFILE="${HOME}/.history/bash_persistent_history" log_bash_persistent_history() { local rc=$? [[ $(history 1) =~ ^\ *[0-9]+\ +([^\ ]+\ [^\ ]+)\ +(.*)$ ]] local date_part="${BASH_REMATCH[1]}" local command_part="${BASH_REMATCH[2]}" # Ensure file exists if ! [ -w "$(dirname ${PERSISTENT_HISTFILE})" ]; then mkdir -p $(dirname ${PERSISTENT_HISTFILE}) fi if [ "$command_part" != "$PERSISTENT_HISTORY_LAST" ] then echo $date_part "|" "$rc" "|" "$command_part" >> "${PERSISTENT_HISTFILE}" export PERSISTENT_HISTORY_LAST="$command_part" fi } PROMPT_COMMAND="log_bash_persistent_history; $PROMPT_COMMAND" #{- SOURCING -}# # Source profile, if it hasn't already been loaded if [ -z "$__PROFILE_DONE" ]; then . $HOME/.profile fi # Source .env to extend with secret/sensitive environment variables if it exists if [ -r "$HOME/.env" ]; then . "$HOME/.env" fi # Source aliases, if they exist if [ -f "$HOME/.aliases" ] && [ -r "$HOME/.aliases" ]; then . "$HOME/.aliases" fi # Source private aliases, if they exist if [ -f "$HOME/.private_aliases" ] && [ -r "$HOME/.private_aliases" ]; then . "$HOME/.private_aliases" fi # Source functions, if they exist if [ -f "$HOME/.functions" ] && [ -r "$HOME/.functions" ]; then . "$HOME/.functions" fi # Source private functions, if they exist if [ -f "$HOME/.private_functions" ] && [ -r "$HOME/.private_functions" ]; then . "$HOME/.private_functions" fi # Preserve the usefulness of set -x by attempting to hide everything that # happens in prompt_command preserve_xtrace() { if grep -q "x" <<< $-; then XTRACE_WAS_SET=1 set +x fi } 2>/dev/null preserve_xtrace_reset() { if [ "${XTRACE_WAS_SET}" ]; then set -x unset XTRACE_WAS_SET fi } 2>/dev/null PROMPT_COMMAND="preserve_xtrace; $PROMPT_COMMAND; preserve_xtrace_reset" if $(which direnv &> /dev/null); then eval "$(direnv hook bash)" fi