Created
September 6, 2012 19:10
-
-
Save marclipovsky/3659594 to your computer and use it in GitHub Desktop.
Include branch name (and other info) in my bash prompt
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
# Get's the current git branch | |
function parse_git_branch | |
{ | |
ref=$(git symbolic-ref HEAD 2> /dev/null) || return | |
echo "("${ref#refs/heads/}")" | |
} | |
# Checks to see if there are uncommitted files | |
function git_status | |
{ | |
string=$(git status 2> /dev/null) || return | |
if [[ "$string" == *"Changes not staged for commit"* ]] | |
then | |
echo "!" | |
fi | |
} | |
# Checks to see if there are files ready to be committed | |
function git_changes | |
{ | |
string=$(git status 2> /dev/null) || return | |
if [[ "$string" == *"Changes to be committed"* ]] | |
then | |
echo "+" | |
fi | |
} | |
RED="\[\e[0;31m\]" | |
YELLOW='\[\e[0;33m\]' | |
CYAN='\[\e[0;36m\]' | |
WHITE='\[\e[0;37m\]' | |
GREEN='\[\e[0;32m\]' | |
PS1="$RED ➜ $CYAN\W $YELLOW\$(parse_git_branch)$RED\$(git_status)$GREEN\$(git_changes) $WHITE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by http://railstips.org/blog/archives/2009/02/02/bedazzle-your-bash-prompt-with-git-info/