Pure: ⌘K to not clear 1st line of prompt - is it possible?

Created on 3 Dec 2018  Â·  4Comments  Â·  Source: sindresorhus/pure

When you hit ⌘K in iTerm (Edit › Clear Buffer), the 1st line of the prompt (that displays the current path) disappears, which is probably the expected behaviour, but I'd prefer it if it didn't disappear so that I can see the current path.

Is there a way to prevent that 1st line from disappearing on ⌘K?

Thanks!


To illustrate the question:

image

on ⌘K becomes:

image

Most helpful comment

As far as I know, it's not possible. iTerm doesn't notify the shell that the screen has been cleared and as such, there's no way for zsh to know it should re-render the prompt. You could use Ctrl+L instead, I know it's not the same, but it's the best we can offer.

All 4 comments

As far as I know, it's not possible. iTerm doesn't notify the shell that the screen has been cleared and as such, there's no way for zsh to know it should re-render the prompt. You could use Ctrl+L instead, I know it's not the same, but it's the best we can offer.

@erusev this came to mind while reading some iTerm documentation the other day:

prompt_pure_cmd_k() {
    # Enable output to terminal and clear iTerm2 scrollback, the newline
    # adds an empty row at the beginning, similar to `clear`.
    zle -I
    print -n '\e]1337;ClearScrollback\a\n'
}

zle -N clear-screen prompt_pure_cmd_k

It's not exactly what you wanted but you could for example assign some other key combination that triggers the prompt_pure_cmd_k widget. Right now it replaces Ctrl+L, which would start clearing scrollback as well. In an earlier iteration of it I manually triggered zle .clear-screen (and zle .reset-prompt) as well, but turns out it's not needed. Hope you find some use for it 😄.

Awesome, thanks!

While searching elsewhere for an answer to this question, I stumbled on this StackOverflow which led me to add this snippet to work around the clear-screen issue:

clear-screen() { echoti clear; prompt_pure_precmd; zle redisplay; }
zle -N clear-screen

Works for me; maybe it'll work for you ¯\_(ツ)_/¯.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

harukizaemon picture harukizaemon  Â·  10Comments

opticalgenesis picture opticalgenesis  Â·  9Comments

Rawnly picture Rawnly  Â·  9Comments

parro-it picture parro-it  Â·  10Comments

tyrollins picture tyrollins  Â·  4Comments