worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

Nushell wrapper reads its cd file with bare `open`, so a user `open` alias breaks `wt switch`

Open worktrunk-bot opened this issue 2 weeks ago • 1 comments

The Nushell wrapper reads its temp files with bare open (templates/nushell.nu lines 131 and 138–139). A user alias such as alias open = ^open (common on macOS, to reach the system open) resolves inside the wrapper function. So the wrapper runs macOS open on the cd file instead of reading it: wt switch prints "Switched" and the shell stays where it was.

This is the same shape as #3730, which fixed only the cleanup rm (now ^rm). The open reads need the same protection from user aliases.

Reported downstream in suddenlyGiovanni/dotfiles@19db264 ("The wt function from that file called macOS open where it meant nu's built-in, so wt switch printed "Switched" and stayed put"), found by the feedback digest (#4813).

Reproduction

With nu 0.117.0, an alias defined before a function applies inside it:

$ nu -c 'alias open = ^echo ALIASED; def t [] { open f.txt --raw }; t'
ALIASED f.txt --raw

The wrapper is defined in vendor autoload after config.nu, so a config.nu alias is in scope there.

worktrunk-bot avatar Nov 20 '26 18:11 worktrunk-bot

Reproduced and fixed in #4865. The wrapper now starts with hide open, so its temp-file reads use Nushell's builtin open even when config.nu aliases or redefines it. The user's alias still works outside the wrapper. The new regression test defines alias open = ^echo ALIASED before the wrapper loads. Without the fix it fails with 'ALIASED /tmp/tmp.… --raw' does not exist at the cd, and with the fix it passes. CI and codecov are green at the PR head, and it is waiting on maintainer review.

worktrunk-bot avatar Nov 20 '26 19:11 worktrunk-bot