Skip to content

Instantly share code, notes, and snippets.

@lzybkr
Created May 8, 2019 02:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lzybkr/06f033df7c9ca8aa7628f64d28187acf to your computer and use it in GitHub Desktop.
Save lzybkr/06f033df7c9ca8aa7628f64d28187acf to your computer and use it in GitHub Desktop.
# Autocompletion for clang
# Autocompletion for clang - only works in pwsh
Register-ArgumentCompleter -CommandName clang -Native -ScriptBlock {
param($wordToComplete, $commandAst)
if ($wordToComplete.StartsWith('-')) {
$p,$a = $wordToComplete -split '=',2
if ($null -ne $a) {
$clangArg = "$p=,$a"
$type = [System.Management.Automation.CompletionResultType]::ParameterValue
} else {
$clangArg = $p
$type = [System.Management.Automation.CompletionResultType]::ParameterName
}
foreach ($completion in clang --autocomplete=$clangArg) {
$text,$tooltip = $completion -split "\s+", 2
if (!$tooltip) { $tooltip = $text }
$listItem = $text
if ($null -ne $a) {
$text = "$p=$text"
}
[System.Management.Automation.CompletionResult]::new($text, $listItem, $type, $toolTip)
}
}
# TODO: complete files based on extension, e.g. only c/cpp files?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment