Elffuss BraidHub

kikocis/continue public

Fix: improve command extraction in RunInTerminalButton (#5724)
Changeset097e009e2978f54bcf694a49aaba2323a672f2a55c2a5915d884fa2c7415ab5b
AuthorSaim <saimadib2002@gmail.com> · 2025-05-20 08:52 +05:30
CommitterSaim <saimadib2002@gmail.com> · 2025-05-20 08:52 +05:30
Parents5bee654fd479

Browse the files at this changeset

1 file changed

modified gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/RunInTerminalButton.tsx +28 −4
@@ -18,14 +18,38 @@
1818
1919 // Extract just the command line (the line after $ or the first line)
2020 function extractCommand(cmd: string): string {
21- // If the command contains a $ prompt, extract the line after it
21+ // First handle the $ prompt case, extract the line after it
2222 if (cmd.includes("$")) {
2323 const match = cmd.match(/\$\s*([^\n]+)/);
24- return match ? match[1].trim() : "";
24+ if (match) {
25+ return match[1].trim();
26+ }
2527 }
2628
27- // Otherwise, just take the first line
28- return cmd.split("\n")[0].trim();
29+ // Process all lines, filtering out comments and empty lines
30+ const lines = cmd.split("\n")
31+ .map(line => line.trim())
32+ .filter(line =>
33+ line &&
34+ !line.startsWith("#") &&
35+ !line.startsWith("//") &&
36+ !line.startsWith("/*")
37+ );
38+
39+ // Handle multi-line commands
40+ let result = "";
41+ for (let i = 0; i < lines.length; i++) {
42+ const line = lines[i];
43+ result += line;
44+
45+ // Add space for command continuation
46+ if (line.endsWith("&&") || line.endsWith("|") || line.endsWith("\\")) {
47+ result += " ";
48+ } else if (i < lines.length - 1) {
49+ result += " ";
50+ }
51+ }
52+ return result.trim();
2953 }
3054
3155 function runInTerminal() {