Shell integration
The composed environment reaches your shell in one of two ways: a hook that
nem activate installs for interactive use, or nem exec and nem env for
scripts and CI. Neither uses shims; a package is on PATH only while it
applies.
There are two ways to bring the composed environment into your work: a
shell hook for interactive, day-to-day use, and nem exec / nem env for
scripts and CI. Neither uses shims — a package is only on your PATH for as
long as it applies.
Installing the hook
nem activate # zsh or bash
exec $SHELLnem activate [zsh|bash] appends a managed block to .zshrc or .bashrc,
between # >>> nem >>> and # <<< nem <<< markers. nem deactivate removes
it. Restart the shell (exec $SHELL) so the block takes effect.
Use nem activate --print to print the block to stdout instead of
installing it — also the default whenever stdout isn't a terminal, so
eval "$(nem activate --print)" works from another program's init script.
What the hook does
The installed block:
- Saves the shell's original
PATHonce, before nem starts changing it; - Registers a hook that re-evaluates
eval "$(nem env --shell <shell>)": zsh'schpwdruns it on everycd, bash'sPROMPT_COMMANDbefore every prompt; - Wraps the
nemcommand souse,unuse,lock,sync, andupdatere-apply the environment immediately, without waiting for the next directory change; - Sources
nem's shell completions.
Leaving restores everything
The script that nem env prints tracks every variable it manages, together
with the value — or absence — it had before nem touched it. Leaving a
project, or deactivating nem altogether, restores each one exactly:
variables nem changed go back to their saved value, and variables nem set
that didn't exist before are unset. PATH entries are deduplicated on
the way in, so re-evaluating the hook repeatedly never grows PATH.
Scripts and CI
Outside an interactive shell, two commands give you the same composed environment without installing anything:
nem exec -- <cmd> [args...] # run one command in the composed environment
nem env --shell bash # print the script to eval insteadnem exec runs the command as a child process and exits with its exact
status, which makes it the one to reach for in scripts and CI steps. nem env prints the shell script that applies the environment; eval it when you
need the environment in the current shell rather than a subprocess.
nem env support zsh and bash. fish is not supported yet.