How to make PowerShell tab completion work like Bash

馋奶兔 提交于 2019-11-27 09:13:24

问题


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?


回答1:


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.




回答2:


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

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




回答3:


Take a look here, not really your desiderata:

PowerTab

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




回答4:


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



来源:https://stackoverflow.com/questions/8264655/how-to-make-powershell-tab-completion-work-like-bash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!