简体   繁体   English

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

[英]zsh: refresh prompt after running zle widget

I have the following widget defined我定义了以下小部件

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

After pressing the key combination the cwd is already changed, but the terminal prompt is not updated.按下组合键后,cwd 已更改,但终端提示未更新。 Example, after doing this ()例子,做完这个()

~/tmp/todelete$ | # press key ^R  here; "~$" is the prompt; "|" denotes cursor

the terminal remains exactly unchanged.终端保持完全不变。 If I then type ls -ld .如果我输入ls -ld . , it shows , 表明

~/tmp/todelete$ ls -ld .
dr-xr-xr-x 23 root root 4096 Sep 14 07:52 ./

/$ |

which means the cwd at the time ll is running is already / .这意味着ll运行时的cwd已经是/

This is very confusion and may lead to serious errors.这是非常混乱的,可能会导致严重的错误。 (eg If after pressing ^R I was interrupted to leave my desk and then come back, I might forget what I have done) (例如,如果在按^R我被打扰离开我的办公桌然后回来,我可能会忘记我做了什么)

How can I let the terminal to redraw the prompt after pressing the key?如何让终端在按键后重新绘制提示? Is there a zle function to do this?是否有zle函数来执行此操作?

reset-prompt could rescue: 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.否则,提示只会在每次 zle 启动时扩展,并且当显示被 shell 的另一部分(例如作业通知)的输出中断时,会导致重新打印命令行。

--- zshzle(1), reset-prompt, Miscellaneous, Widgets, zsh command line editor --- zshzle(1), reset-prompt, Miscellaneous, Widgets, zsh 命令行编辑器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM