diff options
-rw-r--r-- | README.md | 12 | ||||
-rwxr-xr-x | venvworkon.sh | 13 |
2 files changed, 22 insertions, 3 deletions
@@ -12,11 +12,21 @@ Put the `venvworkon.sh` script somewhere and source it in your ## Usage The script only supports one usage mode: - $ workon [environment] + $ workon [environment] [python version] If *environment* is not provided, then the list of existing venvs will be printed instead. +## Choosing the python version +The python you want to use must exist in the `$PATH` and start with +`python`. Pass the version suffix of the executable as the second +argument to the script. It'll be translated like so when creating +the venv: + +``` +workon foo 3.6 => python3.6 -m venv $WORKON_HOME/foo +``` + ## Where venvs are created When `workon` is called, venvs are created or loaded from the `$HOME/.venv` folder by default. diff --git a/venvworkon.sh b/venvworkon.sh index d714936..ad0090e 100755 --- a/venvworkon.sh +++ b/venvworkon.sh @@ -12,20 +12,29 @@ workon() { # Quit if there is no arguments, while showing available venvs if [ "$#" -lt "1" ]; then - ls "$WORKON_HOME" + echo "Usage: workon ENV_NAME PYTHON_VERSION" + echo "Available envs:" + ls "$WORKON_HOME" return fi envdir="$WORKON_HOME/$1" + python_version="3" if [ "$1" == "." ]; then target=$(basename `pwd`) envdir="$WORKON_HOME/$target" fi + if [ "$#" -gt "1" ]; then + python_version=$2 + fi + + python_exec="python$python_version" + # Creates virtual env if doesn't exists if [ ! -e "$envdir" ]; then - python3 -m venv $envdir + $python_exec -m venv $envdir echo "Virtual env created in $envdir" fi |