Skip to content

Instantly share code, notes, and snippets.

@victorhg
Created January 16, 2013 19:48
Show Gist options
  • Save victorhg/4550215 to your computer and use it in GitHub Desktop.
Save victorhg/4550215 to your computer and use it in GitHub Desktop.
Git Bash integration
alias ls="ls -G"
alias grep="grep --colour=auto"
git_status() {
untracked=$(git status | grep 'Untracked files' 2> /dev/null)
if [ -n "$untracked" ]; then
echo "☠"
else
to_commit=$(git status | grep 'nothing to commit (working directory clean)' 2> /dev/null)
if [ -z "$to_commit" ]; then
echo "☠"
fi
fi
}
parse_git_branch ()
{
result=$(git branch 2> /dev/null | grep -e '\* ' | sed 's/^..\(.*\)/[\1]/')
if [ -n "$result" ]; then
echo $result $(git_status)
fi
}
# If id command returns zero, you’ve root access.
if [ $(id -u) -eq 0 ];then
# you are root, set red colour prompt
PS1="\\[$(tput setaf 1)\\]\\u@\\h:\\w #\\[$(tput sgr0)\\]"
else # normal
PS1='\u \[\e[1;34m\]\W\[\e[m\] \[\e[0;35m\]$(parse_git_branch)\[\e[m\] \[\e[0;32m\]$\[\e[m\]'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment