Skip to content

Commit e02fd05

Browse files
committed
fix(terminal): use stale-title flag instead of overwriting inst.title
The previous approach (b51de0b) directly overwrote inst.title when the foreground process returned to the shell, which broke Linux where bash sets the title via PS1 escape sequences on each prompt. Replace with a _titleStale flag that is set on non-shell→shell transitions and cleared when onTitleChange fires, so shells that emit title sequences (bash/Linux) work correctly while shells that don't (zsh/Mac) still show the profile name instead of stale child titles. Also fix the Linux integration test to trigger a prompt refresh (echo + enter) after shell init so PS1 title escapes fire reliably.
1 parent d27963a commit e02fd05

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

src/extensionsIntegrated/Terminal/main.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,14 @@ define(function (require, exports, module) {
391391
}
392392

393393
/**
394-
* Handle terminal title change — also fetches and displays the foreground process
394+
* Handle terminal title change — also fetches and displays the foreground process.
395+
* Clears the stale-title flag since the shell has provided its own title.
395396
*/
396397
function _onTerminalTitleChanged(id, title) {
398+
const instance = terminalInstances.find(t => t.id === id);
399+
if (instance) {
400+
instance._titleStale = false;
401+
}
397402
_updateFlyout();
398403
_updateTabProcess(id);
399404
}
@@ -409,17 +414,18 @@ define(function (require, exports, module) {
409414
nodeConnector.execPeer("getTerminalProcess", {id}).then(function (result) {
410415
const newProc = result.process || "";
411416
if (processInfo[id] !== newProc) {
417+
const oldProc = processInfo[id];
412418
processInfo[id] = newProc;
413-
// When a child process (e.g. "claude") exits and the
414-
// shell regains foreground, the child may have set a
415-
// custom terminal title via escape sequences. Shells
416-
// like zsh on macOS do not emit a title reset, so
417-
// inst.title stays stale. Reset it only when the
418-
// foreground process returns to the shell. If the
419-
// shell does emit a title change, onTitleChange will
420-
// overwrite this immediately.
421-
if (_isShellProcess(newProc)) {
422-
instance.title = instance.shellProfile.name;
419+
// When a child process exits and the shell regains
420+
// foreground, the child may have set a custom title
421+
// via escape sequences. Some shells (e.g. zsh on
422+
// macOS) don't emit a title reset, leaving inst.title
423+
// stale. Mark it so _updateFlyout can fall back to
424+
// the profile name. If the shell DOES emit a title
425+
// change (e.g. bash on Linux), _onTerminalTitleChanged
426+
// clears this flag immediately.
427+
if (oldProc && !_isShellProcess(oldProc) && _isShellProcess(newProc)) {
428+
instance._titleStale = true;
423429
}
424430
_updateFlyout();
425431
}
@@ -461,13 +467,16 @@ define(function (require, exports, module) {
461467
const proc = processInfo[inst.id] || "";
462468
const basename = proc ? proc.split("/").pop().split("\\").pop() : "";
463469

464-
// Label: process basename; right side: cwd basename; tooltip: full title
470+
// Label: process basename; right side: cwd basename; tooltip: full title.
471+
// If the title is stale (child set it and the shell didn't reset it),
472+
// fall back to the shell profile name.
465473
const label = basename || "Terminal";
466-
const cwdName = _extractCwdBasename(inst.title);
474+
const displayTitle = inst._titleStale ? inst.shellProfile.name : inst.title;
475+
const cwdName = _extractCwdBasename(displayTitle);
467476

468477
const $item = $('<div class="terminal-flyout-item"></div>')
469478
.attr("data-terminal-id", inst.id)
470-
.attr("title", inst.title)
479+
.attr("title", displayTitle)
471480
.toggleClass("active", inst.id === activeTerminalId);
472481

473482
if (!inst.isAlive) {

test/spec/Terminal-integ-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ define(function (require, exports, module) {
224224
} else {
225225
// On Linux, bash/zsh set the title to
226226
// include the cwd (e.g. "user@host: /path").
227+
// Wait for shell ready first, then trigger
228+
// a prompt refresh so PS1 title escapes fire.
229+
await waitForShellReady();
230+
await writeToTerminal("echo\r");
231+
227232
const expectedPath = getNativeProjectPath();
228233
const projectDirName = expectedPath
229234
.split("/").pop().split("\\").pop();

0 commit comments

Comments
 (0)