feat(terminal): 支持配置 shell 与 shellArgs,终端标题使用 shell 名 (#125)

- 支持通过 cordis.patch.yml 指定终端 shell
- 支持 shellArgs 带参启动终端 shell
- 终端标题改用 shell 名,内部使用 uuid 管理
This commit is contained in:
NuperAki authored and GitHub committed 2026-08-18 19:56:04 +08:00
1 parent 498528d2eb
commit c973d6ec1b
15 files changed
+193 -23

No files matched your search

+28 -2
View File
@@ -15,11 +15,13 @@ import { createBetterSidebarService } from '../src/client/service.ts'
import { createSidebarStore } from '../src/client/state.ts'
import { allLeaves } from '../src/client/state.ts'
import { registerBuiltins } from '../src/client/builtins/index.ts'
import type { BuiltinTabOptions } from '../src/client/builtins/tabs.tsx'
import { t } from '../src/client/locales.ts'
function setup(): { service: ReturnType<typeof createBetterSidebarService>; store: ReturnType<typeof createSidebarStore>; dispose: () => void } {
function setup(options: BuiltinTabOptions = {}): { service: ReturnType<typeof createBetterSidebarService>; store: ReturnType<typeof createSidebarStore>; dispose: () => void } {
const store = createSidebarStore()
const service = createBetterSidebarService(store)
const dispose = registerBuiltins({} as Context, service)
const dispose = registerBuiltins({} as Context, service, options)
return { service, store, dispose }
}
@@ -111,6 +113,30 @@ describe('built-in tab registrations', () => {
expect(state.nextBrowser).toBe(3)
})
it('the terminal createTab uses shell-name titles and hidden uuid ids, allowing duplicates', () => {
const { service, store } = setup({ terminalTitle: () => 'bash' })
store.setSession('s1')
service.openTab({ type: 'terminal' })
service.openTab({ type: 'terminal' })
const state = store.getSnapshot().state!
const tabs = allLeaves(state.splits).flatMap(leaf => leaf.tabs).filter(t => t.type === 'terminal')
expect(tabs).toHaveLength(2)
expect(tabs[0]!.title).toBe('bash')
expect(tabs[1]!.title).toBe('bash')
expect(tabs[0]!.id).toMatch(/^terminal:[0-9a-f-]{36}$/)
expect(tabs[1]!.id).toMatch(/^terminal:[0-9a-f-]{36}$/)
expect(tabs[0]!.id).not.toBe(tabs[1]!.id)
})
it('the terminal createTab falls back to the localized terminal label before shell info resolves', () => {
const { service, store } = setup()
store.setSession('s1')
service.openTab({ type: 'terminal' })
const state = store.getSnapshot().state!
const tab = allLeaves(state.splits).flatMap(leaf => leaf.tabs).find(t => t.type === 'terminal')
expect(tab?.title).toBe(t('terminal'))
})
it('every built-in tab carries the settings-surface icon', () => {
const { service } = setup()
for (const tab of service.getTabs()) {
+8
View File
@@ -37,10 +37,18 @@ describe('dsh-better-sidebar plugin export shape', () => {
// The terminal shell config defaults to auto-resolution (empty shell =
// the platform chain in defaultShell()).
expect(resolved.shell).toBe('')
// Shell args default to an empty list; non-empty values replace the
// automatic platform login flag.
expect(resolved.shellArgs).toEqual([])
const configured = (schema as unknown as {
(input: Record<string, unknown> | undefined): Record<string, unknown>
})({ shell: 'pwsh.exe' })
expect(configured.shell).toBe('pwsh.exe')
const configuredWithArgs = (schema as unknown as {
(input: Record<string, unknown> | undefined): Record<string, unknown>
})({ shell: '/bin/zsh', shellArgs: ['--noprofile', '--no-rc'] })
expect(configuredWithArgs.shell).toBe('/bin/zsh')
expect(configuredWithArgs.shellArgs).toEqual(['--noprofile', '--no-rc'])
})
it('registers the side card preferences schema with the documented defaults', async () => {
+17 -1
View File
@@ -13,7 +13,7 @@ vi.mock('node:os', async (importOriginal) => {
})
import { resolveSidebarConfig } from '../src/config.ts'
import { defaultShell, ensureSpawnHelper } from '../src/pty-manager.ts'
import { defaultShell, ensureSpawnHelper, shellDisplayName, shellSpawnArgs } from '../src/pty-manager.ts'
describe('pty helpers', () => {
it('prefers an explicit shell, then SHELL, then the account login shell on POSIX', () => {
@@ -69,6 +69,22 @@ describe('pty helpers', () => {
it('trims the configured shell and defaults it to auto for old documents', () => {
expect(resolveSidebarConfig(undefined).shell).toBe('')
expect(resolveSidebarConfig({ shell: ' pwsh.exe ' }).shell).toBe('pwsh.exe')
expect(resolveSidebarConfig({ shell: '/bin/zsh', shellArgs: ['--noprofile'] }).shellArgs).toEqual(['--noprofile'])
expect(resolveSidebarConfig(undefined).shellArgs).toEqual([])
})
it('derives a short display name for terminal tab titles', () => {
expect(shellDisplayName('/bin/zsh')).toBe('zsh')
expect(shellDisplayName('/usr/bin/bash')).toBe('bash')
expect(shellDisplayName('C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe')).toBe('powershell')
expect(shellDisplayName('pwsh.exe')).toBe('pwsh')
expect(shellDisplayName('/weird')).toBe('weird')
expect(shellDisplayName('/')).toBe('/')
})
it('uses explicit shell args verbatim and keeps platform defaults when none are configured', () => {
expect(shellSpawnArgs(['--noprofile', '--no-rc'])).toEqual(['--noprofile', '--no-rc'])
expect(shellSpawnArgs([])).toEqual(process.platform === 'win32' ? [] : ['-l'])
})
it('restores the spawn-helper executable bit idempotently', () => {
+11
View File
@@ -578,6 +578,17 @@ describe('side card settings routes', () => {
expect((result.value as { externalDisable?: boolean }).externalDisable).toBe(true)
})
it('serves the effective terminal shell and its display name', async () => {
const route = mountWithSettings(undefined)
const result = await invoke(route, 'shell.get', {})
expect(result.ok).toBe(true)
expect(result.value).toMatchObject({
shell: expect.any(String),
name: expect.any(String),
})
expect(String((result.value as { name: unknown }).name).length).toBeGreaterThan(0)
})
it('reads the resolved prefs and writes a patch through the seam', async () => {
const route = mountWithSettings(createFakeSettings())
const read = await invoke(route, 'settings.get', {})