MCPcopy
hub / github.com/codeaashu/claude-code / installBindingsForZed

Function installBindingsForZed

src/commands/terminalSetup/terminalSetup.tsx:462–530  ·  view source on GitHub ↗
(theme: ThemeName)

Source from the content-addressed store, hash-verified

460 }
461}
462async function installBindingsForZed(theme: ThemeName): Promise<string> {
463 // Zed uses JSON keybindings similar to VSCode
464 const zedDir = join(homedir(), '.config', 'zed');
465 const keymapPath = join(zedDir, 'keymap.json');
466 try {
467 // Ensure zed directory exists (idempotent with recursive)
468 await mkdir(zedDir, {
469 recursive: true
470 });
471
472 // Read existing keymap file, or default to empty array if it doesn't exist
473 let keymapContent = '[]';
474 let fileExists = false;
475 try {
476 keymapContent = await readFile(keymapPath, {
477 encoding: 'utf-8'
478 });
479 fileExists = true;
480 } catch (e: unknown) {
481 if (!isFsInaccessible(e)) throw e;
482 }
483 if (fileExists) {
484 // Check if keybinding already exists
485 if (keymapContent.includes('shift-enter')) {
486 return `${color('warning', theme)('Found existing Zed Shift+Enter key binding. Remove it to continue.')}${EOL}${chalk.dim(`See ${formatPathLink(keymapPath)}`)}${EOL}`;
487 }
488
489 // Create backup
490 const randomSha = randomBytes(4).toString('hex');
491 const backupPath = `${keymapPath}.${randomSha}.bak`;
492 try {
493 await copyFile(keymapPath, backupPath);
494 } catch {
495 return `${color('warning', theme)('Error backing up existing Zed keymap. Bailing out.')}${EOL}${chalk.dim(`See ${formatPathLink(keymapPath)}`)}${EOL}${chalk.dim(`Backup path: ${formatPathLink(backupPath)}`)}${EOL}`;
496 }
497 }
498
499 // Parse and modify the keymap
500 let keymap: Array<{
501 context?: string;
502 bindings: Record<string, string | string[]>;
503 }>;
504 try {
505 keymap = jsonParse(keymapContent);
506 if (!Array.isArray(keymap)) {
507 keymap = [];
508 }
509 } catch {
510 keymap = [];
511 }
512
513 // Add the new keybinding for terminal context
514 keymap.push({
515 context: 'Terminal',
516 bindings: {
517 'shift-enter': ['terminal::SendText', '\u001b\r']
518 }
519 });

Callers 1

setupTerminalFunction · 0.85

Calls 10

mkdirFunction · 0.85
readFileFunction · 0.85
isFsInaccessibleFunction · 0.85
colorFunction · 0.85
jsonParseFunction · 0.85
jsonStringifyFunction · 0.85
formatPathLinkFunction · 0.70
toStringMethod · 0.65
logErrorFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected