/direnv-modules

Environment Modules-like interface for direnv

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

direnv Modules

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

https://asciinema.org/a/405131.svg

Setup

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.

Usage

Everything is handled by the dm (for direnv module) command. These are its sub commands:

avail

List all available modulefiles in the current DMODULEPATH

help

Print the usage of each sub-command. If an argument is given, print the Module-specific help information for the dmodulefile.

list

List loaded modules.

load modulefile…

Load modulefile into the shell environment.

purge

Unload all loaded modulefiles.

reload

Unload then load all loaded modulefiles.

unload modulefile…

Remove modulefile from the shell environment.