asdf
Squash the current repository state back into one baseline commit while preserving the README reframing and repository contents. Constraint: User explicitly requested a single squashed commit with subject "asdf" Confidence: high Scope-risk: broad Reversibility: clean Directive: This commit intentionally rewrites published history; coordinate before future force-pushes Tested: git status clean; local history rewritten to one commit; force-pushed main to origin and instructkr Not-tested: Fresh clone verification after push
This commit is contained in:
commit
d2542c9a62
13
src/commands/keybindings/index.ts
Normal file
13
src/commands/keybindings/index.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { Command } from '../../commands.js'
|
||||
import { isKeybindingCustomizationEnabled } from '../../keybindings/loadUserBindings.js'
|
||||
|
||||
const keybindings = {
|
||||
name: 'keybindings',
|
||||
description: 'Open or create your keybindings configuration file',
|
||||
isEnabled: () => isKeybindingCustomizationEnabled(),
|
||||
supportsNonInteractive: false,
|
||||
type: 'local',
|
||||
load: () => import('./keybindings.js'),
|
||||
} satisfies Command
|
||||
|
||||
export default keybindings
|
||||
53
src/commands/keybindings/keybindings.ts
Normal file
53
src/commands/keybindings/keybindings.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { mkdir, writeFile } from 'fs/promises'
|
||||
import { dirname } from 'path'
|
||||
import {
|
||||
getKeybindingsPath,
|
||||
isKeybindingCustomizationEnabled,
|
||||
} from '../../keybindings/loadUserBindings.js'
|
||||
import { generateKeybindingsTemplate } from '../../keybindings/template.js'
|
||||
import { getErrnoCode } from '../../utils/errors.js'
|
||||
import { editFileInEditor } from '../../utils/promptEditor.js'
|
||||
|
||||
export async function call(): Promise<{ type: 'text'; value: string }> {
|
||||
if (!isKeybindingCustomizationEnabled()) {
|
||||
return {
|
||||
type: 'text',
|
||||
value:
|
||||
'Keybinding customization is not enabled. This feature is currently in preview.',
|
||||
}
|
||||
}
|
||||
|
||||
const keybindingsPath = getKeybindingsPath()
|
||||
|
||||
// Write template with 'wx' flag (exclusive create) — fails with EEXIST if
|
||||
// the file already exists. Avoids a stat pre-check (TOCTOU race + extra syscall).
|
||||
let fileExists = false
|
||||
await mkdir(dirname(keybindingsPath), { recursive: true })
|
||||
try {
|
||||
await writeFile(keybindingsPath, generateKeybindingsTemplate(), {
|
||||
encoding: 'utf-8',
|
||||
flag: 'wx',
|
||||
})
|
||||
} catch (e: unknown) {
|
||||
if (getErrnoCode(e) === 'EEXIST') {
|
||||
fileExists = true
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
// Open in editor
|
||||
const result = await editFileInEditor(keybindingsPath)
|
||||
if (result.error) {
|
||||
return {
|
||||
type: 'text',
|
||||
value: `${fileExists ? 'Opened' : 'Created'} ${keybindingsPath}. Could not open in editor: ${result.error}`,
|
||||
}
|
||||
}
|
||||
return {
|
||||
type: 'text',
|
||||
value: fileExists
|
||||
? `Opened ${keybindingsPath} in your editor.`
|
||||
: `Created ${keybindingsPath} with template. Opened in your editor.`,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user