Shell Integration
How enx integrates with your shell to enable features like enx cd.
Table of Contents
- TOC
Why Shell Integration?
A child process cannot change the parent shell’s working directory. This means enx cd can’t directly cd you into a project — it needs a shell wrapper function that captures the output and calls the shell’s built-in cd.
enx setup detects your shell and installs this wrapper automatically. If you need to set it up manually, see the snippets below.
Automatic Setup
When you run enx setup, it detects your shell and appends the appropriate wrapper function to your shell configuration file:
| Shell | Config file |
|---|---|
| Bash | ~/.bashrc |
| Zsh | ~/.zshrc |
| Fish | ~/.config/fish/config.fish |
| PowerShell | $PROFILE |
If shell integration doesn’t take effect immediately, restart your shell or source the config file (e.g.
source ~/.bashrc).
Manual Setup
Bash / Zsh
Add this to your ~/.bashrc or ~/.zshrc:
enx() {
if [ "$1" = "cd" ]; then
shift
local dir
dir=$(command enx cd "$@")
if [ $? -eq 0 ]; then
cd "$dir" || return 1
else
return 1
fi
else
command enx "$@"
fi
}
Fish
Add this to ~/.config/fish/config.fish:
function enx
if test "$argv[1]" = "cd"
set dir (command enx cd $argv[2..])
and cd $dir
else
command enx $argv
end
end
PowerShell
Add this to your PowerShell profile ($PROFILE):
function enx {
if ($args[0] -eq "cd") {
$dir = & enx.exe cd @($args[1..($args.Length-1)])
if ($LASTEXITCODE -eq 0) { Set-Location $dir }
} else {
& enx.exe @args
}
}
How It Works
The wrapper function intercepts calls to enx:
- If the first argument is
cd, it runscommand enx cd <args>— the actual binary - The binary prints the matched project’s path to stdout
- The wrapper captures that path and calls the shell’s built-in
cd - For all other subcommands, the wrapper passes through to the binary directly
This means enx cd works transparently — you type enx cd api and your shell changes directory, even though the enx binary itself can’t do that.
All other enx commands work without shell integration. Only
enx cdrequires the wrapper function.
Verifying Integration
After setup, test that it works:
# Register a project if you haven't already
enx init
# Navigate away and back
cd /tmp
enx cd my-project
pwd # should show your project's path
If pwd shows the correct path, shell integration is working.