简体   繁体   English

zle reset-prompt 不清理提示

[英]zle reset-prompt not cleaning the prompt

I have a key binding to go up by one directory (very useful):我有一个到 go 的键绑定到一个目录(非常有用):

# C-M-u: up-directory
up-directory() {
    builtin cd .. && zle reset-prompt
}
zle -N up-directory
bindkey '\e\C-u' up-directory

It works well, except that the prompt is not really reset.它工作得很好,除了提示没有真正重置。

Example, starting in a Git repo ( ~/.dotfiles ):例如,从 Git 存储库 ( ~/.dotfiles ) 开始:

在此处输入图像描述

After CMu , I get:CMu之后,我得到:

在此处输入图像描述

So, I'm well one level up (into ~ ), but the Git info is still there , while not valid anymore -- I'm not in a Git repo anymore所以,我已经升级了一级(进入~ ),但是Git 信息仍然存在,虽然不再有效——我不再在 Git 回购中......

How to fix this?如何解决这个问题?

You probably need to execute the precmds before resetting the prompt.您可能需要在重置提示之前执行precmds

fzf's zsh integration does this: fzf 的zsh 集成做到了这一点:

# Ensure `precmds` are run after `cd`
fzf-redraw-prompt() {
  local precmd
  for precmd in $precmd_functions; do
    $precmd
  done
  zle reset-prompt
}

So, try something like this:所以,试试这样的事情:

up-directory() {
    builtin cd ..
    if (( $? == 0 )); then
        local precmd
        for precmd in $precmd_functions; do
            $precmd
        done
        zle reset-prompt
    fi
}

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

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