“direnv is an extension for your shell. It augments existing shells with a new feature that can load and unload environment variables depending on the current directory.”
“The Environment Modules package is a tool that simplify shell initialization and lets users easily modify their environment during the session with modulefiles. Modules can be loaded and unloaded dynamically and atomically, in an clean fashion.”
This is an Environment Modules-like interface built on top of direnv, for those who want the best of both worlds.
Here’s a quick demo
Create dmodulefiles in a directory structure like this:
mkdir /opt/dmodulefiles
mkdir /opt/dmodulefiles/tool_a
mkdir /opt/dmodulefiles/tool_b
Inside the tool_a and tool_b directories, create text files named for the version of the tool the dmodulefile is for. In that text file write shell syntax code to set environment variable that are needed by the tool. For example, in /opt/dmodulefiles/tools_a/1.3
you might have:
export PATH=/path/to/tool_a/bin:$PATH
export LM_LICENSE_FILE=4567@license_server
Then, in your ~/.profile
add this line:
export DMODULEPATH=/top/dmodulefiles
Then copy dm
and dm-editor
to some directory in your PATH
.
Everything is handled by the dm
(for direnv module) command. These are its sub commands:
List all available modulefiles in the current DMODULEPATH
Print the usage of each sub-command. If an argument is given, print the Module-specific help information for the dmodulefile.
List loaded modules.
Load modulefile into the shell environment.
Unload all loaded modulefiles.
Unload then load all loaded modulefiles.
Remove modulefile from the shell environment.