4

When writing in command line I have this aversion to scrolling my eyes down to the bottom of the page as I write commands.

How do I keep the cursor/line at the top and allow the output to be displayed below it every time I write and execute a command? Has anyone ever tried to accomplish this?

3
  • 2
    Unless output of your programs is scrolled down (instead of up), this would somehow break the natural order of things, where commands are followed by their output in the terminal. Moreover, once one screenful of output is shown, your prompt line is going to stay in the same place - at the bottom of the terminal window. No need to move your eyes from there, if that really is the problem.
    – peterph
    Aug 31, 2013 at 22:25
  • That's a good point. It's definitely the prompt being at the bottom thats the issue, especially on larger resolutions. I'm researching how to accomplish this using tmux. One small interface at the top that directs its output to the bottom, larger interface.
    – Seph
    Sep 1, 2013 at 0:10
  • For simple commands you could use a named pipe (see mkfifo) to feed some input to another shell. Won't work for TUIs though.
    – peterph
    Sep 2, 2013 at 23:11

1 Answer 1

3

You can do something like that by adding

\[\e[f\e[K\]

at the beginning of your prompt variable (PS1). But it doesn't take scrolling into account.

\[      start non-printing sequence
\e[f    ANSI escape sequence to move cursor to position 1;1
\e[K    ANSI escape sequence to erase from cursor to end of line
\]      end of non-printing sequence
3
  • I just add explicitly: this of course messes up the output of many programs - once the buffer is scrolled, the first line contains regular output and the prompt overwrites it.
    – peterph
    Aug 31, 2013 at 22:23
  • Nice, but yeah, the scrolling poses a natural barrier.
    – Seph
    Sep 1, 2013 at 0:10
  • Did you get any better solution that takes into account scrolling as well?
    – Mahesh M
    Feb 18, 2019 at 15:17

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.