Search code examples
terminalzshoh-my-zshiterm2

Clear terminal without clearing first line of multi-line prompt


I'm trying to setup the terminal on my new Mac to match the behavior of my old Mac, however I have run into an issue with my multiline prompt that has me stumped. I remember having this issue when I setup my old Mac several years ago, however I don't remember how I solved it.

My prompt (without color) looks like this:

╭─username ~                                   130 ↵
╰─ 

When I press ⌘commandK in iTerm2 on my old Mac it clears the terminal window so that both lines of the prompt are shown at the top.

When I press ⌘commandK in iTerm2 on my new Mac it clears the terminal window so that only the second line of the prompt is shown at the top.

I have tried checking everything I could think of, I have checked:

  • Every dot file/directory in my home directory (copied them to the new Mac).
  • iTerm2 settings.
  • System settings (primarily keyboard shortcuts).
  • Various websites with instructions about setting up multi-line prompts.

Interestingly I have discovered that if I type clear iTerm2 will clear the screen and leave the top line showing on both Macs. However it first clears the entire screen, including the prompt, before bringing the prompt back (looks bad imo). However since it works differently ⌘commandK does I don't think that's what my old Mac is doing.

It's possible that I installed some program/script that somehow does this, but if so I'm not finding it locally or referenced online.

Does anyone know how I can get ⌘commandK working to clear the screen while keeping the top line of my prompt? I still have the old Mac so I can check/compare anything on it to the new Mac if there are any guesses about what settings I changed.

Edit: I was able to find something that worked, however if anyone has any other suggestions I'll be happy to try them and accept any that I can make work that are less hacky than this (e.g. don't require another 3rd party app).


Solution

  • Do you have iTerm2's shell integration installed? It's what provides this functionality:

    Shell Integration works by configuring your shell on each host you log into to send special escape codes that convey the following information:

    • Where the command prompt begins and ends.
    • Where a command entered at the command prompt ends and its output begins. [...]