6

I need to keep the command line on the top of the screen and see the output of any command below it. How can I achieve this using any available tools on any platform?

Currently, on the all terminal emulators I have worked with if you run ls foo -l the result will be:

$ ls foo -l
hi.txt
bye.txt
$ command prompt is here

In like to see this:

$ command prompt is here
$ ls foo -l
hi.txt
bye.txt
Real Dreams
  • 5,408

2 Answers2

2

Linux, Bash.

Bash uses stderr (file descriptor 2) to print its command prompt and command line. Use tmux to display two shells one above the other (or just place two GUI windows, terminal emulators one above the other). In the lower one invoke tty. Don't use the lower shell directly from now on. In the upper one redirect file descriptor 1 to the tty of the lower one (e.g. exec 1>/dev/pts/2).

Ctrl+L clears the upper, clear clears the lower. Each portion is multi-line. Thanks to tmux's features you can resize them (i.e. move the border up and down).

Use this to make commands appear also in the lower portion of the display:

trap 'printf "%s\n" "-----$ $BASH_COMMAND"' DEBUG

I tested the solution and at some point my terminal window looked like this:

kamil@foo:~$ ls -l /proc/$$/fd
kamil@foo:~$ uname -r
kamil@foo:~$ cat /etc/issue
kamil@foo:~$ █

──────────────────────────────────────────────────────────────────────
-----$ ls --color=auto -l /proc/$$/fd
total 0
lrwx------ 1 kamil kamil 64 Sep  9 20:42 0 -> /dev/pts/3
l-wx------ 1 kamil kamil 64 Sep  9 20:42 1 -> /dev/pts/2
lrwx------ 1 kamil kamil 64 Sep  9 20:42 2 -> /dev/pts/3
lrwx------ 1 kamil kamil 64 Sep  9 21:13 255 -> /dev/pts/3
-----$ uname -r
4.15.0-33-generic
-----$ cat /etc/issue
Ubuntu 18.04.1 LTS \n \l

(Note: --color=auto appeared because my ls is an alias).

Expect interactive tools (like text editors) to misbehave, so it's better to revert the change while calling them. Example:

1>&2 nano

Some shells (e.g. zsh) use a separate file descriptor 10 for command line. This allows you to redirect stderr to the lower (or yet another, 3rd) tty, keeping the command line in the upper one.

1

Like the OP I've been seeking a way to keep the prompt on the top, and @kamil-maciorowski's answer was an eye-opener for me. After playing around some, here is the sequence of commands I landed on, and I believe it achieves what the OP wants.

tmux
tmux split-window -v
tmux selectp -t 1
tty > /tmp/bottom_tty
tmux selectp -t 0
tmux resize-pane -U 50
exec 1>`cat /tmp/bottom_tty`
  1. Invoke tmux
  2. Split the terminal into two panes stacked vertically
  3. Set the focus on the bottom pane
  4. Store the terminal path for the bottom pane in a temporary file
  5. Set the focus on the top pane
  6. Resize the top pane to just one line (by resizing it upwards an excessive amount)
  7. Redirect output of top pane to the bottom pane
Kirkman14
  • 141