Skip to content

Instantly share code, notes, and snippets.

@hail2u
Created April 29, 2009 09:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hail2u/103685 to your computer and use it in GitHub Desktop.
Save hail2u/103685 to your computer and use it in GitHub Desktop.
# 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