Created
June 14, 2016 08:33
-
-
Save z448/22ded8ac3a028a78f2f77af5624d0986 to your computer and use it in GitHub Desktop.
display current git branch in terminal prompt
This file contains hidden or 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 | |
# to display current git branch in terminal prompt on start of session add this to your ~/.bashrc file | |
# ex.: if you are in folder which is git repository switched to master branch your prompt will look like | |
# /home/joe [master] _ | |
# | |
# source http://perltricks.com/article/displaying-the-git-branch-in-the-terminal-prompt-with-perl/ | |
function current_git_branch { | |
git branch 2> /dev/null | perl -ne 'print " [$_]" if s/^\*\s+// && chomp' | |
} | |
PS1="\w\$(current_git_branch) " | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment