6

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.

1
  • 1
    bash does not have a status bar. You could display the info you want in the bash prompt ....
    – DavidPostill
    Nov 15, 2014 at 17:03

4 Answers 4

3

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! :)

1
  • Ok, and now for the serious answer ;-) (I discovered this seconds after I had poster my original answer. But I'm still keeping the old answer, just for fun.) I think you could use this: powerline.readthedocs.org/en/latest/usage/…. Disclaimer: I haven't tested it!
    – Edward
    Nov 17, 2014 at 8:27
1

I'm very surprised to find your question, because I developed pretty much exactly this over a week ago.

Check out Basta (Bash Status Line).

This is Bash code with few external dependencies (it requires stty, sleep and kill) which you can source in your .bashrc.

You get a scroll-protected, persistent status line at the bottom of the terminal, in which the time, host name and current directory are displayed.

If you look at the history, you can see I debugged this for a number of issues.

The clock is shown in inverse video, and updates spontaneously even if Bash is just sitting at a prompt, waiting for input.

This tiny project was motivated by having too cluttered a prompt for too many years. I wanted to have a $ prompt, but still see the current working directory and other things: and not in the window title, where my eyes rarely go.

I also use PuTTY and screen; it works inside screen and outside. I've tested with Termux, PuTTY and Gnome Terminal so far.

If you want to disable it while inside screen, you can probably make it conditional whether you source Basta or not based on the TERM variable, which contains something like screen-256color.

0

cyberninja216:

PS1='[\e[s\e[1;1H\e[41;1m\e[K\e[33;1m][ backtickhere curl ipinfo.io 2> /dev/null |grep -m 1 '"ip"'backtickhere][\e[0m\e[u]\w> '

notice the backticks to analyze a commands output. "use for live feed"

1
  • Can you elaborate on this a little more?
    – Toto
    May 14, 2018 at 18:34
0

Regarding drawback #3 on Edwards very nice answer, I could add:

One can arrange the extra brackets to let bash properly count the spaces and parse the multiline commands.

A simplified example would be:

PS1='\[\e[s\e[1;1H\e[K\]\[[ \u@\w ]\]\[\e[0m\e[u\]$ '

breaking it down to 3 parts

  1. \[\e[s\e[1;1H\e[K\] - the top line part (preamble is a good word?)
  2. \[[ \u@\w ]\] - the top line content
  3. \[\e[0m\e[u\]$ - the prompt part

Mind the extra instances of \[ and \] that tell bash which parts should be ignored in the 'counting' of characters for the cursor position.

You must log in to answer this question.

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