YarnComplete.psm1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
$GetCompletion = { param($commandName, $wordToComplete, $cursorPosition) if (-not (Test-Path .\package.json)) { return } $startMatch = [Text.RegularExpressions.Regex]::Match($wordToComplete, '\s([^\s]*)') if (-not $startMatch.Success) { return } $start = $startMatch.Groups[1].Value try { $packageInfo = Get-Content -Raw -Encoding UTF8 .\package.json | ConvertFrom-Json $scripts = Get-Member -InputObject $packageInfo.scripts | ? {$_.MemberType -eq 'NoteProperty'} | Select-Object -ExpandProperty Name return $scripts | Where-Object { $_ -like "$start*" } | ForEach-Object { New-Object -Type System.Management.Automation.CompletionResult -ArgumentList @($_, $_, "ParameterValue", $_) } } catch { return } } Register-ArgumentCompleter -Native -CommandName 'yarn' -ScriptBlock $GetCompletion |