Showing Git status in shell with emotional icon
When using the Git version control system, we create a lot of branches. There are already tons of shell profile script to show you which branch you are. I go a step further by showing the git status also. Moreover, I used emotional face icon to represent different states.
For example,
v-.-v is a clean repository.
\_/! means there are changes.
\_/||| means there are staged but not commit changes.
By using these cute emotions, I can quickly know the status of the repo with just a glimpse. The following screenshot shows my terminal with different git status.

The following code are the source of the profile bash. The code is also available on Github.
function parse_git_dirty {
D="$(git status 2> /dev/null | tail -n1 | awk '{ print $1 }' )"
if [ "$D" = "nothing" ] ; then
echo -e "v-.-v : "
elif [ "$D" = "no" ]; then
echo -e "\_/! : "
elif [ "$D" = "#" ]; then
#echo -e "\_/||| \033[0;37m: "
echo -e "\_/||| : "
else
echo "-.-"
fi
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
}
export PS1="\[\033[1;32m\]\t \[\033[1;35m\]\u@\h:\W \$(parse_git_dirty)\$(parse_git_branch)\$ \[\033[0m\]"
The output of any Git repo directory looks like the following.
15:20:51 makzan@Mr-Air-Mak:JailBreakers v-.-v : dev_zoom$
To install it in Mac, paste the code in the <home directory>/.profile file and reopen the terminal to see the changes.


Mar 30, 2011 @ 17:23:25
Thanks for that awesome posting. It saved MUCH time :-)