Skip to content

Commit 7f674f4

Browse files
CopilotTyriar
andcommitted
Fix git diff completions on Windows by removing sed dependency
Co-authored-by: Tyriar <[email protected]>
1 parent 4cf4cda commit 7f674f4

File tree

1 file changed

+37
-18
lines changed
  • extensions/terminal-suggest/src/completions

1 file changed

+37
-18
lines changed

extensions/terminal-suggest/src/completions/git.ts

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,22 @@ export const gitGenerators = {
464464
} satisfies Fig.Generator,
465465

466466
getStagedFiles: {
467-
script: [
468-
"bash",
469-
"-c",
470-
"git --no-optional-locks status --short | sed -ne '/^M /p' -e '/A /p'",
471-
],
472-
postProcess: postProcessTrackedFiles,
467+
script: ["git", "--no-optional-locks", "status", "--short"],
468+
postProcess: (out, context) => {
469+
const output = filterMessages(out);
470+
471+
if (output.startsWith("fatal:")) {
472+
return [];
473+
}
474+
475+
// Filter lines that start with 'M ' (modified in index) or contain 'A ' (added)
476+
// Equivalent to: sed -ne '/^M /p' -e '/A /p'
477+
const filteredLines = output.split("\n").filter(line => {
478+
return line.match(/^M /) || line.match(/A /);
479+
});
480+
481+
return postProcessTrackedFiles(filteredLines.join("\n"), context);
482+
},
473483
},
474484

475485
getUnstagedFiles: {
@@ -478,22 +488,31 @@ export const gitGenerators = {
478488
} satisfies Fig.Generator,
479489

480490
getChangedTrackedFiles: {
481-
script: function (context) {
491+
script: ["git", "--no-optional-locks", "status", "--short"],
492+
postProcess: (out, context) => {
493+
const output = filterMessages(out);
494+
495+
if (output.startsWith("fatal:")) {
496+
return [];
497+
}
498+
499+
let filteredLines;
482500
if (context.includes("--staged") || context.includes("--cached")) {
483-
return [
484-
"bash",
485-
"-c",
486-
`git --no-optional-locks status --short | sed -ne '/^M /p' -e '/A /p'`,
487-
];
501+
// Filter lines that start with 'M ' or contain 'A '
502+
// Equivalent to: sed -ne '/^M /p' -e '/A /p'
503+
filteredLines = output.split("\n").filter(line => {
504+
return line.match(/^M /) || line.match(/A /);
505+
});
488506
} else {
489-
return [
490-
"bash",
491-
"-c",
492-
`git --no-optional-locks status --short | sed -ne '/M /p' -e '/A /p'`,
493-
];
507+
// Filter lines that contain 'M ' or 'A ' anywhere
508+
// Equivalent to: sed -ne '/M /p' -e '/A /p'
509+
filteredLines = output.split("\n").filter(line => {
510+
return line.match(/M /) || line.match(/A /);
511+
});
494512
}
513+
514+
return postProcessTrackedFiles(filteredLines.join("\n"), context);
495515
},
496-
postProcess: postProcessTrackedFiles,
497516
} satisfies Fig.Generator,
498517
};
499518

0 commit comments

Comments
 (0)