Skip to content

Instantly share code, notes, and snippets.

@bordoni
Created August 23, 2012 10:47
Show Gist options
  • Select an option

  • Save bordoni/3435427 to your computer and use it in GitHub Desktop.

Select an option

Save bordoni/3435427 to your computer and use it in GitHub Desktop.
Git Bash terminal output
function parse_git_dirty {
[[ "$(git status 2> /dev/null | tail -n1)" != "nothing to commit (working directory clean)" ]] && echo "*"
}
function bord_git_unpushed {
branchinfo=$(git branch -v 2> /dev/null)
if [[ $branchinfo != "" ]]
then
brinfo=$($branchinfo | grep $(bord_git_parse_branch) | egrep " \[ahead [[:digit:]]{1,}\] ")
else
brinfo=""
fi
if [[ $brinfo == "" ]]
then
echo -e ""
else
echo -e "$Yellow"
fi
}
function bord_git_prefix {
if [ "$(parse_git_dirty)" == "*" ] ; then
echo -e "[$Red"
else
echo -e "[$Green"
fi
}
function bord_git_suffix {
if [ "$(parse_git_dirty)" == "*" ] ; then
echo -e "$White]"
else
echo -e "$White]"
fi
}
function bord_git_parse_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
# Another way to be done:
# $(git symbolic-ref HEAD 2>/dev/null | awk -F/ {'print $NF'})
}
function bord_git {
if [ -d "./.git/" ]
then
echo -e "$(bord_git_prefix)$(bord_git_unpushed)$(bord_git_parse_branch)$(bord_git_suffix)"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment