Last active
August 29, 2015 13:55
-
-
Save kevinastone/8728554 to your computer and use it in GitHub Desktop.
Bash function and completion script to allow quick switching between projects (especially if they share a relative virtualenv dir)
This file contains 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
# Change this to your base projects path [$WORKON_BASE_DIR/{project1,project2,...}] | |
WORKON_BASE_DIR=/mnt/hgfs | |
# Change this to your relative virtual_env dir (if exists) [$WORKON_BASE_DIR/{project}/$VENV_DIR] | |
VENV_DIR=".env" | |
function workon() { | |
[ -z "$VIRTUAL_ENV" ] || deactivate | |
cd $WORKON_BASE_DIR/$1 && | |
[ -d $VENV_DIR ] && source $VENV_DIR/bin/activate | |
} | |
_workon() { | |
local cur prev opts | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" | |
words=("${COMP_WORDS[@]}") | |
[ $COMP_CWORD -gt 1 ] && return 0 | |
# COMPREPLY=( $(compgen -d -- ${cur}) ) | |
COMPREPLY=( $(compgen -W "$(for d in $WORKON_BASE_DIR/${cur}*; do [[ -d "$d" ]] && echo `basename $d`; done)" -- ${cur}) ) | |
return 0 | |
} | |
complete -F _workon workon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment