简体   繁体   中英

zle reset-prompt not cleaning the prompt

I have a key binding to go up by one directory (very useful):

# 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 ):

在此处输入图像描述

After CMu , I get:

在此处输入图像描述

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

How to fix this?

You probably need to execute the precmds before resetting the prompt.

fzf's zsh integration does this:

# 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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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