How to make PowerShell tab completion work like Bash

RobSiklos picture RobSiklos · Nov 25, 2011 · Viewed 44.6k times · Source

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.

  • In Bash, it gets expanded to ./build

  • In PowerShell, it gets expanded to ./buildBar.bat -- the first item in the list.

  • In Cmd, the behavior is the same as PowerShell.

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

Answer

svick picture svick · Jun 9, 2016

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

Set-PSReadlineKeyHandler -Key Tab -Function Complete

To make it permanent, put this command into C:\Users\[User]\Documents\WindowsPowerShell\profile.ps1.