]> Vexing Labs - dotfiles.git/commitdiff
Update .bash_profile for Python dev - add activate function for virtual environments...
authorAdam A.G. Shamblin <adam.shamblin@imulus.com>
Tue, 24 Jun 2014 20:36:51 +0000 (14:36 -0600)
committerAdam A.G. Shamblin <adam.shamblin@imulus.com>
Tue, 24 Jun 2014 20:36:51 +0000 (14:36 -0600)
dotbash_profile

index 43fa9cdba7407f43f8085b676cd5d44255202d30..f8528b0365bca73a5d2381aafe8226db8f3708a5 100644 (file)
@@ -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*