Skip to content

Instantly share code, notes, and snippets.

@stoneage7
Created September 30, 2014 19:17
Show Gist options
  • Save stoneage7/2e2ae14dec45e2b98fdf to your computer and use it in GitHub Desktop.
Save stoneage7/2e2ae14dec45e2b98fdf to your computer and use it in GitHub Desktop.
Bash Prompt with git and virtualenv (2 lines)
case "$TERM" in
xterm*|screen)
# last command status ($?) shown as tick/cross and color
ok="\[\033[01;32m\]\342\234\223"
notok="\[\033[01;31m\]\342\234\227"
cmdresult="\$([[ \$? == 0 ]] && echo \"$ok\" || echo \"$notok\")"
# git current branch
git="\$( git branch 2> /dev/null | sed -n '/\\* /s///;s/^/ [/;s/$/]/p' )"
# virtualenv
virtualenv="\${VIRTUAL_ENV+\" (\$(basename \$VIRTUAL_ENV))\"}"
export VIRTUAL_ENV_DISABLE_PROMPT=1
# put only prompt on 2nd line
ln1="\[\033[01;37m\]\342\225\255 $cmdresult$virtualenv$git \u@\h:\w"
ln2="\[\033[01;37m\]\342\225\260 \$ "
PS1="${ln1}\n${ln2}\[\033[00m\]"
unset ok notok cmdresult ln1 ln2 git virtualenv
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment