Skip to content

Instantly share code, notes, and snippets.

@hersonls
Last active October 7, 2015 23:47
Show Gist options
  • Save hersonls/3243814 to your computer and use it in GitHub Desktop.
Save hersonls/3243814 to your computer and use it in GitHub Desktop.
Show git branch on bash prompt
## My alias
# mkpass - Generate random string with 12 chars
alias mkpass='python -c "import random, string; print \"\".join(random.choice(string.ascii_letters + string.digits + \"[]\") for x in range(12))"'
## Virtualenvwrapper Settings
VIRTUALENVWRAPPER=`which virtualenvwrapper.sh`
export WORKON_HOME=$HOME/.virtualenvs
if [ -f ${VIRTUALENVWRAPPER} ]; then
source ${VIRTUALENVWRAPPER}
fi
## PIP Settings
export PIP_DOWNLOAD_CACHE=$HOME/.pip_download_cache/
## Print the current branch if current dir is a git repo.
function git_branch {
if git ls-files >& /dev/null; then
branch_name="`git branch | grep '*'`"
if [ -z "$branch_name" ]; then
branch_name="no_branch"
fi
echo " [git:${branch_name//[*\ ]/}]"
fi
}
## Shell settings
export PS1='\[\e[00;37m\]`git_branch`\[\e[0m\]\[\033[0;36m\] \w - \u\$\[\e[0m\] '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment