Skip to content

Instantly share code, notes, and snippets.

Created June 18, 2012 14:56
Show Gist options
  • Save anonymous/2948770 to your computer and use it in GitHub Desktop.
Save anonymous/2948770 to your computer and use it in GitHub Desktop.
branch on bashrc
# git branchs
function find_git_branch {
local dir=. head
until [ "$dir" -ef / ]; do
if [ -f "$dir/.git/HEAD" ]; then
head=$(< "$dir/.git/HEAD")
if [[ $head == ref:\ refs/heads/* ]]; then
git_branch=" (${head#*/*/})"
elif [[ $head != '' ]]; then
git_branch=' (detached)'
else
git_branch=' (unknown)'
fi
return
fi
dir="../$dir"
done
git_branch=''
}
PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
green=$'\e[1;32m'
normal_colours=$'\e[m'
PS1="\[$normal_colours\]\u@\h:\w\[$green\]\$git_branch\[$normal_colours\]\\$\[$normal_colours\] "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment