@@ -154,7 +154,7 @@ function stripTerminalControl(text: string): string {
154154 . replace ( / [ \x00 - \x08 \x0b \x0c \x0e - \x1f \x7f ] / g, "" ) ;
155155}
156156
157- // Line editors (zsh, fish, bash 5.1+) enable bracketed paste when they start reading a command.
157+ // Line editors (zsh, fish, nu, bash 5.1+) enable bracketed paste when they start reading a command.
158158const BRACKETED_PASTE_ON = "\x1b[?2004h" ;
159159const BRACKETED_PASTE_OFF = "\x1b[?2004l" ;
160160// Longer than one subprocess poll plus its ps timeout, so a startup prompt is seen as busy first.
@@ -166,12 +166,13 @@ function lineEditorReading(text: string, previous: boolean): boolean {
166166 return on === off ? previous : on > off ;
167167}
168168
169- type CompletionShell = "posix" | "fish" | "powershell" ;
169+ type CompletionShell = "posix" | "fish" | "nushell" | " powershell";
170170
171171function resolveCompletionShell ( shell : string ) : CompletionShell | null {
172172 const name = ( shell . split ( / [ / \\ ] / ) . at ( - 1 ) ?? shell ) . toLowerCase ( ) . replace ( / \. e x e $ / , "" ) ;
173173 if ( name === "cmd" ) return null ;
174174 if ( name === "fish" ) return "fish" ;
175+ if ( name === "nu" ) return "nushell" ;
175176 if ( name === "pwsh" || name === "powershell" ) return "powershell" ;
176177 return "posix" ;
177178}
@@ -188,6 +189,20 @@ function wrapCommandForCompletion(
188189 return `$global:LASTEXITCODE = $null; & {\r${ body } \r}; if ($null -ne $LASTEXITCODE) { $__t3c = $LASTEXITCODE } elseif ($?) { $__t3c = 0 } else { $__t3c = 1 }; Write-Host "${ sentinel } $__t3c"` ;
189190 case "fish" :
190191 return `begin\r${ body } \rend; printf '\\n${ sentinel } %s\\n' $status` ;
192+ case "nushell" : {
193+ const escaped = command . replace ( / [ " \\ \x00 - \x1f ] / g, ( char ) =>
194+ char === '"' || char === "\\" ? `\\${ char } ` : `\\u{${ char . charCodeAt ( 0 ) . toString ( 16 ) } }` ,
195+ ) ;
196+ // Nu resolves imports before running cd; source a file rooted in the worktree.
197+ return [
198+ "$env.LAST_EXIT_CODE = 0" ,
199+ "let __t3f = try { mktemp --tmpdir-path $env.T3CODE_WORKTREE_PATH --suffix .nu .t3-setup-XXXXXXXX } catch {|e| print -e $e.msg; null }" ,
200+ `if $__t3f == null { $env.LAST_EXIT_CODE = 1 } else { try { [$"rm --permanent ($__t3f | to nuon)" "${ escaped } "] | str join (char newline) | save --force --raw $__t3f; ^$nu.current-exe --login --commands $"cd $env.T3CODE_WORKTREE_PATH; source ($__t3f | to nuon)" } catch {|e| if $e != null and $e.exit_code? == null { print -e $e.msg }; if $env.LAST_EXIT_CODE == 0 { $env.LAST_EXIT_CODE = 1 } } }` ,
201+ "let __t3c = $env.LAST_EXIT_CODE" ,
202+ "try { if $__t3f != null and ($__t3f | path exists) { rm --permanent $__t3f } } catch {|e| print -e $e.msg }" ,
203+ `print $"\\n${ sentinel } ($__t3c)"` ,
204+ ] . join ( "; " ) ;
205+ }
191206 case "posix" :
192207 return `( ${ body } \r); printf '\\n${ sentinel } %s\\n' "$?"` ;
193208 }
@@ -517,9 +532,9 @@ export const make = Effect.gen(function* () {
517532 // Return once the terminal exists so callers can show it while a startup prompt waits.
518533 // PowerShell and cmd have no line-editor signal.
519534 yield * (
520- completionShell === "posix " || completionShell === "fish"
521- ? readiness . wait
522- : Effect . succeed ( "ready" as const )
535+ completionShell === "powershell " || completionShell === null
536+ ? Effect . succeed ( "ready" as const )
537+ : readiness . wait
523538 ) . pipe (
524539 Effect . flatMap ( ( shell ) =>
525540 shell === "exited" || commandLine === null
0 commit comments