MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / buildEditorCommands

Function buildEditorCommands

cli/src/utils/open-file.ts:28–101  ·  view source on GitHub ↗
(
  filePath: string,
  env: CliEnv = getCliEnv(),
)

Source from the content-addressed store, hash-verified

26}
27
28const buildEditorCommands = (
29 filePath: string,
30 env: CliEnv = getCliEnv(),
31): string[] => {
32 const commands: string[] = []
33 const shellPath = isWindows ? escapeForCmd(filePath) : escapeForShell(filePath)
34 const rawPath = filePath
35
36 // Check custom editor env vars
37 const editorValues = [
38 env.CODEBUFF_CLI_EDITOR,
39 env.CODEBUFF_EDITOR,
40 env.VISUAL,
41 env.EDITOR,
42 ]
43
44 for (const value of editorValues) {
45 if (!value) continue
46 const withFile = replaceFilePlaceholder(value, rawPath)
47 if (withFile !== value) {
48 commands.push(withFile)
49 } else {
50 commands.push(`${value} ${isWindows ? shellPath : shellPath}`)
51 }
52 }
53
54 const termProgram = (env.TERM_PROGRAM || '').toLowerCase()
55 const candidates: Array<{ detect: boolean; command: string }> = [
56 {
57 detect:
58 termProgram.includes('vscode') ||
59 env.VSCODE_GIT_IPC_HANDLE !== undefined ||
60 env.VSCODE_PID !== undefined,
61 command: `code --goto ${shellPath}`,
62 },
63 {
64 detect:
65 termProgram.includes('cursor') ||
66 env.CURSOR_PORT !== undefined ||
67 env.CURSOR !== undefined,
68 command: `cursor --goto ${shellPath}`,
69 },
70 {
71 detect:
72 termProgram.includes('zed') ||
73 env.ZED_NODE_ENV !== undefined,
74 command: `zed --add ${shellPath}`,
75 },
76 {
77 detect: termProgram.includes('sublime'),
78 command: `subl ${shellPath}`,
79 },
80 {
81 detect: termProgram.includes('atom'),
82 command: `atom ${shellPath}`,
83 },
84 ]
85

Callers 1

openFileAtPathFunction · 0.85

Calls 4

getCliEnvFunction · 0.90
escapeForCmdFunction · 0.85
escapeForShellFunction · 0.85
replaceFilePlaceholderFunction · 0.85

Tested by

no test coverage detected