5

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
Handsome Nerd
  • 4,682
  • 17
  • 55
  • 80
  • Take a look at this repo: https://github.com/swirepe/alwaysontop – Scot Sep 09 '18 at 01:53
  • Possible duplicate of [Make window always on top?](https://superuser.com/questions/28907/make-window-always-on-top) – phuclv Sep 09 '18 at 01:59
  • 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 09 '18 at 02:02
  • How about setting the window title to the last command, and leave the terminal output as-is? – Xen2050 Sep 09 '18 at 04:34
  • @phuclv OMG, it's unrelated to that question. I edit the title. and see the first comment that caught the question correctly. – Handsome Nerd Sep 09 '18 at 08:32
  • @l0b0 It's fine in any way. I rarely if ever, type multiple line commands. – Handsome Nerd Sep 09 '18 at 08:34
  • @PHPst I wasn't even talking about multi-line commands, but more than one command in the same terminal window. – l0b0 Sep 09 '18 at 08:45
  • @l0b0 only command prompt on the first line. all other out are without change. as is shown in the example. – Handsome Nerd Sep 09 '18 at 09:51
  • Close voters: Please note the reason this is closed is due to the OP's request *How can I achieve this using any available tools on any platform?* That's simply too broad. – I say Reinstate Monica Sep 09 '18 at 16:22
  • On windows 10 you can try with `prompt $E[0;0H$E[K$p$g` – MC ND Sep 12 '18 at 14:56
  • @MCND Could you please explain? – Handsome Nerd Sep 15 '18 at 08:10
  • @PHPst, it just changes the prompt to include the escape sequence to move the cursor to first line first column and clean the line. Not very useful as new commands will overwrite the output of the previous commands (hence the comment not an answer), but visually similar to the request. – MC ND Sep 15 '18 at 08:32

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.

Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
  • You could also use something like Tmuxinator to automate this setup, so you don't have to manually set it up everytime. – Lasse Meyer Jul 08 '20 at 10:48
0

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
  • 131
  • 5