From 103536401b0559a7dfe6f5384351dcf0af59257d Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Mon, 7 Mar 2022 12:19:25 -0800 Subject: [PATCH 1/2] Support shell type context key on mac/linux Fixes #144619 --- src/vs/platform/terminal/common/terminal.ts | 12 ++++++++++- .../platform/terminal/node/terminalProcess.ts | 20 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/vs/platform/terminal/common/terminal.ts b/src/vs/platform/terminal/common/terminal.ts index 8c90aa61c62..3ff4e70ca4c 100644 --- a/src/vs/platform/terminal/common/terminal.ts +++ b/src/vs/platform/terminal/common/terminal.ts @@ -111,13 +111,23 @@ export const enum TerminalSettingId { ShellIntegrationCommandHistory = 'terminal.integrated.shellIntegration.history' } +export const enum PosixShellType { + PowerShell = 'pwsh', + Bash = 'bash', + Fish = 'fish', + Sh = 'sh', + Csh = 'csh', + Ksh = 'ksh', + Zsh = 'zsh', +} export const enum WindowsShellType { CommandPrompt = 'cmd', PowerShell = 'pwsh', Wsl = 'wsl', GitBash = 'gitbash' } -export type TerminalShellType = WindowsShellType | undefined; +export type TerminalShellType = PosixShellType | WindowsShellType | undefined; + export interface IRawTerminalInstanceLayoutInfo { relativeSize: number; terminal: T; diff --git a/src/vs/platform/terminal/node/terminalProcess.ts b/src/vs/platform/terminal/node/terminalProcess.ts index 2a1dfd1823f..1c89b047438 100644 --- a/src/vs/platform/terminal/node/terminalProcess.ts +++ b/src/vs/platform/terminal/node/terminalProcess.ts @@ -17,7 +17,7 @@ import { URI } from 'vs/base/common/uri'; import { Promises } from 'vs/base/node/pfs'; import { localize } from 'vs/nls'; import { ILogService } from 'vs/platform/log/common/log'; -import { FlowControlConstants, IShellLaunchConfig, ITerminalChildProcess, ITerminalLaunchError, IProcessProperty, IProcessPropertyMap as IProcessPropertyMap, ProcessPropertyType, TerminalShellType, IProcessReadyEvent, ITerminalProcessOptions } from 'vs/platform/terminal/common/terminal'; +import { FlowControlConstants, IShellLaunchConfig, ITerminalChildProcess, ITerminalLaunchError, IProcessProperty, IProcessPropertyMap as IProcessPropertyMap, ProcessPropertyType, TerminalShellType, IProcessReadyEvent, ITerminalProcessOptions, PosixShellType } from 'vs/platform/terminal/common/terminal'; import { ChildProcessMonitor } from 'vs/platform/terminal/node/childProcessMonitor'; import { findExecutable, getShellIntegrationInjection, getWindowsBuildNumber, IShellIntegrationConfigInjection } from 'vs/platform/terminal/node/terminalEnvironment'; import { WindowsShellHelper } from 'vs/platform/terminal/node/windowsShellHelper'; @@ -75,6 +75,16 @@ interface IWriteObject { isBinary: boolean; } +const posixShellTypeMap = new Map([ + ['bash', PosixShellType.Bash], + ['csh', PosixShellType.Csh], + ['fish', PosixShellType.Fish], + ['ksh', PosixShellType.Ksh], + ['sh', PosixShellType.Sh], + ['pwsh', PosixShellType.PowerShell], + ['zsh', PosixShellType.Zsh] +]); + export class TerminalProcess extends Disposable implements ITerminalChildProcess { readonly id = 0; readonly shouldPersist = false; @@ -111,7 +121,12 @@ export class TerminalProcess extends Disposable implements ITerminalChildProcess get exitMessage(): string | undefined { return this._exitMessage; } get currentTitle(): string { return this._windowsShellHelper?.shellTitle || this._currentTitle; } - get shellType(): TerminalShellType { return this._windowsShellHelper ? this._windowsShellHelper.shellType : undefined; } + get shellType(): TerminalShellType { + if (isWindows) { + return this._windowsShellHelper?.shellType; + } + return posixShellTypeMap.get(this._currentTitle); + } private readonly _onProcessData = this._register(new Emitter()); readonly onProcessData = this._onProcessData.event; @@ -389,6 +404,7 @@ export class TerminalProcess extends Disposable implements ITerminalChildProcess } this._currentTitle = ptyProcess.process; this._onDidChangeProperty.fire({ type: ProcessPropertyType.Title, value: this._currentTitle }); + this._onDidChangeProperty.fire({ type: ProcessPropertyType.ShellType, value: posixShellTypeMap.get(this.currentTitle) }); } shutdown(immediate: boolean): void { From 6be9a400739c529a96d39a200a16e5253e10dd2b Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Tue, 8 Mar 2022 16:48:27 -0800 Subject: [PATCH 2/2] Update src/vs/platform/terminal/node/terminalProcess.ts Co-authored-by: Megan Rogge --- src/vs/platform/terminal/node/terminalProcess.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/vs/platform/terminal/node/terminalProcess.ts b/src/vs/platform/terminal/node/terminalProcess.ts index 1c89b047438..23ab10777cb 100644 --- a/src/vs/platform/terminal/node/terminalProcess.ts +++ b/src/vs/platform/terminal/node/terminalProcess.ts @@ -121,12 +121,7 @@ export class TerminalProcess extends Disposable implements ITerminalChildProcess get exitMessage(): string | undefined { return this._exitMessage; } get currentTitle(): string { return this._windowsShellHelper?.shellTitle || this._currentTitle; } - get shellType(): TerminalShellType { - if (isWindows) { - return this._windowsShellHelper?.shellType; - } - return posixShellTypeMap.get(this._currentTitle); - } + get shellType(): TerminalShellType { return isWindows ? this._windowsShellHelper?.shellType : posixShellTypeMap.get(this._currentTitle); } private readonly _onProcessData = this._register(new Emitter()); readonly onProcessData = this._onProcessData.event;