Skip to content

Conversation

@Mado13
Copy link
Contributor

@Mado13 Mado13 commented Oct 28, 2025

Problem

When opening a new Fish shell tab in the same directory (e.g., in WezTerm or other terminal emulators), the Ruby version was not automatically set based on .ruby-version. Users had to cd out and back into the directory to trigger the version switch.

Root Cause

The Fish shell init script only defined a --on-variable PWD hook, which triggers when the working directory changes. However, when a new shell starts in a directory, $PWD is set but never "changes", so the hook never fires.

Solution

Call _rv_autoload_hook immediately after defining it, matching the behavior already implemented for Zsh and Bash shells. This ensures the Ruby version is activated on shell startup, not just on directory changes.

Changes

  • Modified crates/rv/src/commands/shell/init.rs to call _rv_autoload_hook after function definition in Fish shell
  • All existing tests pass

Testing

Before:

$ rv shell init fish
function _rv_autoload_hook --on-variable PWD --description 'Change Ruby version on directory change using rv'
    status --is-command-substitution; and return
    /opt/homebrew/bin/rv shell env fish | source
end

After:

$ rv shell init fish
function _rv_autoload_hook --on-variable PWD --description 'Change Ruby version on directory change using rv'
    status --is-command-substitution; and return
    /opt/homebrew/bin/rv shell env fish | source
end
_rv_autoload_hook

Verified that opening new tabs in the same directory now correctly activates the Ruby version specified in .ruby-version.

- Call _rv_autoload_hook after defining it in Fish init
- Matches existing behavior in Zsh and Bash shells
- Fixes issue where new tabs in same directory don't activate Ruby version
@codecov
Copy link

codecov bot commented Oct 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@indirect
Copy link
Member

Nice, thanks!

@indirect indirect added this pull request to the merge queue Oct 29, 2025
Merged via the queue into spinel-coop:main with commit b2034f6 Oct 29, 2025
18 checks passed
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

Successfully merging this pull request may close these issues.

2 participants