Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--use-on-cd not prompting when used with fish and tmux #1384

Open
maxjacobson opened this issue Feb 17, 2025 · 0 comments
Open

--use-on-cd not prompting when used with fish and tmux #1384

maxjacobson opened this issue Feb 17, 2025 · 0 comments

Comments

@maxjacobson
Copy link
Contributor

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:

  1. cd into a directory that has a .node-version file
  2. run tmux to start a new tmux session in the directory
  3. within the tmux session, use vim to edit .node-version to change to a newer node version
  4. <C-b> c to 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:

Image

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant