Skip to content

Instantly share code, notes, and snippets.

@dgarana
Last active December 19, 2018 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgarana/9b8d06c0d3ff2cf167ff94d4300f1c5a to your computer and use it in GitHub Desktop.
Save dgarana/9b8d06c0d3ff2cf167ff94d4300f1c5a to your computer and use it in GitHub Desktop.
Bash config with git/virtualenv prompt (including current python version on venv)
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
FG_RED="\033[38;5;9m"
FG_YELLOW="\033[0;33m"
FG_GREEN="\033[0;32m"
FG_OCHRE="\033[38;5;110m"
FG_BLUE="\033[0;34m"
FG_WHITE="\033[0;37m"
FG_RESET="\033[0m"
FG_DARK_BLUE="\033[38;5;6m"
FG_LIGHT_BLUE="\033[38;5;195m"
RESET_ALL="\e[0m"
NEWLINE="\n"
function git_color {
local git_status="$(git status 2> /dev/null)"
if [[ ! $git_status =~ "working tree clean" ]]; then
echo -e $FG_RED
elif [[ $git_status =~ "Your branch is ahead of" ]]; then
echo -e $FG_YELLOW
elif [[ $git_status =~ "nothing to commit" ]]; then
echo -e $FG_GREEN
else
echo -e $FG_OCHRE
fi
}
function git_branch {
local git_status="$(git status 2> /dev/null)"
local on_branch="On branch ([^${IFS}]*)"
local on_commit="HEAD detached at ([^${IFS}]*)"
if [[ $git_status =~ $on_branch ]]; then
local branch=${BASH_REMATCH[1]}
echo -e "$FG_WHITE ~ $(git_color)$branch$FG_WHITE"
elif [[ $git_status =~ $on_commit ]]; then
local commit=${BASH_REMATCH[1]}
echo -e "$FG_WHITE ~ $(git_color)$commit$FG_WHITE"
fi
}
source ~/.bashd/venv_prompt.sh
# Enable the virtualenv
function virtualenv_info(){
# Get Virtual Env
if [[ -n "$VIRTUAL_ENV" ]]; then
# Strip out the path and just leave the env name
venv="${VIRTUAL_ENV##*/}"
py=`python --version 2>&1`
else
# In case you don't have one activated
venv=''
fi
[[ -n "$venv" ]] && echo -e "$FG_WHITE[$FG_OCHRE$venv$FG_WHITE-$FG_YELLOW$py$FG_WHITE]"
}
# disable the default virtualenv prompt change
export VIRTUAL_ENV_DISABLE_PROMPT=1
export PS1="\n\$(virtualenv_info)\$(git_branch)$RESET_ALL\n$FG_RED[$FG_WHITE\t$FG_RED] \u$FG_YELLOW@$FG_OCHRE\h $FG_DARK_BLUE[$FG_LIGHT_BLUE\w$FG_DARK_BLUE]$RESET_ALL\n"
# This is used to autochange to directory using virtualenv postactivate
export PROJECT_FOLDER=~/Projects
# This file should go under ~/.virtualenvs/postactivate
# It just looks for a directory named as the virtualenv and moves there
#!/bin/bash
# This hook is sourced after every virtualenv is activated.
export VENV_NAME=`basename $VIRTUAL_ENV`
export VENV_PATH=`find $PROJECT_FOLDER -type d -name "$VENV_NAME" | head -n 1`
#export VENV_PATH=~/Projects/$VENV_NAME
if [ -d $VENV_PATH ]; then
cd $VENV_PATH
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment