8

It occurred to me recently that it would occasionally be much better to type terminal/command line commands at the top of a window, with the last run commands below. The reverse of the usual display.

On smaller laptop screens for example, it's much more comfortable to focus at the top of the screen, than at the bottom.

Regardless of wether this is a good idea or not, does such a terminal / command line plugin exist for achieving this?

(I'm mostly OS X based, but interested in all platform solutions)

3
  • 1
    Multi-line output would be really awkward to read.
    – Daniel Beck
    Nov 10, 2010 at 16:18
  • @Daniel Beck, I suppose that could still go top to bottom - just below my current line..... but i see your point, it wouldn't just be a simple 'reverse all'.
    – Jon Hadley
    Nov 10, 2010 at 16:29
  • 5
    Right, and after it's filled a page you need to scroll back up to see the current (not the previous) prompt. That's the really awkward behaviour, not the highway line order alternative.
    – Daniel Beck
    Nov 10, 2010 at 16:50

1 Answer 1

5

Here's something to play with in Bash.

To set it up:

$ bash    # try this in a subshell since ^C seems to cause it to exit
$ f () { sed "1s/^/$(tput cup 0 0)/;s/^/$(tput il1)/"; }
$ PROMPT_COMMAND='tput cup 0 0;tput il1; echo'
$ exec > >(f)

Press enter one extra time and it's ready to try. Sometimes the output and the prompt are out of order and there may be other weirdness, but it's kind of an interesting thing to try.

Screen oriented programs won't work because they don't see a tty.

2
  • tput cup 0 0 homes the cursor to the upper left of the terminal. tput il1 inserts an empty line. The sed command inserts those control sequences at the beginning, respectively, of the first line and each line of output redirected to the function. The exec command redirects all stdout to the function. The PROMPT_COMMAND is executed each time a Bash prompt is issued and causes the prompt to be displayed at the top of the terminal. Nov 11, 2010 at 12:00
  • Another approach might be to use Bash's DEBUG trap to issue the cursor movement sequences. Feb 16, 2011 at 17:47

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.