英文:
How to clear line or password prompt in Windows PowerShell like CTRL+U in Linux?
问题
在使用Linux时,您可以使用CTRL+U
来清除当前提示符。当输入密码时,如果需要清除当前(隐藏的)密码以便重新输入,例如因为您输入了错误,这非常有用。
然而,在Windows PowerShell中,使用Windows终端,默认情况下不会起作用。当您按下CTRL+U
时,您会看到^U
而不是清除该行。当然,这对于密码提示也不起作用,比如在C:\WINDOWS\System32\OpenSSH\ssh.exe
中。
哪个进程负责此功能?是Windows Terminal
、PowerShell
、PSReadLine
吗?我猜想它不是ssh.exe
。
是否有已知的方法来实现这一功能?
英文:
When using Linux, you can use CTRL+U
for clearing the current prompt. This is very useful, when entering a password and you need to clear the current (hidden) password, to write it again, for example because you made a typo.
However, this will not work out-of-the-box in Windows PowerShell, using Windows Terminal. When you press CTRL+U
, you will see ^U
instead of clearing the line. Of course, this will not work for password prompt also, like in C:\WINDOWS\System32\OpenSSH\ssh.exe
.
Which process would responsible for this feature? Windows Terminal
, PowerShell
, PSReadLine
? I guess, it's not ssh.exe
.
Is there any known way to achieve this feature?
答案1
得分: 1
没有经过密码提示的测试,但与我在Linux终端中习惯的情况相似的是这个绑定:
Set-PSReadLineKeyHandler -Key Ctrl+u -Function BackwardDeleteLine
还可以参考文档了解其他可用的功能。
与ESC
不同,它只删除光标前面的部分,保留剩下的输入。
英文:
Not tested with password prompts, but what comes pretty close to what I am used from Linux terminals is this binding:
Set-PSReadLineKeyHandler -Key Ctrl+u -Function BackwardDeleteLine
See also the documentation for other available functions.
In contrast to ESC
, it only removes the part in front of the cursor and keeps the remaining input.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论