Last active
December 28, 2015 06:39
-
-
Save ivanalejandro0/7459160 to your computer and use it in GitHub Desktop.
My custom PS1 prompt with virtualenv and git support.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define some colors | |
RED="\[\e[0;38;5;196m\]" | |
GREEN="\[\e[01;32m\]" | |
BLUE="\[\e[01;34m\]" | |
WHITE="\[\e[37;1m\]" | |
LIGHT_BLUE="\[\e[36m\]" | |
PURPLE="\[\e[35m\]" | |
NIL="\[\e[m\]" | |
function git_branch(){ | |
# https://gist.github.com/henrik/31631 | |
branch=$(git symbolic-ref HEAD 2>/dev/null) | |
if [[ -z $branch ]]; then return; fi | |
branch=${branch#refs/heads/} # apparently faster than sed | |
dirty="" | |
if [[ -n "`git status --porcelain 2>/dev/null`" ]]; then | |
dirty="${RED}✘${NIL}" | |
else | |
dirty="${GREEN}✔${NIL}" | |
fi | |
echo -e "(git:${branch} ${dirty}) " | |
} | |
function virtualenv_info(){ | |
# Get Virtual Env | |
if [[ -n "$VIRTUAL_ENV" ]]; then | |
# Strip out the path and just leave the env name | |
venv="${VIRTUAL_ENV##*/}" | |
else | |
# In case you don't have one activated | |
venv='' | |
fi | |
[[ -n "$venv" ]] && echo "(venv:$venv) " | |
} | |
function set_custom_ps1(){ | |
# This is set in order to disable the default (virtualenv_name) prefix in PS1 | |
export VIRTUAL_ENV_DISABLE_PROMPT=1 | |
local USER="${PURPLE}\u${NIL}" | |
local CURRENT_PATH="${LIGHT_BLUE}[\w]${NIL}" | |
local VENV="\$(virtualenv_info)"; | |
# local GIT="\$(git_branch)"; | |
local ARROW="${WHITE}➜${NIL}" | |
export PS1="${USER} in ${CURRENT_PATH}\n${VENV}$(git_branch)${ARROW} ${NIL}" | |
export PS2="${ARROW}${NIL} " | |
export CUSTOM_PS1_LOADED=1 | |
} | |
PROMPT_COMMAND=set_custom_ps1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment