Skip to content

Instantly share code, notes, and snippets.

@martint
Created November 3, 2009 18:58
Show Gist options
  • Save martint/225321 to your computer and use it in GitHub Desktop.
Save martint/225321 to your computer and use it in GitHub Desktop.
bash_prompt() {
local status=$(git status 2> /dev/null | grep 'working directory clean')
local dirty=''
if [ -z "$status" ]; then
local dirty='*'
fi
local branch=$(git branch 2> /dev/null | grep -e "\* " | sed "s/^..\(.*\)/\1/")
if [ -z "$branch" ]; then
export PS1="[$(date +%H:%M) \u@\[\033[33m\]\h\[\033[39m\]:\w] "
else
export PS1="[$(date +%H:%M) \u@\[\033[33m\]\h\[\033[39m\]:\w \[\033[32m\]$branch\[\033[36m\]$dirty\[\033[39m\]] "
fi
}
PROMPT_COMMAND=bash_prompt
cdgit() {
local gitdir=$(git rev-parse --git-dir)
if [ -n "$gitdir" ]; then
cd $(dirname $gitdir)
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment