4

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
  • Take a look at this repo: github.com/swirepe/alwaysontop – Scot Sep 9 '18 at 1:53
  • Possible duplicate of Make window always on top? – phuclv Sep 9 '18 at 1:59
  • @l0b0 I've already retracted the vote half a minute before your comment – phuclv Sep 9 '18 at 2:02
  • 1
    How do you expect multiple commands to work? Should the command + output be printed above/below the previous command, or should it overwrite the last command and output? – l0b0 Sep 9 '18 at 2:02
  • How about setting the window title to the last command, and leave the terminal output as-is? – Xen2050 Sep 9 '18 at 4:34
0

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.

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.