Skip to content

Instantly share code, notes, and snippets.

@dougalcorn
Created September 26, 2011 14:05
Show Gist options
  • Select an option

  • Save dougalcorn/1242310 to your computer and use it in GitHub Desktop.

Select an option

Save dougalcorn/1242310 to your computer and use it in GitHub Desktop.
Bash Prompt for Git Status
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
# Black 0;30 Dark Gray 1;30
# Blue 0;34 Light Blue 1;34
# Green 0;32 Light Green 1;32
# Cyan 0;36 Light Cyan 1;36
# Red 0;31 Light Red 1;31
# Purple 0;35 Light Purple 1;35
# Brown 0;33 Yellow 1;33
# Light Gray 0;37 White 1;37
case $TERM in
ansi|screen|xterm*)
# PROMPT_COMMAND='echo -ne "\033]0;${USER}@${STY}: ${PWD}\007"'
PS1='\[\033]0;\w\007\]\[\033[1;33m\]\h: \W $(parse_git_branch)\$\[\033[0m\] '
;;
*)
PS1="[\u@\h: \w]\\$ "
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment