Created
April 29, 2009 09:38
-
-
Save hail2u/103685 to your computer and use it in GitHub Desktop.
This file contains 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
# show Git branch name with some informations | |
# normal: ~/git/foo (master) | |
# something to commit: ~/git/foo (master*) | |
# not pushed to origin: ~/git/foo (master!) | |
# something to commit and not pushed to origin: ~/git/foo (master*!) | |
# Git: get branch status | |
function git_get_branch_status { | |
local STATUS=`git status 2> /dev/null | tail -n1` | |
[[ ${STATUS} != "nothing to commit (working directory clean)" ]] && echo -ne "*" | |
local REMOTE=`git log origin/$1 2> /dev/null | head -n1` | |
local LOCAL=`git log $1 2> /dev/null | head -n1` | |
[[ ${REMOTE} ]] && [[ ${REMOTE} != ${LOCAL} ]] && echo -ne "!" | |
} | |
# Git: show branch name | |
function git_show_branch_name { | |
BRANCH=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"` | |
if [[ ${BRANCH} != "" ]]; then | |
echo -ne "(" | |
echo -ne ${BRANCH} | |
git_get_branch_status ${BRANCH} | |
echo -ne ")" | |
fi | |
} | |
# prompt settings | |
export PS1=' | |
\[\e[1;33m\]\w \[\e[1;32m\]$(git_show_branch_name) | |
\[\e[0m\]$ ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment