MCPcopy
hub / github.com/codeaashu/claude-code / extractBaseCommand

Function extractBaseCommand

src/tools/PowerShellTool/commandSemantics.ts:100–111  ·  view source on GitHub ↗

* Extract the command name from a single pipeline segment. * Strips leading `&` / `.` call operators and `.exe` suffix, lowercases.

(segment: string)

Source from the content-addressed store, hash-verified

98 * Strips leading `&` / `.` call operators and `.exe` suffix, lowercases.
99 */
100function 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.

Callers 1

Calls 1

popMethod · 0.80

Tested by

no test coverage detected