Skip to content

Instantly share code, notes, and snippets.

@bradurani
Created March 10, 2014 22:07
Show Gist options
  • Save bradurani/9475484 to your computer and use it in GitHub Desktop.
Save bradurani/9475484 to your computer and use it in GitHub Desktop.
add to .profile to add git branch name to cmd prompt
# git-related functions and aliases
parse_git_head () {
git name-rev HEAD 2> /dev/null | sed 's#HEAD\ \(.*\)# (git::\1)#'
}
function get_statuscolor {
if [[ "$(git status 2> /dev/null | tail -n1)" != "nothing to commit, working directory clean" ]]
then
echo $RED
else
echo $GREEN
fi
}
function parse_git_branch {
git status 2> /dev/null | grep '# On branch' | sed 's#\# On\ branch\ \(.*\)# (\1)#'
}
BLACK="\[\033[0;38m\]"
RED="\[\033[0;31m\]"
RED_BOLD="\[\033[01;31m\]"
BLUE="\[\033[0;34m\]"
BLUE_BOLD="\[\033[01;34m\]"
GREEN="\[\033[0;32m\]"
YELLOW="\[\033[0;33m\]"
export PS1="$YELLOW\w$(get_statuscolor)\$(parse_git_branch)$BLACK : "
@bradurani
Copy link
Author

Function has an error in coloring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment