Skip to content

Instantly share code, notes, and snippets.

@Melindrea
Forked from presstube/gist:1299452
Last active December 13, 2015 21:18
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 Melindrea/4976359 to your computer and use it in GitHub Desktop.
Save Melindrea/4976359 to your computer and use it in GitHub Desktop.
Main update from the fork and the awesome post by opinionated programmer is that the default prompt is based on the Ubuntu one, and allows to show Python's virtual environment. Add the snippet to .bash_profile or .bashrc
# Snazzy git prompt
#http://www.opinionatedprogrammer.com/2011/01/colorful-bash-prompt-reflecting-git-status/
function _git_prompt() {
local git_status="`git status -unormal 2>&1`"
if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
if [[ "$git_status" =~ nothing\ to\ commit ]]; then
local ansi=42
elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then
local ansi=43
else
local ansi=45
fi
if [[ "$git_status" =~ On\ branch\ ([^[:space:]]+) ]]; then
branch=${BASH_REMATCH[1]}
test "$branch" != master || branch=' '
else
# Detached HEAD. (branch=HEAD is a faster alternative.)
branch="(`git describe --all --contains --abbrev=4 HEAD 2> /dev/null ||
echo HEAD`)"
fi
echo -n '\[\e[0;37;'"$ansi"';1m\]'"$branch"'\[\e[0m\] '
fi
}
function _python_env_prompt() {
# Virtual Env
if [[ $VIRTUAL_ENV != "" ]]
then
venv="(${VIRTUAL_ENV##*/}) "
else
venv=''
fi
echo -n ${venv}
}
function _prompt_command() {
PS1="`_python_env_prompt`""`_git_prompt`"'\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
}
PROMPT_COMMAND=_prompt_command
# end snazzy git prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment