Skip to content

Instantly share code, notes, and snippets.

@jhulford
Last active January 12, 2021 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhulford/fe520621c7f35fd9ea41c4287d3a3c76 to your computer and use it in GitHub Desktop.
Save jhulford/fe520621c7f35fd9ea41c4287d3a3c76 to your computer and use it in GitHub Desktop.
Adds git branch/status to command prompt
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