-
Notifications
You must be signed in to change notification settings - Fork 610
Description
I'm using fish 4.0b1 with this in my shell initialization config:
fnm env --use-on-cd --shell fish --log-level quiet --corepack-enabled | source(This is fnm 1.38.1)
In general the --use-on-cd behavior works great. But there's one specific scenario where it doesn't seem to notice that the version has changed:
cdinto a directory that has a.node-versionfile- run
tmuxto start a new tmux session in the directory - within the tmux session, use vim to edit
.node-versionto change to a newer node version <C-b> cto create a new tmux window, also in the same directory
My expected behavior is that the new tmux window will run my shell initialization code, which includes source-ing that fnm env code. At that point, fnm should prompt me to install the newer version of node.
The actual behavior is that fnm does not prompt me to install the newer version of node:
I can run cd . to cause fnm to notice that the file has changed and prompt me to install the newer version.
I spent a few mins trying to debug this but I'm coming up short. I see that this is the code that is being sourced:
set -gx PATH "/Users/max/.local/state/fnm_multishells/82992_1739813281436/bin" $PATH;
set -gx FNM_MULTISHELL_PATH "/Users/max/.local/state/fnm_multishells/82992_1739813281436";
set -gx FNM_VERSION_FILE_STRATEGY "local";
set -gx FNM_DIR "/Users/max/.fnm";
set -gx FNM_LOGLEVEL "quiet";
set -gx FNM_NODE_DIST_MIRROR "https://nodejs.org/dist";
set -gx FNM_COREPACK_ENABLED "true";
set -gx FNM_RESOLVE_ENGINES "true";
set -gx FNM_ARCH "arm64";
function _fnm_autoload_hook --on-variable PWD --description 'Change Node version on directory change'
status --is-command-substitution; and return
if test -f .node-version -o -f .nvmrc -o -f package.json
fnm use --silent-if-unchanged
end
end
_fnm_autoload_hook
(Tangent: this was hard to read at first because the indentation is wrong. Might be a small win to make the indentation more human-readable, even if fish interprets it correctly without issue)
This _fnm_autoload_hook function is called once at the bottom each time a shell is initialized, and then again whenever $PWD changes. When opening a new tmux window, $PWD does not change, so it makes sense that the function isn't triggered due to the --on-variable PWD hook. But the shell is initialized, and so that last line which calls the function once on initialization should run. So the function should be called. And indeed, I'm fairly certain that it is called. I made this patch to fnm and installed it from source:
diff --git a/src/shell/fish.rs b/src/shell/fish.rs
index f63c088..5fcc4fe 100644
--- a/src/shell/fish.rs
+++ b/src/shell/fish.rs
@@ -35,6 +35,7 @@ impl Shell for Fish {
VersionFileStrategy::Local => formatdoc!(
r#"
if {version_file_exists_condition}
+ echo "calling fnm use --silent-if-unchanged"
fnm use --silent-if-unchanged
end
"#,And I can see that this line of code is reached during shell initialization when creating new tmux windows. Nevertheless, I am not prompted to install the new version of node. If I try running fnm use --silent-if-unchanged at the prompt, it of course does prompt me to install the new version without issue.
So I think I am stumped... any ideas?
