Created
October 1, 2020 23:15
-
-
Save danni/8d2309805ed537e8724e1e84cc28815a to your computer and use it in GitHub Desktop.
.bashrc fragments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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