Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to redraw the zsh prompt after widget action

Using zsh, i would like to add a shortcut to go in parent directory. Easy peasy to do that

cdup() {
  builtin cd ..
}
zle -N cdup
bindkey "your_favorite_key_code" cdup

But this does not redraw the prompt, anybody knows how to do it?

Binding shortcuts to do pushd/popd could be an idea too, to be honest i got those ideas from the "fish shell".

like image 211
lolesque Avatar asked Feb 09 '12 14:02

lolesque


1 Answers

I've recently implemented the exact same thing. The best solution I can come up with is the following

cdup() {
  cd ..
  zle reset-prompt
}

The zle reset-prompt is the bit that gets it to redraw the prompt.

Edit:
My previous version of the answer had a printf '\n' in the answer. This was necessary if the prompt was a multi-line prompt. However zsh apparently has tons of issues with mutli-lines prompts, so I dropped it.

like image 173
phemmer Avatar answered Sep 28 '22 07:09

phemmer