How to make PowerShell tab completion work like Bash

后端 未结 7 1023
囚心锁ツ
囚心锁ツ 2020-12-12 10:17

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 comm

相关标签:
7条回答
  • 2020-12-12 10:58

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

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

    0 讨论(0)
  • 2020-12-12 11:02

    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.

    0 讨论(0)
  • 2020-12-12 11:02
    # 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
    
    0 讨论(0)
  • 2020-12-12 11:09

    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

    0 讨论(0)
  • 2020-12-12 11:10

    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.

    0 讨论(0)
  • 2020-12-12 11:17

    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

    0 讨论(0)
提交回复
热议问题