Cycle through only specific file types in PS using custom tab completion on the command line Cycle through only specific file types in PS using custom tab completion on the command line powershell powershell

Cycle through only specific file types in PS using custom tab completion on the command line


Use the Register-ArgumentCompleter cmdlet (PSv5+):

# With `java`, cycle through *.java files, but without the extension.Register-ArgumentCompleter -Native -CommandName java -ScriptBlock {    param($wordToComplete)    (Get-ChildItem $wordToComplete*.java).BaseName}# With `javac`, cycle through *.java files, but *with* the extension.Register-ArgumentCompleter -Native -CommandName javac -ScriptBlock {    param($wordToComplete)    (Get-ChildItem $wordToComplete*.java).Name}

To define an alternative key or chord for invoking completion, use Set-PSReadLineKeyHandler; e.g., to make Ctrl+K invoke completions:

Set-PSReadLineKeyHandler -Key ctrl+k -Function TabCompleteNextSet-PSReadLineKeyHandler -Key ctrl+shift+k -Function TabCompletePrevious

Note that this affects completion globally - you cannot implement a command-specific completion key that way.