Last active
December 25, 2015 04:29
-
-
Save Bgouveia/6917841 to your computer and use it in GitHub Desktop.
Commandline git branch description (NOT MINE, just sharing). Paste at the end of your ~/.bashrc or ~/.profile or ~/.bash_profile (check out which one you have first). After pasting and saving it, type "source ~/.bashrc" (or .profile or .bash_profile) and get inside any repo to check if it worked =)
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
# 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" | |
red=$'\e[1;31m' | |
normal_colours=$'\e[m' | |
PS1="\[$normal_colours\]\u@\h:\w\[$red\]\$git_branch\[$normal_colours\]\\$\[$normal_colours\] " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment