Skip to content

fix: use builtin cd in fish shell integration - #3160

Merged
max-sixty merged 2 commits into
mainfrom
fix/issue-3159
Jun 23, 2026
Merged

fix: use builtin cd in fish shell integration#3160
max-sixty merged 2 commits into
mainfrom
fix/issue-3159

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Problem

wt switch <branch> reported a successful switch but then failed to change directory under fish when the kidonng/zoxide.fish plugin is active, printing zoxide: no match found / Error: Directory not found even though the worktree exists (#3159).

The fish integration changed directory with a bare cd -- "$target". zoxide.fish replaces cd with a zoxide query function. With cd -- "$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 bare cd.

Solution

Use builtin cd -- "$target" in templates/fish.fish, bypassing any user cd override (verified: in fish cd is a regular function that builtin cd skips). 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

  • Added test_fish_init_uses_builtin_cd in src/shell/mod.rs, which fails on the old template (cd -- "$target") and passes after the fix.
  • Updated the fish init snapshots (src/shell/snapshots/...init_fish.snap, tests/snapshots/...init_fish.snap).
  • Verified fish 3.7.0 behavior directly: cd is a function, builtin cd and builtin cd -- both succeed, and builtin cd bypasses a user-defined cd function (the simulated override was not invoked).
  • cargo test --test integration test_docs_are_in_sync passes.

Closes #3159 — automated triage

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>
@max-sixty
max-sixty enabled auto-merge (squash) June 23, 2026 16:39
@max-sixty
max-sixty merged commit 03dbf5f into main Jun 23, 2026
35 checks passed
@max-sixty
max-sixty deleted the fix/issue-3159 branch June 23, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-fix Automated CI fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug report: wt switch fails in fish shell with zoxide integration

2 participants