Skip to content

Instantly share code, notes, and snippets.

@robo-corg
Forked from bensonk/ps1.sh
Created May 23, 2012 23:31
Show Gist options
  • Save robo-corg/2778476 to your computer and use it in GitHub Desktop.
Save robo-corg/2778476 to your computer and use it in GitHub Desktop.
Python, mercurial, and git friendly prompt script for bash.
#!/bin/bash
# Put this in ~/bin/ps1, and make it executable
# Then add the following line to your .bashrc or .bash_profile:
# PROMPT_COMMAND="source $HOME/bin/ps1"
HG_BRANCH=`hg branch 2>&1`
if [[ $? == 0 ]]
then
VCS_PROMPT="\[\033[00;33m\](\[\033[00;37m\]$HG_BRANCH\[\033[00;33m\]) \[\033[01;34m\]"
else
VCS_PROMPT=""
fi
GIT_BRANCH=`git branch 2>&1`
if [[ $? == 0 && -z $VCS_PROMPT ]]
then
GIT_BRANCH=`git branch 2>&1 | grep \\* | cut -d ' ' -f 2`
VCS_PROMPT="\[\033[00;33m\](\[\033[00;37m\]$GIT_BRANCH\[\033[00;33m\]) \[\033[01;34m\]"
fi
if [[ -e $VIRTUAL_ENV ]]
then
ENVNAME=`echo $VIRTUAL_ENV | cut -d / -f 5`
VENV_PROMPT="\[\033[00;33m\][\[\033[00;37m\]$ENVNAME\[\033[00;33m\]] "
else
VENV_PROMPT=""
fi
export PS1="$VENV_PROMPT\[\033[01;32m\]\u@\h\[\033[01;34m\] \w $VCS_PROMPT$ \[\033[00m\]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment