Last active
August 29, 2015 14:22
-
-
Save lillesvin/5ca9a23640767b81389d to your computer and use it in GitHub Desktop.
Show active git branch in Bash prompt
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
#!/bin/bash | |
# Put this in $HOME/bin/get_git_branch.sh | |
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then | |
if [[ "$branch" == "HEAD" ]]; then | |
branch='detached*' | |
fi | |
fi | |
echo $branch |
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
# Add this to $HOME/.bashrc | |
function git_prompt { | |
gitBranch=`$HOME/bin/get_git_branch.sh` | |
if [ -z $gitBranch ]; then | |
PS1='\u@\h:\W\$ ' | |
else | |
PS1='\u@\h:\W (\[\033[0;35m\]$gitBranch\[\033[0m\])\$ ' | |
fi | |
} | |
PROMPT_COMMAND=git_prompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment