如何在Windows PowerShell中清除行或密码提示,类似于Linux中的CTRL+U?

huangapple go评论64阅读模式
英文:

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 TerminalPowerShellPSReadLine吗?我猜想它不是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.

huangapple
  • 本文由 发表于 2023年2月6日 18:44:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75360258.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定