* Extract the command name from a single pipeline segment. * Strips leading `&` / `.` call operators and `.exe` suffix, lowercases.
(segment: string)
| 98 | * Strips leading `&` / `.` call operators and `.exe` suffix, lowercases. |
| 99 | */ |
| 100 | function extractBaseCommand(segment: string): string { |
| 101 | // Strip PowerShell call operators: & "cmd", . "cmd" |
| 102 | // (& and . at segment start followed by whitespace invoke the next token) |
| 103 | const stripped = segment.trim().replace(/^[&.]\s+/, '') |
| 104 | const firstToken = stripped.split(/\s+/)[0] || '' |
| 105 | // Strip surrounding quotes if command was invoked as & "grep.exe" |
| 106 | const unquoted = firstToken.replace(/^["']|["']$/g, '') |
| 107 | // Strip path: C:\bin\grep.exe → grep.exe, .\rg.exe → rg.exe |
| 108 | const basename = unquoted.split(/[\\/]/).pop() || unquoted |
| 109 | // Strip .exe suffix (Windows is case-insensitive) |
| 110 | return basename.toLowerCase().replace(/\.exe$/, '') |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Extract the primary command from a PowerShell command line. |
no test coverage detected