Created
May 10, 2009 23:55
-
-
Save hallettj/109793 to your computer and use it in GitHub Desktop.
This file contains 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
# My bash prompt. Displays the currently checked out git | |
# branch and the exit status of the last command. | |
# | |
# This is adapted from various sources, including colors | |
# from Lifehacker and exit status and git branch indicators | |
# from Igal Koshevoy <http://gist.github.com/109520>. | |
# | |
# To use copy and paste this code into your .bashrc file. | |
function prompt { | |
local WHITE="\[\033[1;37m\]" | |
local CYAN="\[\033[0;36m\]" | |
local GRAY="\[\033[0;37m\]" | |
local GREEN="\[\e[1;32m\]" | |
local BLUE="\[\e[1;34m\]" | |
local BLACK="\[\e[0m\]" | |
function git_branch { | |
ref=$(git symbolic-ref HEAD 2> /dev/null) || return 0 | |
echo " ${ref#refs/heads/}" | |
} | |
# Displays a frowning face if any commands in a pipe expression fail. | |
# For example, foo | bar | grep nao | |
# | |
# Displays a smiling face if all commands ran successfully. | |
function exit_status_indicator { | |
for stat in ${PIPESTATUS[*]} | |
do | |
stat_sum=$(($stat_sum + $stat)) | |
done | |
if [ $stat_sum == 0 ] | |
then | |
echo ':)' | |
else | |
echo ':(' | |
fi | |
} | |
export PS1="${debian_chroot:+($debian_chroot)}${GREEN}\u@\h ${BLUE}\W${CYAN}\$(git_branch) ${BLUE}\$(exit_status_indicator) ${BLACK}" | |
} | |
prompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment