Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-mice-skip-dms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fnm": patch
---

guard the documented shell setup snippets (and the installer-appended ones) behind an interactive-shell check so non-interactive logins, such as display managers scraping env vars at session start, no longer leak a stale `fnm_multishells` path into `$PATH`. Closes #1551.
15 changes: 12 additions & 3 deletions .ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ setup_shell() {
if [ "$USE_HOMEBREW" != "true" ]; then
echo ' export PATH="$FNM_PATH:$PATH"'
fi
echo ' eval "$(fnm env --shell zsh)"'
echo ' # only initialize for interactive shells; non-interactive logins'
echo ' # (e.g. display managers scraping env vars) would otherwise leak a'
echo ' # stale multishell into the session PATH.'
echo ' [[ $- == *i* ]] && eval "$(fnm env --shell zsh)"'
echo 'fi'
} | tee -a "$CONF_FILE"

Expand All @@ -193,7 +196,10 @@ setup_shell() {
if [ "$USE_HOMEBREW" != "true" ]; then
echo ' set PATH "$FNM_PATH" $PATH'
fi
echo ' fnm env --shell fish | source'
echo ' # only initialize for interactive shells; non-interactive logins'
echo ' # (e.g. display managers scraping env vars) would otherwise leak a'
echo ' # stale multishell into the session PATH.'
echo ' status is-interactive; and fnm env --shell fish | source'
echo 'end'
} | tee -a "$CONF_FILE"

Expand All @@ -213,7 +219,10 @@ setup_shell() {
if [ "$USE_HOMEBREW" != "true" ]; then
echo ' export PATH="$FNM_PATH:$PATH"'
fi
echo ' eval "$(fnm env --shell bash)"'
echo ' # only initialize for interactive shells; non-interactive logins'
echo ' # (e.g. display managers scraping env vars) would otherwise leak a'
echo ' # stale multishell into the session PATH.'
echo ' [[ $- == *i* ]] && eval "$(fnm env --shell bash)"'
echo 'fi'
} | tee -a "$CONF_FILE"

Expand Down
8 changes: 5 additions & 3 deletions .ci/test_installation_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ echo "---"
echo "PATH=$PATH"
echo "---"

$SHELL_TO_RUN -c "
# Use an interactive shell (-i) so the appended fnm setup, which is now guarded
# by an interactive-shell check, actually runs when the profile is sourced.
$SHELL_TO_RUN -i -c "
. $PROFILE_FILE
fnm --version
"

$SHELL_TO_RUN -c "
$SHELL_TO_RUN -i -c "
. $PROFILE_FILE
fnm install 12.5.0
fnm ls | grep 12.5.0

echo 'fnm ls worked.'
"

$SHELL_TO_RUN -c "
$SHELL_TO_RUN -i -c "
. $PROFILE_FILE
fnm use 12.5.0
node --version | grep 12.5.0
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,29 @@ Check out the following guides for the shell you use:
Add the following to your `.bashrc` profile:

```bash
eval "$(fnm env --use-on-cd --shell bash)"
# only run for interactive shells; non-interactive logins (e.g. display managers
# scraping env vars) would otherwise leave a stale multishell in the session PATH.
[[ $- == *i* ]] && eval "$(fnm env --use-on-cd --shell bash)"
```

#### Zsh

Add the following to your `.zshrc` profile:

```zsh
eval "$(fnm env --use-on-cd --shell zsh)"
# only run for interactive shells; non-interactive logins (e.g. display managers
# scraping env vars) would otherwise leave a stale multishell in the session PATH.
[[ $- == *i* ]] && eval "$(fnm env --use-on-cd --shell zsh)"
```

#### Fish shell

Create `~/.config/fish/conf.d/fnm.fish` and add this line to it:

```fish
fnm env --use-on-cd --shell fish | source
# only run for interactive shells; non-interactive logins (e.g. display managers
# scraping env vars) would otherwise leave a stale multishell in the session PATH.
status is-interactive; and fnm env --use-on-cd --shell fish | source
```

#### PowerShell
Expand Down