Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix(nushell): switch wrapper to @complete attribute on untyped rest (#2458)

Maximilian Roosfdc6df61b927
diff --git a/src/shell/snapshots/worktrunk__shell__tests__init_nu.snap b/src/shell/snapshots/worktrunk__shell__tests__init_nu.snap
index 10ddca5fd..1e59d694f 100644
--- a/src/shell/snapshots/worktrunk__shell__tests__init_nu.snap
+++ b/src/shell/snapshots/worktrunk__shell__tests__init_nu.snap
@@ -8,7 +8,7 @@ expression: output
# Note: nushell's completion engine bypasses custom completers when the current
# token starts with `-`, so flag completions (e.g. `wt switch --<TAB>`) don't
# appear. Subcommand and value completions work. (nushell/nushell#14504)
-export def "nu-complete wt" [context: string] {
+export def "nu-complete wt" [spans: list<string>] {
let worktrunk_bin = if ($env.WORKTRUNK_BIN? | is-not-empty) {
$env.WORKTRUNK_BIN
} else {
@@ -17,15 +17,8 @@ export def "nu-complete wt" [context: string] {
($external | get 0.path)
}
- let tokens = ($context | split row " " | where {|t| $t != "" })
- let tokens = if ($context | str ends-with " ") {
- $tokens | append ""
- } else {
- $tokens
- }
-
let result = (do {
- with-env { COMPLETE: nu } { ^$worktrunk_bin -- ...$tokens }
+ with-env { COMPLETE: nu } { ^$worktrunk_bin -- ...$spans }
} | complete)
if $result.exit_code != 0 { return [] }
@@ -66,7 +59,15 @@ export def "nu-complete wt" [context: string] {
# Stderr flows to the terminal in real-time. The binary sees non-TTY stdout
# and uses buffered mode, but commands other than `list` don't benefit from
# progressive rendering anyway.
-export def --env --wrapped wt [...args: string@"nu-complete wt"] {
+#
+# Completer wired via `@complete` attribute on an untyped `[...args]` rest.
+# The parameter-level `string@"completer"` form keeps tokens literal, which
+# blocks nushell's normal argument handling for `--flag="value"` (quote
+# stripping) and `~` (path expansion). Untyped rest gets that handling once
+# nushell/nushell#18131 ships in stable nu; until then `--flag="value"` still
+# arrives quoted. See nushell/nushell#18128 for upstream tracking.
+@complete "nu-complete wt"
+export def --env --wrapped wt [...args] {
let worktrunk_bin = if ($env.WORKTRUNK_BIN? | is-not-empty) {
$env.WORKTRUNK_BIN
} else {
diff --git a/templates/nushell.nu b/templates/nushell.nu
index 4b9cd6ea4..369bc3402 100644
--- a/templates/nushell.nu
+++ b/templates/nushell.nu
@@ -4,7 +4,7 @@
# Note: nushell's completion engine bypasses custom completers when the current
# token starts with `-`, so flag completions (e.g. `wt switch --<TAB>`) don't
# appear. Subcommand and value completions work. (nushell/nushell#14504)
-export def "nu-complete {{ cmd }}" [context: string] {
+export def "nu-complete {{ cmd }}" [spans: list<string>] {
let worktrunk_bin = if ($env.WORKTRUNK_BIN? | is-not-empty) {
$env.WORKTRUNK_BIN
} else {
@@ -13,15 +13,8 @@ export def "nu-complete {{ cmd }}" [context: string] {
($external | get 0.path)
}
- let tokens = ($context | split row " " | where {|t| $t != "" })
- let tokens = if ($context | str ends-with " ") {
- $tokens | append ""
- } else {
- $tokens
- }
-
let result = (do {
- with-env { COMPLETE: nu } { ^$worktrunk_bin -- ...$tokens }
+ with-env { COMPLETE: nu } { ^$worktrunk_bin -- ...$spans }
} | complete)
if $result.exit_code != 0 { return [] }
@@ -62,7 +55,15 @@ export def "nu-complete {{ cmd }}" [context: string] {
# Stderr flows to the terminal in real-time. The binary sees non-TTY stdout
# and uses buffered mode, but commands other than `list` don't benefit from
# progressive rendering anyway.
-export def --env --wrapped {{ cmd }} [...args: string@"nu-complete {{ cmd }}"] {
+#
+# Completer wired via `@complete` attribute on an untyped `[...args]` rest.
+# The parameter-level `string@"completer"` form keeps tokens literal, which
+# blocks nushell's normal argument handling for `--flag="value"` (quote
+# stripping) and `~` (path expansion). Untyped rest gets that handling once
+# nushell/nushell#18131 ships in stable nu; until then `--flag="value"` still
+# arrives quoted. See nushell/nushell#18128 for upstream tracking.
+@complete "nu-complete {{ cmd }}"
+export def --env --wrapped {{ cmd }} [...args] {
let worktrunk_bin = if ($env.WORKTRUNK_BIN? | is-not-empty) {
$env.WORKTRUNK_BIN
} else {