* Resolves the configured VS Code terminal profile (see `terminalProfile` * setting / Terminal.getTerminalProfile) into a shell path and args by * reading VS Code's `terminal.integrated.profiles. ` configuration. * * This reuses VS Code's terminal profile concept so users ca
( platform: NodeJS.Platform = process.platform, )
| 510 | * configured or the profile cannot be resolved (default behavior). |
| 511 | */ |
| 512 | public static getProfileShell( |
| 513 | platform: NodeJS.Platform = process.platform, |
| 514 | ): { shellPath: string; shellArgs?: string[]; env?: Record<string, string | null> } | undefined { |
| 515 | const profileName = Terminal.getTerminalProfile() |
| 516 | |
| 517 | if (!profileName) { |
| 518 | return undefined |
| 519 | } |
| 520 | |
| 521 | const platformKey = Terminal.getPlatformProfileKey(platform) |
| 522 | |
| 523 | const profiles = Terminal.getConfiguredProfiles(platform) |
| 524 | |
| 525 | const profile = profiles?.[profileName] as |
| 526 | | { |
| 527 | path?: string | string[] |
| 528 | args?: string | string[] |
| 529 | source?: string |
| 530 | env?: Record<string, unknown> |
| 531 | } |
| 532 | | null |
| 533 | | undefined |
| 534 | |
| 535 | if (!profile) { |
| 536 | console.warn(`[Terminal] Configured terminal profile "${profileName}" not found for ${platformKey}.`) |
| 537 | return undefined |
| 538 | } |
| 539 | |
| 540 | const pathValue = Terminal.resolveProfilePath(profile.path, platform) |
| 541 | |
| 542 | if (!pathValue) { |
| 543 | // Profiles defined only by `source` (e.g. "PowerShell") can't be mapped to |
| 544 | // a shell path here, so we fall back to the default terminal. |
| 545 | console.warn( |
| 546 | `[Terminal] Terminal profile "${profileName}" has no resolvable "path"; using default terminal.`, |
| 547 | ) |
| 548 | return undefined |
| 549 | } |
| 550 | |
| 551 | const shellArgs = Array.isArray(profile.args) |
| 552 | ? profile.args.filter((arg): arg is string => typeof arg === "string") |
| 553 | : typeof profile.args === "string" |
| 554 | ? [profile.args] |
| 555 | : undefined |
| 556 | |
| 557 | // VS Code profiles may declare their own `env` (e.g. to set a UTF-8 locale or |
| 558 | // a custom PATH). Preserve it so the inline terminal doesn't lose environment |
| 559 | // the user configured on the profile. A `null` value unsets that variable. |
| 560 | // Values come from user `settings.json`, so sanitize to string/null only. |
| 561 | let env: Record<string, string | null> | undefined |
| 562 | |
| 563 | if (profile.env && typeof profile.env === "object") { |
| 564 | const sanitized: Record<string, string | null> = {} |
| 565 | const blockedKeys = new Set([ |
| 566 | "ZDOTDIR", |
| 567 | "PROMPT_COMMAND", |
| 568 | "LD_PRELOAD", |
| 569 | "LD_LIBRARY_PATH", |
no test coverage detected