feat(terminal): add Windows default shell setting (PowerShell vs CMD) (#950)
Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
This commit is contained in:
co-authored by
Jinwoo-H
parent
38f6b550c7
commit
87a2a371ff
@@ -85,6 +85,7 @@ function createSettings(overrides: Partial<GlobalSettings> = {}): GlobalSettings
|
||||
experimentalTerminalDaemon: false,
|
||||
experimentalTerminalDaemonNoticeShown: false,
|
||||
terminalForceHyperlink: true,
|
||||
terminalWindowsShell: 'powershell.exe',
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ function createSettings(overrides: Partial<GlobalSettings> = {}): GlobalSettings
|
||||
experimentalTerminalDaemon: false,
|
||||
experimentalTerminalDaemonNoticeShown: false,
|
||||
terminalForceHyperlink: true,
|
||||
terminalWindowsShell: 'powershell.exe',
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,6 +455,27 @@ describe('registerPtyHandlers', () => {
|
||||
expect.any(Object)
|
||||
)
|
||||
})
|
||||
|
||||
it('uses terminalWindowsShell setting over COMSPEC when provided', () => {
|
||||
// Why: COMSPEC always points to cmd.exe on stock Windows, so without the
|
||||
// setting the terminal would ignore the user's shell preference.
|
||||
process.env.COMSPEC = 'C:\\Windows\\system32\\cmd.exe'
|
||||
|
||||
registerPtyHandlers(mainWindow as never, undefined, undefined, () => ({
|
||||
terminalWindowsShell: 'powershell.exe'
|
||||
} as never))
|
||||
handlers.get('pty:spawn')!(null, { cols: 80, rows: 24 })
|
||||
|
||||
expect(spawnMock).toHaveBeenCalledWith(
|
||||
'powershell.exe',
|
||||
[
|
||||
'-NoExit',
|
||||
'-Command',
|
||||
'try { . $PROFILE } catch {}; [Console]::OutputEncoding = [System.Text.Encoding]::UTF8; [Console]::InputEncoding = [System.Text.Encoding]::UTF8'
|
||||
],
|
||||
expect.any(Object)
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects missing WSL worktree cwd instead of validating only the fallback Windows cwd', async () => {
|
||||
|
||||
@@ -147,6 +147,7 @@ export function registerPtyHandlers(
|
||||
localProvider.configure({
|
||||
isHistoryEnabled: () => getSettings?.()?.terminalScopeHistoryByWorktree ?? true,
|
||||
isForceHyperlinkEnabled: () => getSettings?.()?.terminalForceHyperlink ?? true,
|
||||
getWindowsShell: () => getSettings?.()?.terminalWindowsShell,
|
||||
buildSpawnEnv: (id, baseEnv) => {
|
||||
const selectedCodexHomePath = getSelectedCodexHomePath?.() ?? null
|
||||
|
||||
|
||||
@@ -98,6 +98,11 @@ export type LocalPtyProviderOptions = {
|
||||
* significant shell-startup slowdown with heavy rc files. When absent,
|
||||
* defaults to the prior behavior (on). */
|
||||
isForceHyperlinkEnabled?: () => boolean
|
||||
/** Why: COMSPEC is always cmd.exe on a stock Windows machine, so reading it
|
||||
* directly would ignore the user's shell preference. This callback lets the
|
||||
* IPC layer inject the persisted setting without coupling the provider to the
|
||||
* settings store. Returns undefined when no preference is set. */
|
||||
getWindowsShell?: () => string | undefined
|
||||
onSpawned?: (id: string) => void
|
||||
onExit?: (id: string, code: number) => void
|
||||
onData?: (id: string, data: string, timestamp: number) => void
|
||||
@@ -134,7 +139,7 @@ export class LocalPtyProvider implements IPtyProvider {
|
||||
effectiveCwd = getDefaultCwd()
|
||||
validationCwd = cwd
|
||||
} else if (process.platform === 'win32') {
|
||||
shellPath = process.env.COMSPEC || 'powershell.exe'
|
||||
shellPath = this.opts.getWindowsShell?.() || process.env.COMSPEC || 'powershell.exe'
|
||||
// Why: use path.win32.basename so backslash-separated Windows paths
|
||||
// are parsed correctly even when tests mock process.platform on Linux CI.
|
||||
const shellBasename = pathWin32.basename(shellPath).toLowerCase()
|
||||
@@ -447,7 +452,7 @@ export class LocalPtyProvider implements IPtyProvider {
|
||||
|
||||
async getDefaultShell(): Promise<string> {
|
||||
if (process.platform === 'win32') {
|
||||
return process.env.COMSPEC || 'powershell.exe'
|
||||
return this.opts.getWindowsShell?.() || process.env.COMSPEC || 'powershell.exe'
|
||||
}
|
||||
return process.env.SHELL || '/bin/zsh'
|
||||
}
|
||||
|
||||
@@ -36,7 +36,8 @@ import {
|
||||
TERMINAL_PANE_STYLE_SEARCH_ENTRIES,
|
||||
TERMINAL_RIGHT_CLICK_TO_PASTE_SEARCH_ENTRY,
|
||||
TERMINAL_SETUP_SCRIPT_SEARCH_ENTRIES,
|
||||
TERMINAL_TYPOGRAPHY_SEARCH_ENTRIES
|
||||
TERMINAL_TYPOGRAPHY_SEARCH_ENTRIES,
|
||||
TERMINAL_WINDOWS_SHELL_SEARCH_ENTRY
|
||||
} from './terminal-search'
|
||||
import { useDetectedOptionAsAlt } from '@/lib/keyboard-layout/use-effective-mac-option-as-alt'
|
||||
import { detectedCategoryToDefault } from '@/lib/keyboard-layout/detect-option-as-alt'
|
||||
@@ -90,6 +91,49 @@ export function TerminalPane({
|
||||
scrollbackMode === 'custom' ? 'custom' : isPreset ? `${scrollbackMb}` : 'custom'
|
||||
|
||||
const visibleSections = [
|
||||
isWindows && matchesSettingsSearch(searchQuery, TERMINAL_WINDOWS_SHELL_SEARCH_ENTRY) ? (
|
||||
<section key="windows-shell" className="space-y-4">
|
||||
<SearchableSetting
|
||||
title="Default Shell"
|
||||
description="Choose the default shell for new terminal panes on Windows."
|
||||
keywords={[
|
||||
'terminal',
|
||||
'windows',
|
||||
'shell',
|
||||
'powershell',
|
||||
'cmd',
|
||||
'command prompt',
|
||||
'default'
|
||||
]}
|
||||
className="space-y-2"
|
||||
>
|
||||
<Label>Default Shell</Label>
|
||||
<div className="flex w-fit gap-1 rounded-md border border-border/50 p-1">
|
||||
{(
|
||||
[
|
||||
{ label: 'PowerShell', value: 'powershell.exe' },
|
||||
{ label: 'Command Prompt', value: 'cmd.exe' }
|
||||
] as const
|
||||
).map(({ label, value }) => (
|
||||
<button
|
||||
key={value}
|
||||
onClick={() => updateSettings({ terminalWindowsShell: value })}
|
||||
className={`rounded-sm px-3 py-1 text-sm transition-colors ${
|
||||
(settings.terminalWindowsShell ?? 'powershell.exe') === value
|
||||
? 'bg-accent font-medium text-accent-foreground'
|
||||
: 'text-muted-foreground hover:text-foreground'
|
||||
}`}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Shell used when opening a new terminal pane. Takes effect for new terminals.
|
||||
</p>
|
||||
</SearchableSetting>
|
||||
</section>
|
||||
) : null,
|
||||
matchesSettingsSearch(searchQuery, TERMINAL_TYPOGRAPHY_SEARCH_ENTRIES) ? (
|
||||
<section key="typography" className="space-y-4">
|
||||
<div className="space-y-1">
|
||||
|
||||
@@ -175,7 +175,16 @@ export const TERMINAL_SETUP_SCRIPT_SEARCH_ENTRIES: SettingsSearchEntry[] = [
|
||||
}
|
||||
]
|
||||
|
||||
export const TERMINAL_WINDOWS_SHELL_SEARCH_ENTRY: SettingsSearchEntry[] = [
|
||||
{
|
||||
title: 'Default Shell',
|
||||
description: 'Choose the default shell for new terminal panes on Windows.',
|
||||
keywords: ['terminal', 'windows', 'shell', 'powershell', 'cmd', 'command prompt', 'default']
|
||||
}
|
||||
]
|
||||
|
||||
export const TERMINAL_WINDOWS_SEARCH_ENTRIES: SettingsSearchEntry[] = [
|
||||
...TERMINAL_WINDOWS_SHELL_SEARCH_ENTRY,
|
||||
{
|
||||
title: 'Right-click to paste',
|
||||
description:
|
||||
@@ -184,7 +193,14 @@ export const TERMINAL_WINDOWS_SEARCH_ENTRIES: SettingsSearchEntry[] = [
|
||||
}
|
||||
]
|
||||
|
||||
export const TERMINAL_RIGHT_CLICK_TO_PASTE_SEARCH_ENTRY = TERMINAL_WINDOWS_SEARCH_ENTRIES
|
||||
export const TERMINAL_RIGHT_CLICK_TO_PASTE_SEARCH_ENTRY: SettingsSearchEntry[] = [
|
||||
{
|
||||
title: 'Right-click to paste',
|
||||
description:
|
||||
'On Windows, right-click pastes the clipboard into the terminal. Use Ctrl+right-click to open the context menu.',
|
||||
keywords: ['terminal', 'windows', 'right click', 'paste', 'context menu']
|
||||
}
|
||||
]
|
||||
|
||||
export function getTerminalPaneSearchEntries(platform: {
|
||||
isWindows: boolean
|
||||
|
||||
@@ -120,6 +120,10 @@ export function getDefaultSettings(homedir: string): GlobalSettings {
|
||||
// box. Other platforms ignore this field because the UI never exposes it,
|
||||
// and Ctrl+right-click still opens the context menu when paste is enabled.
|
||||
terminalRightClickToPaste: true,
|
||||
// Why: COMSPEC on a stock Windows machine always resolves to cmd.exe, so
|
||||
// falling back to COMSPEC would silently open CMD instead of PowerShell.
|
||||
// Defaulting to powershell.exe matches what users expect from a modern IDE.
|
||||
terminalWindowsShell: 'powershell.exe',
|
||||
// Default false: opt-in only (matches Ghostty's default). Existing users
|
||||
// on upgrade inherit this default via persistence.ts's
|
||||
// { ...defaults.settings, ...parsed.settings } merge, so enabling
|
||||
|
||||
@@ -654,6 +654,11 @@ export type GlobalSettings = {
|
||||
* The setting stays Windows-only so macOS/Linux keep their existing context
|
||||
* menu behavior and users can still reach the menu with Ctrl+right-click. */
|
||||
terminalRightClickToPaste: boolean
|
||||
/** Why: COMSPEC always points to cmd.exe on stock Windows, so without an
|
||||
* explicit setting the terminal would always open CMD instead of the
|
||||
* user's preferred shell. Defaults to 'powershell.exe' which is the
|
||||
* modern choice for an IDE context. Only consulted on Windows. */
|
||||
terminalWindowsShell: string
|
||||
terminalFocusFollowsMouse: boolean
|
||||
/** Why: mirrors X11 / gnome-terminal "copy on select" UX — making a terminal
|
||||
* selection copies it to the system clipboard automatically, so users can
|
||||
|
||||
Reference in New Issue
Block a user