Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zle reset-prompt not cleaning the prompt

Tags:

zsh

zsh-zle

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

enter image description here

After C-M-u, I get:

enter image description here

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?

like image 455
user3341592 Avatar asked Oct 22 '25 04:10

user3341592


1 Answers

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
}
like image 194
Fred Dubois Avatar answered Oct 24 '25 04:10

Fred Dubois