Skip to content

Instantly share code, notes, and snippets.

@trackd
Created September 6, 2025 18:27
Show Gist options
  • Select an option

  • Save trackd/e470d5976d8205afcd191a2bc0ef996b to your computer and use it in GitHub Desktop.

Select an option

Save trackd/e470d5976d8205afcd191a2bc0ef996b to your computer and use it in GitHub Desktop.
function Send-Completion {
<#
https://github.com/microsoft/terminal/wiki/Experimental-Shell-Completion-Menu
#>
[CmdletBinding()]
param()
try {
$a = [char]7 # BEL, `a
$e = [char]27 # ESC, `e
$InputString = [string]::Empty
$CursorIndex = 0
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$InputString, [ref]$CursorIndex)
$sb = [Text.StringBuilder]::new().Append("$e]633;Completions")
if (-Not [String]::IsNullOrEmpty($InputString)) {
$CompletionResults = TabExpansion2 -inputScript $InputString -cursorColumn $CursorIndex
if ($CompletionResults.CompletionMatches) {
[void] $sb.
AppendFormat(
';{0};{1};{2};',
$CompletionResults.ReplacementIndex,
$CompletionResults.ReplacementLength,
$CursorIndex
).
Append(
($CompletionResults.CompletionMatches | ConvertTo-Json -Compress)
)
}
}
Write-Host -NoNewline $sb.Append($a).ToString()
}
catch {
throw
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment