Skip to content

Instantly share code, notes, and snippets.

@imba3r
Created October 14, 2014 15:47
Show Gist options
  • Save imba3r/1bcd38d276feff51a25f to your computer and use it in GitHub Desktop.
Save imba3r/1bcd38d276feff51a25f to your computer and use it in GitHub Desktop.
Bash PS1 with Git and Virtualenv support.
# PS1 (prompt) colors (colornames refer to jwr theme)
DF="\e[0m" # refault
BW="\e[1;37m" # bold white
BR="\e[1;31m" # bold red
BB="\e[1;34m" # bold blue
BC="\e[1;32m" # bold cyan
BL="\e[1;33m" # bold light red
[[ -n "$SSH_CLIENT" ]] && HC=$BR || HC=$BB
# prepare bash prompt git support
GIT_PROMPT_SH="/usr/share/git/completion/git-prompt.sh"
if [[ -x /usr/bin/git && -f $GIT_PROMPT_SH ]]; then
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export GIT_PS1_SHOWUPSTREAM=1
source $GIT_PROMPT_SH
GIT='$(__git_ps1 "─['$BR'%s'$DF']")'
fi
# prepare python virtual env (and it's prompt support)
VEV_WRAPPER_SH="/usr/bin/virtualenvwrapper.sh"
if [[ -x /usr/bin/virtualenv && -f $VEV_WRAPPER_SH ]]; then
export VIRTUAL_ENV_DISABLE_PROMPT=1
export WORKON_HOME="${HOME}/Development/virtualenvs"
mkdir -p "$WORKON_HOME"
source $VEV_WRAPPER_SH
function __venv_ps1 {
if [[ -n $VIRTUAL_ENV ]]; then
echo -e "─[${BL}$(basename $VIRTUAL_ENV)$DF]"
fi
}
VEV="\$(__venv_ps1)"
fi
# assemble the PS1
function set_bash_prompt {
PS1='┌─['$BW'\u'$DF'@'$HC'\h'$DF']─['$BC'\w'$DF']'$VEV''$GIT'\n└─╼ '
}
PROMPT_COMMAND="$PROMPT_COMMAND; set_bash_prompt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment