MCPcopy Create free account
hub / github.com/github/gh-aw / formatBashCommand

Function formatBashCommand

actions/setup/js/log_parser_shared.cjs:164–186  ·  view source on GitHub ↗

* Formats a bash command by normalizing whitespace and escaping * @param {string} command - The raw bash command string * @returns {string} Formatted and escaped command string

(command)

Source from the content-addressed store, hash-verified

162 * @returns {string} Formatted and escaped command string
163 */
164function formatBashCommand(command) {
165 if (!command) return "";
166
167 // Convert multi-line commands to single line by replacing newlines with spaces
168 // and collapsing multiple spaces
169 let formatted = command
170 .replace(/\n/g, " ") // Replace newlines with spaces
171 .replace(/\r/g, " ") // Replace carriage returns with spaces
172 .replace(/\t/g, " ") // Replace tabs with spaces
173 .replace(/\s+/g, " ") // Collapse multiple spaces into one
174 .trim(); // Remove leading/trailing whitespace
175
176 // Escape backticks to prevent markdown issues
177 formatted = formatted.replace(/`/g, "\\`");
178
179 // Truncate if too long (keep reasonable length for summary)
180 const maxLength = 300;
181 if (formatted.length > maxLength) {
182 formatted = formatted.substring(0, maxLength) + "...";
183 }
184
185 return formatted;
186}
187
188/**
189 * Truncates a string to a maximum length with ellipsis

Callers 4

formatToolUseFunction · 0.85
appendToolExecutionLineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected