Skip to content

Instantly share code, notes, and snippets.

@clarsen
Forked from bsag/.bashrc
Created July 25, 2009 13:15
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 clarsen/154793 to your computer and use it in GitHub Desktop.
Save clarsen/154793 to your computer and use it in GitHub Desktop.
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
# bsag: I combined the best of both worlds and used the parse_git_dirty function here:
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/#comment-4166
# as well as various other mods from the forks of this gist.
function parse_git_dirty {
git diff --quiet HEAD &>/dev/null
[[ $? == 1 ]] && echo "*"
}
function parse_git_branch {
ref=$(git-symbolic-ref HEAD 2> /dev/null) || return
echo ${ref#refs/heads/}
}
# 3 line prompt:
# >>> {bash history number} {username}@{host}
# {time} {working directory}
# [git branch and state] $
# and titlebar:
# user@host:working directory
#
# PS1 set in function so you can choose to not set the fancy prompt for
# certain situations.
function set_prompt {
# ANSI escape codes documented in:
# http://en.wikipedia.org/wiki/ANSI_escape_code
case $TERM in
xterm*)
TITLEBAR='\[\033]0;\u@\h:$(dirs)\007\]'
;;
*)
TITLEBAR=""
;;
esac
local REDBOLD="\[\033[1;31m\]"
local WHITE="\[\033[0;37m\]"
local YELLOWBOLD="\[\033[1;33m\]"
local NORMAL="\[\033[0m\]"
export PS1="${TITLEBAR}\
$REDBOLD>>> \! $WHITE\u@\h\n\
$WHITE\@ $YELLOWBOLD\$(dirs)\n\
[\$(parse_git_branch)\$(parse_git_dirty)] \$$NORMAL "
}
set_prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment