3a17d3b9fd
Resolve #1691 by preserving argv boundaries, adding bounded native rg and wc/skill query support, surfacing WSL-to-Windows hints, and splitting the oversized SSH module and embedded remote scripts. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
24 lines
1.5 KiB
PowerShell
24 lines
1.5 KiB
PowerShell
if ($operation -eq 'wc') {
|
|
$showLines = $false; $showWords = $false; $showChars = $false; $showBytes = $false; $paths = [Collections.Generic.List[string]]::new()
|
|
foreach ($arg in $toolArgs) {
|
|
if ($arg -eq '-l' -or $arg -eq '--lines') { $showLines = $true; continue }
|
|
if ($arg -eq '-w' -or $arg -eq '--words') { $showWords = $true; continue }
|
|
if ($arg -eq '-m' -or $arg -eq '--chars') { $showChars = $true; continue }
|
|
if ($arg -eq '-c' -or $arg -eq '--bytes') { $showBytes = $true; continue }
|
|
if ($arg.StartsWith('-') -and $arg -ne '-') { Fail ('unsupported wc option on Windows route: ' + $arg) 2 }
|
|
$paths.Add($arg)
|
|
}
|
|
if ($paths.Count -eq 0) { Fail 'wc requires at least one file path on Windows routes' 2 }
|
|
if (-not ($showLines -or $showWords -or $showChars -or $showBytes)) { $showLines = $true; $showWords = $true; $showChars = $true; $showBytes = $true }
|
|
foreach ($raw in $paths) {
|
|
$path = Resolve-UnideskPath $raw; $text = Read-StrictText $path 1048576; $values = [Collections.Generic.List[string]]::new()
|
|
$lineCount = [regex]::Matches($text, "`n").Count; if ($text.Length -gt 0 -and -not $text.EndsWith("`n")) { $lineCount += 1 }
|
|
if ($showLines) { $values.Add([string]$lineCount) }
|
|
if ($showWords) { $values.Add([string]([regex]::Matches($text, '\S+').Count)) }
|
|
if ($showChars) { $values.Add([string]$text.Length) }
|
|
if ($showBytes) { $values.Add([string]([IO.FileInfo]$path).Length) }
|
|
$values.Add($path); [Console]::Out.WriteLine([string]::Join(' ', $values))
|
|
}
|
|
exit 0
|
|
}
|