Skip to content

Instantly share code, notes, and snippets.

@danni
Created October 1, 2020 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danni/8d2309805ed537e8724e1e84cc28815a to your computer and use it in GitHub Desktop.
Save danni/8d2309805ed537e8724e1e84cc28815a to your computer and use it in GitHub Desktop.
.bashrc fragments
# Create a prompt command function that can set the terminal title with info including your Git branch
__prompt_command() {
# Based on: http://stackoverflow.com/a/13003854/170413
local branch
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
branch='detached'
fi
if [[ "$(git status --porcelain 2> /dev/null)" != "" ]]; then
branch="$branch*"
fi
branch="($branch)"
fi
# Set the XTerm title
echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~} ${branch}\007"
}
case $TERM in
xterm*)
PROMPT_COMMAND=__prompt_command
;;
*)
;;
esac
# Replace virtualenv name with an emoji
function __venv_info() {
[[ -n "$VIRTUAL_ENV" ]] && echo " 🐍"
}
export VIRTUAL_ENV_DISABLE_PROMPT=1 # Disable default behaviour
export PS1="[\u@\h \W\$(__venv_info)]\$ " # Add \$(__venv_info) into your prompt
# Report exit statuses from failed commands
# Put this at the top
trap ERR # Uninstall trap
# Put this last
# Otherwise random scripts you source might cause traps you don't care for
__trap() {
local exit=$?
if [[ $exit != 0 ]]; then
echo -e "\033[91mexit($exit)\033[0m"
fi
}
trap __trap ERR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment