Skip to content

Instantly share code, notes, and snippets.

@mars
Last active October 22, 2018 21:48
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 mars/3933132 to your computer and use it in GitHub Desktop.
Save mars/3933132 to your computer and use it in GitHub Desktop.
bash prompt git status
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
function parse_git_dirty {
git diff --quiet || echo " ▲ "
}
function parse_git_branch {
e=`echo $( { git status; } 2>&1 ) | tr '[:upper:]' '[:lower:]'`
if [[ ! $e =~ 'not a git repository' ]]
then git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)] /"
fi
}
export PS1="\[$(tput rev)\]\t\[$(tput sgr0)\] \[\033[1m\]---\[\033[0m\] \W \$(parse_git_branch)\[\033[1m\]---\[\033[0m\] "
export PS2="\[$(tput rev)\]\t\[$(tput sgr0)\] \[\033[1m\]---\[\033[0m\] "
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment