Skip to content

Instantly share code, notes, and snippets.

@tmichel
Created November 7, 2012 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmichel/4028863 to your computer and use it in GitHub Desktop.
Save tmichel/4028863 to your computer and use it in GitHub Desktop.
pimp_it - PS1 for git
# colors
Escape="\033"
Red="${Escape}[31m"
Green="${Escape}[32m"
Yellow="${Escape}[33m"
Reset="${Escape}[0m"
pimp_it ()
{
# are we in a git repo?
git branch &>/dev/null
if [ $? -eq 0 ]; then
local status=`git status --porcelain`
# staging area
local idx_modified=$(expr `echo "$status" | grep -P '^M' -c` + `echo "$status" | grep -P '^R' -c`)
local idx_new=`echo "$status" | grep -P '^A' -c`
local idx_deleted=`echo "$status" | grep -P '^D' -c`
# working tree
local wrk_modified=$(expr `echo "$status" | grep -P '^ M' -c` + `echo "$status" | grep -P '^ R' -c`)
local wrk_new=$(expr `echo "$status" | grep -P '^\?\?' -c` + `echo "$status" | grep -P '^ A' -c`)
local wrk_deleted=`echo "$status" | grep -P '^ D' -c`
# let's put it together, add some nice colors
work="${Red}+$wrk_new ~$wrk_modified -$wrk_deleted${Reset}"
index="${Green}+$idx_new ~$idx_modified -$idx_deleted${Reset}"
echo -e " [$index | $work] $(__git_ps1 "(%s)")"
fi
}
pimp_the_branch ()
{
git branch &>/dev/null
if [ $? -eq 0 ]; then
local mod=`git status | grep -c "nothing to commit"`
if [ $mod -eq 1 ]; then
echo -e " (${Green}$(__git_ps1 "%s")${Reset})"
else
echo -e " (${Yellow}$(__git_ps1 "%s")${Reset})"
fi
fi
}
PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w$(pimp_the_branch)\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment