powershellcmdtab-completion

How to make PowerShell tab completion work like Bash


Let's say I have the following files in my current directory:

buildBar.bat
buildFoo.bat
buildHouse.bat

And I type the following at my command prompt, ./bu and then TAB.

I prefer the Bash behaviour - is there a way to make PowerShell behave like Bash?


Solution

  • New versions of PowerShell include PSReadline, which can be used to do this:

    Set-PSReadlineKeyHandler -Key Tab -Function Complete
    

    or, to make it even more like bash where you can use arrow-keys to navigate available options:

    Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
    

    To make it permanent, put this command into your powershell profile, defined by $PROFILE (usually %UserProfile%\Documents\WindowsPowerShell\profile.ps1 for Windows PowerShell 5.x and %UserProfile%\Documents\PowerShell\profile.ps1 for PowerShell 6+).