Skip to content

Activate environments when you change directory

This page shows how to make your shell switch a project's environment on when you enter the project's directory and off when you leave, the way direnv does.

Before you start

Steps

1. Load the hook

Load the hook from your shell's start-up file, once:

Add to ~/.bashrc:

eval "$(repro shell hook bash)"

2. Open a new shell

Open a new shell, so the start-up file runs.

3. Allow the project directory

Enter the project's directory and allow it:

cd my-project
repro allow

The environment switches on. From now on it switches on whenever you enter this directory, and off when you leave it.

Danger

Trust follows the directory, not its contents. After repro allow, a change to the project's repro.nim, such as one that arrives with git pull, takes effect the next time you enter the directory, without asking you again. Allow only directories whose changes you would run yourself.

Withdraw trust

In the project's directory, run:

repro deny

The hook no longer activates the environment there. repro allow and repro deny also take a directory as an argument.

Skip the trust check where no one can answer it

In CI and other non-interactive shells, set REPRO_DEV_ENV_AUTO_ALLOW=1 to activate environments without repro allow.

Danger

With REPRO_DEV_ENV_AUTO_ALLOW=1, every directory with a project file is activated, including one you have never inspected. Set it only in a disposable environment that runs code you already trust.

Check that it worked

Enter the project directory and run a tool the project declares, such as its compiler, with --version. Leave the directory and run it again: the version changes back to your system's, or the command is not found.