1

Similar to this question, but instead of adding a new line to the end of the prompt, add a new line to the beginning of the long command (when a command reaches to the right side of the command line window).

I believe I saw such behavior in fish as shown in this video. It only adds newline to the line containing the prompt.

I'm using zsh (v5.8) on Linux (kernel: v5.10)

Edit:

How can I implement such behavior in zsh or bash?

1 Answer 1

2

In zsh, you could do something like:

zle-line-pre-redraw() {
  (( BUFFERLINES == 1 + ${#BUFFER//[^$'\n']} )) || PREDISPLAY=$'\n'
}
zle -N zle-line-pre-redraw

Which prepends a newline if the number of lines to display to render the buffer is greater than the number of newline characters plus 1 (meaning at least one line overflowed or PREDISPLAY was already set to newline for that buffer).

3
  • It works nicely; thank you!! Sorry, I couldn't understand your explanation. What do you mean by number of lines?
    – ali b
    Sep 30, 2021 at 15:49
  • 1
    @alib, $BUFFERLINES contains the number of lines / rows needed to display the editing buffer. It starts at 1, if you enter a line long enough so as to wrap, it will be 2. It would also be 2 if you enter a literal newline character in the buffer (with Esc Enter or Ctrl-V Ctrl-J) so we take that into account. Sep 30, 2021 at 15:52
  • Now I see!! Thanks!!!
    – ali b
    Sep 30, 2021 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.