fix: use builtin cd in fish shell integration - #3160
Merged
Conversation
The fish wrapper changed directory with a bare `cd -- "$target"`, which is interceptable by shell `cd` overrides. The kidonng/zoxide.fish plugin replaces `cd` with a zoxide query function; it sees the `--` separator as a query argument (argc=2) and falls through to fuzzy-query mode, failing with "zoxide: no match found" / "Error: Directory not found" even though the worktree exists. `builtin cd` bypasses any user `cd` function, matching what the bash and zsh wrappers already do. The target is an absolute path written by the binary, so the `--` is retained purely for consistency with bash/zsh. Closes #3159 Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
wt switch <branch>reported a successful switch but then failed to change directory under fish when thekidonng/zoxide.fishplugin is active, printingzoxide: no match found/Error: Directory not foundeven though the worktree exists (#3159).The fish integration changed directory with a bare
cd -- "$target".zoxide.fishreplacescdwith a zoxide query function. Withcd -- "$target"it receives two arguments (--and the path), so its single-directory fast path (argc -eq 1) is skipped and it falls through to fuzzy-query mode, which finds no match for-- /path/to/worktree.The bash and zsh wrappers were already immune because they use
builtin cd; only fish used a barecd.Solution
Use
builtin cd -- "$target"intemplates/fish.fish, bypassing any usercdoverride (verified: in fishcdis a regular function thatbuiltin cdskips). The--is retained for consistency with the bash/zsh wrappers; the target is an absolute path written by the binary, so it can never be flag-injected.Testing
test_fish_init_uses_builtin_cdinsrc/shell/mod.rs, which fails on the old template (cd -- "$target") and passes after the fix.src/shell/snapshots/...init_fish.snap,tests/snapshots/...init_fish.snap).3.7.0behavior directly:cdis a function,builtin cdandbuiltin cd --both succeed, andbuiltin cdbypasses a user-definedcdfunction (the simulated override was not invoked).cargo test --test integration test_docs_are_in_syncpasses.Closes #3159 — automated triage