Skip to content

Instantly share code, notes, and snippets.

@smasty
Created September 14, 2011 14:29
Show Gist options
  • Save smasty/1216717 to your computer and use it in GitHub Desktop.
Save smasty/1216717 to your computer and use it in GitHub Desktop.
Bash prompt with exit code and Git branch
# ========= PS1 SETTINGS
# Git branch
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/@\1/'
}
# Pipe code notifiation
bash_prompt_command() {
PC=$?
pipe_code=$(pipe_code $PC)
unset C
}
PROMPT_COMMAND=bash_prompt_command
pipe_code() {
if [ $1 != 0 ] && [ $1 != 130 ] ; then
echo -e "\e[0;31m[#$1]\e[0;0m"
fi
}
export PS1="\w\[\033[33m\]\$(git_branch)\[\033[00m\]\$pipe_code\$\[\033[00m\] "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment