3

It is common to cram useful information in the Unix shell prompt, but I have too many things I want to keep an eye on to fit it all in one prompt: current Gnu screen window, current directory, current time, hostname, current git branch, phase of the moon, you-name-it.

It would be saner to have a fixed status region at the bottom (or top) of the terminal to show all this information, and leave the prompt alone. (I wrote "fixed status region" rather than "fixed status line" because I don't want to limit myself to one line.)

(This region, of course, would not be affected by normal interactive output.)

Is there a standard Unix to implement such a fixed status region, and would allow me to update it through the precmd function?

1

4 Answers 4

2

You could split your screen horizontally in screen, set one area the size you want for your status region, and run some watch -t cat ~/.status in it and then fill the content of that ~/.status in your precmd().

1

If your terminal supports terminal addressing, save cursor and restore cursor, this might work:

PS1="$(tput sc;tput cup 0 0;tput rev;tput el)\u@\h \W$( tput rc;tput sgr0)\$ "

But beware that the command can be difficult to edit as the shell gets confused about where it is in the input buffer.

In bash, you can tell it to ignore the cursor control sequences using backslash-square brackets:

PS1="\[$(tput sc;tput cup 0 0;tput rev;tput el)\]\u@\h \W\[$( tput rc;tput sgr0)\]\$ "

If this doesn't work, try sending the output direct to the terminal:

TOSL=$(tput sc;tput cup 0 0;tput rev;tput el)
FROMSL=$(tput sgr0; tput rc)
PS1='$(echo -n "$TOSL $LOGNAME@$HOSTNAME ${PWD/#$HOME/~}$FROMSL">/dev/tty)\$ '
1
  • The use of \[...\] here is not quite right to avoid confusing the prompt. Brackets are needed not just for non-printing escape sequences, but for anything which doesn't print on the line where the user input will be entered. This means the entire status line portion of PS1 should be inside the brackets, with only the "\$ " outside.
    – djpohly
    Jan 9 at 19:54
1

This year [2023], ten years after your question, I got bored one day and wrote a little thing called "Basta" (Bash Status line).

https://www.kylheku.com/cgit/basta/about/

It's small script you source from your ~/.bashrc file which gives you a protected status line at the bottom of the screen, showing the date, time, host and working directory (abbreviated to fit, if necessary).

The time updates while Bash is waiting for input!

9
  • Source links seem to be dead, unfortunately Mar 24 at 22:29
  • @InterLinked You probably ran into my over-aggressive ban filter.
    – Kaz
    Mar 25 at 2:37
  • @InterLinked Someone accessing the Bata repo, leaving a httpd log like this got banned for 1 day: 207.241.*.* - - [24/Mar/2024:15:26:46 -0700] "GET /cgit/basta/ HTTP/1.1" 200 10585 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/605.1.15". The reason is probably my rule against too many browsers in the agent string. We have Mozilla, Gecko, Chrome, Safari, sheesh ... that looks spammy, like not a human being with a normal browser. You can have two, that's it: your actual software and one popular one it's compatible with.
    – Kaz
    Mar 25 at 2:42
  • That isn't my user agent, but from the moment I first when to the link, it hasn't been working, apart from the "about" page Mar 25 at 12:15
  • Another agent string got banned about 40 minutes ago accessing the Basta repo: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36, IPv4 address 172.58.*.*. That was the only access today, Pacific time. Yesterday, since my previous comment, someone reporting as Mozilla/5.0 (X11; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0 visted the /about page without being banned, but didn't access the code.
    – Kaz
    Mar 25 at 18:11
0

AT&T Unix had sysline command, which provided a status line for terminals that don't have it in hardware. Maybe there is a GNU equivalent by now...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .