Last active
January 12, 2021 14:55
-
-
Save jhulford/fe520621c7f35fd9ea41c4287d3a3c76 to your computer and use it in GitHub Desktop.
Adds git branch/status to command 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
function parse_git_branch { | |
if we_are_in_git_work_tree | |
then | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
fi | |
} | |
function we_are_in_git_work_tree { | |
git rev-parse --is-inside-work-tree &> /dev/null | |
} | |
function parse_git_status { | |
if we_are_in_git_work_tree | |
then | |
local ST=$(git status --short 2> /dev/null) | |
if [ -n "$ST" ] | |
then echo -n "*" | |
else echo -n "" | |
fi | |
fi | |
} | |
export PS1="\u \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\$(parse_git_status) > " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment