Skip to content

Instantly share code, notes, and snippets.

@krymtkts
Last active July 18, 2021 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krymtkts/b2e6742691fdca6ca09567ca146063df to your computer and use it in GitHub Desktop.
Save krymtkts/b2e6742691fdca6ca09567ca146063df to your computer and use it in GitHub Desktop.
$psake = Get-Command -Name Invoke-psake -ErrorAction SilentlyContinue
if ($psake) {
Register-ArgumentCompleter -Native -CommandName $psake.Name -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
Get-ChildItem "$wordToComplete*.ps1" | Select-Object -ExpandProperty Name
}
Register-ArgumentCompleter -CommandName $psake.Name -ParameterName taskList -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
if ($commandAst -match '(?<file>[^\.]*\.ps1)') {
$file = $Matches.file
}
else {
$file = 'psakefile.ps1'
}
& $commandName -buildFile $file -docs -nologo | Out-String -Stream | ForEach-Object { if ($_ -match "^[^ ]*") { $matches[0] } } | `
Where-Object { $_ -notin ('Name', '----', '') } | Where-Object { !$wordToComplete -or $_ -like "$wordToComplete*" }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment