Linux – Status line in linux shell

bashdisplaylinuxshellstatusbar

I use Windows and Putty in order to remotely connect (ssh) to some linux servers.
I have set my hardstatus in my .screenrc file so that I can monitor some useful information.
But this works only when I'm in Screen.

I would like to use the same thing outside Screen.
So, basically, I want to have a status bar (similar to Screen's status bar) when I'm on
my bash shell outside screen.

Is that even possible? How can I do it?
If not, is there any alternative?

PS: My goal is to show the current time and the deadline to renew my access to the server in a status bar.

Best Answer

Cool question. To my knowledge, this can't be done with Bash alone, as David Postill said. But as he suggested, you could (ab)use the prompt for this purpose. Here's an example using ANSI escape sequences to achieve the effect of a status bar :-)

PS1='\[\e[s\e[1;1H\e[41;1m\e[K\e[33;1m\][ *** \t *** ]\[\e[0m\e[u\]\w> '

This one just displays the current time on the 'status bar', while also displaying a regular prompt. A couple of notes:

  • \e[ introduces most of the special commands
  • \e[s saves the current cursor position
  • \e[1;1H positions the cursor at row 1, column 1
  • \e[...m change (fore- and background) colours
  • \e[K clears to end of line
  • \e[u restores the cursor position
  • \[ and \] delimit non-printable characters in the prompt; they let Bash compute the precise length of the prompt. You could in principle do without those, but then the prompt would not be updated correctly in a multi-line command (but do see the drawbacks below)

I'm not suggesting you take this solution seriously. It has serious drawbacks:

  1. it's hard to read and fragile
  2. the status bar is only updated when the prompt is updated; i.e., when control returns to the shell (as I read your question, a very big disadvantage)
  3. multi-line commands are not displayed properly (cursor restarts on first line)

But, still, I hope you enjoy! :)

Related Question