gpt4 book ai didi

zsh:运行 zle 小部件后刷新提示

转载 作者:行者123 更新时间:2023-12-04 18:56:18 24 4
gpt4 key购买 nike

我定义了以下小部件

function cdd()
{
cd /
}
zle -N cdd{,}
bindkey "^R" cdd

按下组合键后,cwd 已更改,但终端提示未更新。例子,做完这个()
~/tmp/todelete$ | # press key ^R  here; "~$" is the prompt; "|" denotes cursor

终端保持完全不变。如果我输入 ls -ld . , 表明
~/tmp/todelete$ ls -ld .
dr-xr-xr-x 23 root root 4096 Sep 14 07:52 ./

/$ |

这意味着 cwd当时 ll正在运行已经 / .

这是非常困惑的,可能会导致严重的错误。 (例如,如果在按下 ^R 之后我被打扰离开我的办公 table 然后回来,我可能会忘记我做了什么)

如何让终端在按键后重新绘制提示?有没有 zle功能来做到这一点?

最佳答案

reset-prompt可以拯救:

function cdd()
{
cd /
zle reset-prompt # XXX: added
}

reset-prompt

Force the prompts on both the left and right of the screen to be re-expanded, then redisplay the edit buffer. This reflects changes both to the prompt variables themselves and changes in the expansion of the values (for example, changes in time or directory, or changes to the value of variables referred to by the prompt).

Otherwise, the prompt is only expanded each time zle starts, and when the display as been interrupted by output from another part of the shell (such as a job notification) which causes the command line to be reprinted.

--- zshzle(1), reset-prompt, Miscellaneous, Widgets, zsh command line editor

关于zsh:运行 zle 小部件后刷新提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52325626/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com