Skip to content

Find terminal profiles at the login shell path when it's not on PATH - #339556

Merged
Megan Rogge (meganrogge) merged 3 commits into
microsoft:mainfrom
nkramber:fix/195768-login-shell-profile
Nov 5, 2026
Merged

Megan Rogge (meganrogge) merged 3 commits into
microsoft:mainfrom
nkramber:fix/195768-login-shell-profile

Conversation

@nkramber

@nkramber nkramber commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #195768

On macOS and Linux, a terminal profile with a bare path (the default fish, zsh, bash, … entries) is only looked up on the PATH of the resolved shell environment. That environment comes from running $SHELL as a login shell, and when resolution fails or times out, the lookup falls back to the pty host's own PATH. For VS Code launched from the macOS Dock, that's launchd's /usr/bin:/bin:/usr/sbin:/sbin. So a Homebrew fish at /opt/homebrew/bin/fish that is the user's login shell can disappear from the profile list. An explicit terminal.integrated.defaultProfile.osx: "fish" then can't match it and silently falls back to $SHELL, which in a Dock-launched app can still be the old shell after chsh.

Approach described on the issue: #195768 (comment)

Change

src/vs/platform/terminal/node/terminalProfiles.ts:

  • getValidatedProfile (Unix only): when a profile's path is a bare name equal to the basename of the user's login shell, that login shell's absolute path is added as an extra candidate after the PATH lookup. It's validated like any absolute path (exists check), so nothing changes when the shell is on PATH, and other bare names (e.g. tmux) are unaffected.
  • New getLoginShells: $SHELL from the resolved environment and from the process, plus os.userInfo().shell, which reads the user database and so is current even when the session's $SHELL predates chsh. Only absolute paths are kept, de-duplicated. It's passed down through detectAvailableUnixProfiles → transformToTerminalProfiles → getValidatedProfile. detectAvailableProfiles takes an optional testLoginShells for tests, like the existing testPwshSourcePaths.
  • validateProfilePaths (all platforms): when a bare name isn't found on PATH, the recursive call now passes env, overrideName and isAutoDetected like the other two recursive calls do. Previously they were dropped, which would have stripped them from a profile resolved through the login-shell candidate. This also affects any profile with a path array whose bare first entry isn't on PATH (e.g. ["pwsh.exe", "C:\\tools\\pwsh.exe"] on Windows): its env and overrideName are now kept instead of silently dropped. The built-in default profiles set neither.

A profile found this way shows its full path in the profile picker (fish, /opt/homebrew/bin/fish -l), like other absolute-path profiles. Unchanged: profile defaults, how the default follows $SHELL when defaultProfile is unset, and shell environment resolution.

How to test

macOS with fish from Homebrew (brew install fish), Code - OSS launched the way the Dock does (no VSCODE_CLI, launchd PATH):

env -i HOME="$HOME" USER="$USER" TMPDIR="$TMPDIR" PATH=/usr/bin:/bin:/usr/sbin:/sbin SHELL=/opt/homebrew/bin/fish \
  XDG_CONFIG_HOME=/tmp/xdg-nobrew NODE_ENV=development VSCODE_DEV=1 \
  "./.build/electron/Code - OSS.app/Contents/MacOS/Code - OSS" . --user-data-dir=/tmp/udd

with /tmp/xdg-nobrew/fish/config.fish containing set -gx PATH /usr/bin /bin /usr/sbin /sbin, so the resolved shell env has no /opt/homebrew/bin, and "terminal.integrated.defaultProfile.osx": "fish" in the profile's settings.

  1. Open a terminal. Before: fish starts without -l (generated fallback profile), and Terminal: Select Default Profile has no fish entry. After: fish -l from the fish profile, and the picker lists fish, /opt/homebrew/bin/fish -l.
  2. Same with SHELL=/bin/zsh in the command above while the account's login shell is fish (chsh -s /opt/homebrew/bin/fish), i.e. a stale $SHELL, and a zsh config whose PATH lacks /opt/homebrew/bin. Before: zsh, silently. After: fish -l.
  3. Regression: launched normally (fish on PATH), the picker still shows fish, fish -l and fish starts as before.

Results from my runs (dev build, Dock-style launch, defaultProfile.osx: "fish"):

scenario before after
$SHELL=fish, shell env resolution times out fish (no -l), fish missing from picker fish -l
$SHELL=fish, resolved PATH without Homebrew fish missing from picker fish -l, fish in picker
login shell fish, stale $SHELL=zsh, resolution times out zsh fish -l
login shell fish, stale $SHELL=zsh, zsh PATH without Homebrew zsh fish -l
fish on PATH (normal) fish -l unchanged

Automated: src/vs/workbench/contrib/terminal/test/node/terminalProfiles.test.ts › should find a bare-name profile at the login shell path when it is not on PATH (fails without this change; it also fails if only the validateProfilePaths change is reverted). All terminal unit tests pass locally. Linux uses the same code path, verified only through the unit test. On Windows the only change is the validateProfilePaths fix above. The login-shell candidate is Unix only.

Copilot AI balanced review requested due to automatic review settings October 4, 2026 04:10
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Anthony Kim (@anthonykim1)

Matched files:

  • src/vs/platform/terminal/node/terminalProfiles.ts
  • src/vs/workbench/contrib/terminal/test/node/terminalProfiles.test.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Login-shell candidates can override the configured ordering of profile path fallbacks.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Improves Unix terminal profile discovery when a login shell is absent from PATH.

Changes:

  • Adds absolute login-shell paths as profile fallbacks.
  • Preserves profile metadata during fallback validation.
  • Adds Unix regression coverage.
File Description
terminalProfiles.ts Adds login-shell discovery and fallback validation.
terminalProfiles.test.ts Tests bare-name profile resolution outside PATH.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The fallback is narrowly scoped, preserves existing precedence, and has focused regression coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@meganrogge Megan Rogge (meganrogge) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@meganrogge
Megan Rogge (meganrogge) enabled auto-merge (squash) November 3, 2026 19:30
@meganrogge
Megan Rogge (meganrogge) merged commit a360507 into microsoft:main Nov 5, 2026
63 of 82 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.146.0 milestone Nov 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The synchronous account lookup can stall the main process or remote server, while appending login-shell candidates can bypass the configured shell preference order.

2 open issues

Review effort: Max

function getLoginShells(shellEnv: typeof process.env): string[] {
const shells = [shellEnv.SHELL, process.env.SHELL];
try {
shells.push(userInfo().shell ?? undefined);
Comment on lines +248 to +249
const bareNames = paths.filter((e): e is string => isString(e) && basename(e) === e);
paths.push(...bareNames.flatMap(name => (loginShells ?? []).filter(e => basename(e) === name)));
CAPITAL8 (Capital-8) pushed a commit to Capital-8/vscode that referenced this pull request Nov 10, 2026
Bound the account database lookup and preserve configured path fallback order.

Follow up to microsoft#339556 and microsoft#195768.

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terminal profile default discovery isn't working as expected

5 participants