/ Published in: Bash
URL: http://webjournal.nerdfiles.net/2012/11/14/work-that-is-workon-in-python/
"work" with a Python virtual environment of the current dir.
Expand |
Embed | Plain Text
function work() { :<<FUNC_WORK "work" with a Python virtual environment of the current dir. @assumes: Basic shared name between environment and project folder; so, e.g.: #File .bashrc contains: $WORKON_HOME=$HOME/.virtualenvs/shared_name $PROJECT_HOME=$HOME/Projects/shared_name @usage: $ cd /path/to/dir $ work $ cd /path/to/dir $ work scss #see http://snipplr.com/view/68643/a-work-file-example/ $ git status #e.g. (compass will continue crunching, just ctrl+c after mods to SCSS files) FUNC_WORK # Development debug=0 if [ "$1" == "scss" ]; then workon_scss=$1 if [[ -f ".work" ]]; then source .work fi fi # Get the current directory. # Underscores and periods are dealt with as per, what it seems, # virtualenv's naming conventions. I have no fully tested this. old="$PWD" cur="$PWD" # Store IFS OLDIFS=$IFS set -- "$cur" IFS="/"; declare -a pwdarray=($*) len=${#pwdarray[@]} len=($len-1) proj=${pwdarray[$len]} proj=${proj/"-"/"_"} proj=${proj/"."/""} # Get the virtual env by a shared name with the project folder. env_proj="$(find "$WORKON_HOME" -type d -maxdepth 1 -iname '*'$proj'*' -print)" set -- "$env_proj" IFS="/"; declare -a envarray=($*) lenw=${#envarray[@]} lenw=($len) proj_env=${envarray[$lenw]} # I'm assuming one has set their markdown editor, like Byword. if [[ -f "$PWD/readme.markdown" ]]; then open readme.markdown elif [[ -f "$PWD/README.md" ]]; then open README.md fi # assuming python; that is #ideas workon $proj_env # Reset IFS IFS=$OLDIFS # Display printf "\nWorking on [$proj_env]...\n---" printf "\nEnvironment: $(py?)" printf "\nParking at yr repo...\n" git status }
You need to login to post a comment.
