MCPcopy Create free account
hub / github.com/anus-dev/ANUS / getDiffCommand

Function getDiffCommand

packages/core/src/utils/editor.ts:98–157  ·  view source on GitHub ↗
(
  oldPath: string,
  newPath: string,
  editor: EditorType,
)

Source from the content-addressed store, hash-verified

96 * Get the diff command for a specific editor.
97 */
98export function getDiffCommand(
99 oldPath: string,
100 newPath: string,
101 editor: EditorType,
102): DiffCommand | null {
103 if (!isValidEditorType(editor)) {
104 return null;
105 }
106 const commandConfig = editorCommands[editor];
107 const commands =
108 process.platform === 'win32' ? commandConfig.win32 : commandConfig.default;
109 const command =
110 commands.slice(0, -1).find((cmd) => commandExists(cmd)) ||
111 commands[commands.length - 1];
112
113 switch (editor) {
114 case 'vscode':
115 case 'vscodium':
116 case 'windsurf':
117 case 'cursor':
118 case 'zed':
119 return { command, args: ['--wait', '--diff', oldPath, newPath] };
120 case 'vim':
121 case 'neovim':
122 return {
123 command,
124 args: [
125 '-d',
126 // skip viminfo file to avoid E138 errors
127 '-i',
128 'NONE',
129 // make the left window read-only and the right window editable
130 '-c',
131 'wincmd h | set readonly | wincmd l',
132 // set up colors for diffs
133 '-c',
134 'highlight DiffAdd cterm=bold ctermbg=22 guibg=#005f00 | highlight DiffChange cterm=bold ctermbg=24 guibg=#005f87 | highlight DiffText ctermbg=21 guibg=#0000af | highlight DiffDelete ctermbg=52 guibg=#5f0000',
135 // Show helpful messages
136 '-c',
137 'set showtabline=2 | set tabline=[Instructions]\\ :wqa(save\\ &\\ quit)\\ \\|\\ i/esc(toggle\\ edit\\ mode)',
138 '-c',
139 'wincmd h | setlocal statusline=OLD\\ FILE',
140 '-c',
141 'wincmd l | setlocal statusline=%#StatusBold#NEW\\ FILE\\ :wqa(save\\ &\\ quit)\\ \\|\\ i/esc(toggle\\ edit\\ mode)',
142 // Auto close all windows when one is closed
143 '-c',
144 'autocmd WinClosed * wqa',
145 oldPath,
146 newPath,
147 ],
148 };
149 case 'emacs':
150 return {
151 command: 'emacs',
152 args: ['--eval', `(ediff "${oldPath}" "${newPath}")`],
153 };
154 default:
155 return null;

Callers 2

editor.test.tsFile · 0.85
openDiffFunction · 0.85

Calls 2

isValidEditorTypeFunction · 0.85
commandExistsFunction · 0.70

Tested by

no test coverage detected