Skip to content

Commit f117437

Browse files
fix(terminal): cd before running startup command so prompt shows worktree dir
Joining the cd and the user's command with && hid the prompt update until the long-running command finished, leaving the user looking at the old directory while bin/setup ran. Send the cd as its own line first so the shell renders a fresh prompt with the worktree path, then send the command 250ms later. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 03557a2 commit f117437

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

Sources/NeetlyApp/TerminalTabViewController.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,19 @@ class TerminalTabViewController: NSViewController, LocalProcessTerminalViewDeleg
203203
// shells and wipes out env-level PATH additions).
204204
let escapedExecDir = execDir.replacingOccurrences(of: "'", with: "'\\''")
205205
let pathExport = "export PATH='\(escapedExecDir)':\"$PATH\""
206-
let cmd: String
207-
if self.command.isEmpty {
208-
cmd = "\(pathExport); cd '\(escapedPath)'\n"
209-
} else {
210-
cmd = "\(pathExport); cd '\(escapedPath)' && \(self.command)\n"
206+
207+
// Send the cd as its own line so the shell renders a fresh prompt
208+
// showing the worktree directory before the user's command starts
209+
// running. Joining them with `&&` would suppress the prompt update
210+
// until the long-running command finished.
211+
let setup = "\(pathExport); cd '\(escapedPath)'\n"
212+
self.terminalView.send(data: Array(setup.utf8)[...])
213+
214+
guard !self.command.isEmpty else { return }
215+
let runCmd = "\(self.command)\n"
216+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { [weak self] in
217+
self?.terminalView.send(data: Array(runCmd.utf8)[...])
211218
}
212-
let bytes = Array(cmd.utf8)
213-
self.terminalView.send(data: bytes[...])
214219
}
215220
}
216221

0 commit comments

Comments
 (0)