Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmd + k to refresh prompt #45

Open
npearson72 opened this issue May 21, 2024 · 2 comments
Open

Cmd + k to refresh prompt #45

npearson72 opened this issue May 21, 2024 · 2 comments
Assignees

Comments

@npearson72
Copy link

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 ?

@agkozak agkozak self-assigned this May 22, 2024
@npearson72
Copy link
Author

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants