Created
September 14, 2011 14:29
-
-
Save smasty/1216717 to your computer and use it in GitHub Desktop.
Bash prompt with exit code and Git branch
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
# ========= 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