Is there the reverse of "eval `opam env`"

Hi all,

In bash, you type:

eval `opam env`

Then your environment is configured to use opam and opam-installed software.

Is there a command to do the reverse?
I.e. unload this opam env from your environment?

Thanks,
F.

I don’t think there is a fully robust solution, other than to spawn a subshell prior to evaluating opam env, and then exiting the subshell to unload the configuration. When changing switches, opam does it’s best to unload the settings of one before applying those of the next, but it is not bullet-proof.

See for example the related discussion here.

Are you looking for something like opam env --revert?

2 Likes

Does eval `opam env --revert` undo the effects of setenv clauses in opam files, for example such as this? (Apologies for the tangent to the OP.)

What I do is opam exec -- bash to launch a subshell with the right environment, and exit to revert to the original shell.

Cheers,
Nicolas

Yes, It should reverse setenv: field. You can test in your terminal by diffing opam env and opam env --revert outputs.

Maybe (in bash):

eval `opam env --revert`

Nice, but that’s just a workaround.