oh-my-dir is a set of configuration files for direnv that add high-level functions to create isolated, per-directory virtual environments for various software stacks such as programming languages and package managers.
oh-my-dir automatically set up your stack(s) whenever you enter your project directory, taking care of several otherwise time consuming steps:
- Installation of a stack-specific manager (if not already present)
- Installation of the requested version of the stack (if not already present)
- Creation of a named environment (if not already present)
- Modification of environment variables to use this stack and environment
If you are familiar with tools such as virtualenv, rbenv or perlbrew then oh-my-dir is a higher-level environment manager. In fact, it probably uses these tools behind the scene.
There are only three steps involved in the installation of oh-my-dir:
- Install direnv if not done already (various platform-specific binaries are available)
- Download and unzip the latest archive from the oh-my-dir repository, or clone it
- Once in the oh-my-dir source folder, run
make install
Note:
make install
will overwrite any existing~/.direnvrc
file; if you want to manually merge your file with the oh-my-dir functions, you can runmake build
instead and copy all or part of the newly created filedist/direnvrc
in your existing~/.direnvrc
.
- In your project directory, create a
.envrc
file with your favorite editor and add one or moreuse stack
instructions, withstack
being the name of the stack optionally followed by a version number and an environment name (not all stacks support these options; please refer to the table in the last section). - Then tell direnv to use your file by typing
direnv allow
, and oh-my-dir will switch to your stack and environment (or install/create it if needed).
Note: a shortcut to the
.envrc
editing/allow cycle is to typedirenv edit .
, which will launch $EDITOR and automatically allow the resulting content.
For example if you want your project to use the version 2.7.10 of the Python interpreter just add use python 2.7.10
in your <project>/.envrc
file. oh-my-dir will check (and install if needed) for a Python-specific manager (here pyenv), the specified version of the Python interpreter, and an environment named default
in <project>/.env/
(default name for the environment if none provided). The relevant environment variables will be set for you to use this named environment:
$ cd my_project
$ direnv edit . # added 'use python 2.7.10'
direnv: loading ~/.direnvrc
direnv: loading .envrc
direnv: using python 2.7.10
preparing Python environment 'default'
New python executable in my_project/.env/pyenv-2.7.10-default/bin/python2.7
Also creating executable in my_project/.env/pyenv-2.7.10-default/bin/python
Installing setuptools, pip, wheel...
done.
direnv: export +PYENV_ROOT +PYENV_VERSION +PYENV_VIRTUALENV_DISABLE_PROMPT +VIRTUAL_ENV ~PATH
$ which python
my_project/.env/pyenv-2.7.10-default/bin/python
Note: while creating your environment direnv will likely complain that its initialization take too long, with a message such as
direnv is taking a while to execute. Use CTRL-C to give up
, which you can safely ignore.
If you want to maintain (and automatically switch to) multiple named environments in your project, just add a name (e.g., use python 2.7.10 production
).
Note: the various oh-my-dir functions will use (and create if needed) a
~/.direnv
folder to store the stack-specific managers, and a<project>/.env
folder to store the various named environments you created.
Stack | Underlying manager |
Enforce stack version?1 |
Allow named environments?2 |
Relocatable?3 | Supported platforms |
Status |
---|---|---|---|---|---|---|
Docker machine | n/a | ❌ | ✔️ | n/a | Unix, OSX | Stable |
Julia | playground.jl | ✔️ | ✔️ | untested | Unix, OSX | Beta |
Perl | perlbrew | ✔️ | ✔️ | untested | Unix, OSX | Stable |
Python | pyenv | ✔️ | ✔️ | ❌ | Unix, OSX | Stable |
Rust | rsvm | ✔️ | ❌ | ✔️ | Unix, OSX | Stable |
Conda | n/a | ❌ | ✔️ | ❌ | Unix, OSX | Beta |
1: means that the underlying manager can switch to, and install if necessary, a specific version of the stack
2: means that the underlying manager can switch to, and created if necessary, a named environment for the current stack and version
3: means that the project folder can be safely moved elsewhere without breaking the environments