Created
October 16, 2009 20:05
-
-
Save Apreche/212034 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# git_venv_bash_prompt.sh | |
# | |
# This builds a bash prompt that is aware of git and virtualenv | |
# | |
# to make this work put this file somewhere on your machine | |
# then put the following line in your .bashrc | |
# source /path/to/git_venv_bash_prompt.sh | |
# bash colors | |
RED="\[\033[1;31m\]" | |
GREEN="\[\033[1;32m\]" | |
BLUE="\[\033[1;34m\]" | |
MAGENTA="\[\033[1;35m\]" | |
CYAN="\[\033[1;36m\]" | |
WHITE="\[\033[1;37m\]" | |
GRAY="\[\033[0;37m\]" | |
NOCO="\[\e[0m\]" | |
# get current branch | |
function parse_git_branch { | |
git branch | awk '/^\*/ { print $2 }' | |
} | |
# get whether or not git is dirty | |
function parse_git_dirty { | |
git diff --quiet || echo "${RED}▒~^${NOCO}" | |
} | |
# get the part of the prompt for git | |
function get_git_prompt { | |
git branch &> /dev/null || return 1 | |
echo " [${CYAN}$(parse_git_branch)$(parse_git_dirty)${NOCO}]" | |
} | |
# get the part of the prompt for virtualenv | |
function get_venv { | |
if [ $VIRTUAL_ENV ] | |
then | |
echo " ${MAGENTA}`basename \"$VIRTUAL_ENV\"`${NOCO}" | |
fi | |
} | |
# sloppily build the entire prompt | |
function prompt_func { | |
prompta="${GREEN}\u${GRAY}@" | |
promptb="${BLUE}\h${GRAY} : ${WHITE}\w${NOCO}" | |
promptc="$(get_venv)$(get_git_prompt) ${WHITE}\$${NOCO}" | |
PS1="${prompta}${promptb}${promptc}${NOCO}\n" | |
} | |
PROMPT_COMMAND=prompt_func |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment