Repository navigation
feat(settings): import Kitty configs through a shared terminal config import pipeline #37375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bd3a583
3b311b3
095b943
9745be6
65d7ce0
408afd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { ipcMain } from 'electron' | ||
| import type { Store } from '../persistence/loading-store/store' | ||
| import { previewGhosttyImport } from '../ghostty/index' | ||
| import { previewKittyImport } from '../kitty' | ||
| import { previewWarpThemeImport } from '../warp-themes' | ||
|
|
||
| // Omitted sources fall back to each importer's auto-discovery default. | ||
| export function registerSettingsImportHandlers(store: Store): void { | ||
| ipcMain.handle('settings:previewGhosttyImport', (event, source?: unknown) => | ||
| previewGhosttyImport(store, source, event.sender) | ||
| ) | ||
| ipcMain.handle('settings:previewKittyImport', (event, source?: unknown) => | ||
| previewKittyImport(store, source, event.sender) | ||
| ) | ||
| ipcMain.handle('settings:previewWarpThemeImport', (event, source?: unknown) => | ||
| previewWarpThemeImport(store, source, event.sender) | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,47 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { homedir, platform } from 'node:os' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import path from 'node:path' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { constants } from 'node:fs' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { access, stat } from 'node:fs/promises' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function expandHome(dir: string, home: string): string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return dir === '~' || dir.startsWith('~/') ? path.join(home, dir.slice(1)) : dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Kitty's ConfigDirForName order; Kitty has no Windows build, so only an explicit directory applies there. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function getKittyConfigPaths(): string[] { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const home = homedir() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const explicitDir = process.env.KITTY_CONFIG_DIRECTORY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (explicitDir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [path.join(expandHome(explicitDir, home), 'kitty.conf')] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const plat = platform() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (plat === 'win32') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const roots = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.env.XDG_CONFIG_HOME, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...(process.env.XDG_CONFIG_DIRS ?? '').split(':'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '~/.config', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...(plat === 'darwin' ? ['~/Library/Preferences'] : []) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const dirs = roots | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .filter((root): root is string => Boolean(root)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .map((root) => path.posix.join(expandHome(root, home), 'kitty')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [...new Set(dirs)].map((dir) => path.posix.join(dir, 'kitty.conf')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** Kitty reads a single kitty.conf: the first location that has one in a writable directory. */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export async function findKittyConfigPaths(): Promise<string[]> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const configPath of getKittyConfigPaths()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The writability check keeps a read-only system default (e.g. /etc/xdg) from shadowing the user's config. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ((await stat(configPath)).isFile()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await access(path.dirname(configPath), constants.W_OK) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [configPath] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Unreadable candidates must not prevent probing the remaining locations. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+33
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not require write access to the Kitty config directory. When the process can read Suggested fix
Committable suggestion
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { homedir, platform } from 'node:os' | ||
| import type { WebContents } from 'electron' | ||
| import type { TerminalConfigImportPreview } from '../../shared/terminal-config-import-preview' | ||
| import type { Store } from '../persistence/loading-store/store' | ||
| import { translateMain } from '../i18n/main-i18n' | ||
| import { | ||
| previewTerminalConfigImport, | ||
| type TerminalConfigImporter | ||
| } from '../terminal-config-import/preview' | ||
| import { findKittyConfigPaths } from './discovery' | ||
| import { mapKittyToOrca } from './mapper' | ||
| import { loadKittyConfig, type KittyConfig } from './parser' | ||
|
|
||
| const KITTY_IMPORTER: TerminalConfigImporter<KittyConfig> = { | ||
| appName: 'Kitty', | ||
| pickerTitle: () => translateMain('native.dialog.importKittyConfig', 'Import Kitty Config'), | ||
| discover: findKittyConfigPaths, | ||
| // Kitty reads one kitty.conf; anything else arrives through its include directives. | ||
| load: ([entryPath = '']) => loadKittyConfig(entryPath, homedir()), | ||
| map: async (config) => mapKittyToOrca(config, platform() === 'darwin') | ||
| } | ||
|
|
||
| export function previewKittyImport( | ||
| store: Store, | ||
| source?: unknown, | ||
| webContents?: WebContents | ||
| ): Promise<TerminalConfigImportPreview> { | ||
| return previewTerminalConfigImport(KITTY_IMPORTER, store, source, webContents) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Web query:
Kitty terminal configuration file search order XDG_CONFIG_HOME XDG_CONFIG_DIRS ~/.config kitty.conf official documentationResult:
Script executed:
Repository: stablyai/orca
Length of output: 5930
Preserve Kitty’s configuration precedence.
When both candidates exist, place
~/.configbeforeXDG_CONFIG_DIRS. The current order can import a system configuration instead of the user configuration that Kitty selects.Suggested fix
const roots = [ process.env.XDG_CONFIG_HOME, - ...(process.env.XDG_CONFIG_DIRS ?? '').split(':'), '~/.config', + ...(process.env.XDG_CONFIG_DIRS ?? '').split(':'), ...(plat === 'darwin' ? ['~/Library/Preferences'] : []) ]Committable suggestion