agkozak / agkozak-zsh-prompt

A fast, asynchronous Zsh prompt with color ASCII indicators of Git, exit, SSH, virtual environment, and vi mode status. Framework-agnostic and customizable.
MIT License
292 stars 26 forks source link

Cmd + k to refresh prompt #45

Open npearson72 opened 5 months ago

npearson72 commented 5 months ago

First off, thanks for the awesome prompt! I was previously using my own but the git checks were slowing it down so I replaced it with yours which is very nice.

One thing I've noticed is that I used to be able to press Cmd + k (to clear my terminal buffer) and it would refresh the state of the prompt.

But with yours I need to press Enter

Is there way to configure it to refresh on Cmd + k ?

npearson72 commented 5 months ago

Just wanted to add some more context which I forgot to include. I use tmux, and this refresh issue is only relevant in the context of switching panes / windows in tmux.

AndydeCleyre commented 4 months ago

Would something like this do the trick?

Not sure exactly what kind of clearing you're after, you may want to use zle kill-whole-line instead of the zle functions I call below, if you don't want to clear the screen (.clear-screen) or have the cleared input reappear at the next prompt (.push-input).

# -- Refresh prompt, rerunning any hooks --
# Credit: Roman Perepelitsa
# Original: https://github.com/romkatv/zsh4humans/blob/v2/fn/-z4h-redraw-prompt
.zle_redraw-prompt () {
  for 1 ( chpwd $chpwd_functions precmd $precmd_functions ) {
    if (( $+functions[$1] ))  $1 &>/dev/null
  }
  zle .reset-prompt
  zle -R
}
zle -N .zle_redraw-prompt

# -- Better Screen Clearing --
# Clear line and redraw prompt, restore line at next prompt
# Key: ctrl+l
# Optional: .zle_redraw-prompt
.zle_push-line-and-clear () {
  zle .push-input
  zle .clear-screen
  if (( $+functions[.zle_redraw-prompt] ))  zle .zle_redraw-prompt
}
zle -N       .zle_push-line-and-clear
bindkey '^L' .zle_push-line-and-clear  # ctrl+l