Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make PowerShell tab completion work like Bash

People also ask

How do I enable tab completion in PowerShell?

You can add argument completers to any PowerShell command to get PowerShell tab completion; either a default, built-in cmdlet, or a custom function. Let's first cover how to create an argument for a custom function called Do-Thing . The Do-Thing function is a simple function with a single parameter Name .

Does PowerShell have autocomplete?

PowerShell has some neat, and often underused features that can be enabled to help you have that autocomplete functionality. You can enable it just for a certain PowerShell session or you can enable it so that every session has it enabled.

How do I enable IntelliSense in PowerShell?

You can enable the predictive IntelliSense feature with the option cmdlet for PSReadline. To disable the feature, set the source back to none.


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.


It is now possible to get PowerShell to do Bash-style completion, using PSReadline.

Check out blog post Bash-like tab completion in PowerShell.


tab only completes the command name not its previous arguments/parameters.

to also autocomplete the complete command with arguments from history set the below keybinding.

Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

Now, type few characters of command name and use up/down arrow to autocomplete this command (with arguments) from history.

real time saver.


Take a look here, not really your desiderata:

PowerTab

but I think is the best tab expansion feature for PowerShell console!!!


# keep or reset to powershell default
Set-PSReadlineKeyHandler -Key Shift+Tab -Function TabCompletePrevious

# define Ctrl+Tab like default Tab behavior
Set-PSReadlineKeyHandler -Key Ctrl+Tab -Function TabCompleteNext

# define Tab like bash
Set-PSReadlineKeyHandler -Key Tab -Function Complete

Modify the TabExpansion function to achieve what you want. Remember that perhaps it completes till the end if you press tab again the new suggestion modify from where you originally press the key. I strongly prefer the actual behaviour, I want the line writted as fast as possible. Finally don't forget the wildcard expansion, for example: bu*h[Tab] automatically completes to buildHouse.bat


With Powershell Core we can set the PredictionSource property for PSReadLine as History to get auto suggestion. Refer to the YouTube video for more details https://youtu.be/I0iIZe0dUNw