From: Adam A.G. Shamblin Date: Tue, 24 Jun 2014 20:36:51 +0000 (-0600) Subject: Update .bash_profile for Python dev - add activate function for virtual environments... X-Git-Url: https://git.vexinglabs.com/?a=commitdiff_plain;h=a2833e1fc542f3014a2ecfd6d4b6c56163525b2a;p=dotfiles.git Update .bash_profile for Python dev - add activate function for virtual environments and tab completion on virtual environment directories. --- diff --git a/dotbash_profile b/dotbash_profile index 43fa9cd..f8528b0 100644 --- a/dotbash_profile +++ b/dotbash_profile @@ -1,5 +1,6 @@ export CLICOLOR=1 export PYTHONPATH="/usr/local/lib/python2.7/site-packages:$PYTHONPATH" +export PYTHON_ENV_PATH=$HOME/env export GRADLE_HOME=$HOME/bin/gradle export ANDROID_PATH=/Applications/Android\ Studio.app/sdk/platform-tools:/Applications/Android\ Studio.app/sdk/tools export POSTGRES_PATH=/Applications/Postgres.app/Contents/Versions/9.3/bin @@ -15,6 +16,10 @@ if [ -f /usr/local/git/contrib/completion/git-completion.bash ]; then . /usr/local/git/contrib/completion/git-completion.bash fi +if [ -f /usr/local/etc/bash_completion.d/rabbitmqadmin.bash ]; then + . /usr/local/etc/bash_completion.d/rabbitmqadmin.bash +fi + # Change the prompt character when encountering git repositories function prompt_char { if ! git rev-parse --git-dir > /dev/null 2>&1; then @@ -25,23 +30,27 @@ function prompt_char { git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p') echo "($git_branch) $" } +export PS1='\[$ORANGE\]\u\[$RESET\] @ \[$YELLOW\]\h\[$RESET\] in \[$GREEN\]\w\[$RESET\]\n\[$BASE2\]$(prompt_char)\[$RESET\] ' -# Automatically activate virtualenv when encountered, -# deactivate on exit -function activate_env { - HAS_DEACTIVATE=`type -t deactivate` +function activate () { + command source $PYTHON_ENV_PATH/$1/bin/activate +} - if [ -e env/bin/activate ] && [ "${#VIRTUAL_ENV}" -eq 0 ]; then - source env/bin/activate; - elif [ ! -e env/bin/activate ] && [ "${#HAS_DEACTIVATE}" -ne 0 ]; then - deactivate; - fi +function _envdir () { + IFS=' + ' - unset HAS_DEACTIVATE -} -export PROMPT_COMMAND=activate_env -export PS1='\[$ORANGE\]\u\[$RESET\] @ \[$YELLOW\]\h\[$RESET\] in \[$GREEN\]\w\[$RESET\]\n\[$BASE2\]$(prompt_char)\[$RESET\] ' + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts=`ls $PYTHON_ENV_PATH` + + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 +} +complete -F _envdir activate [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*