GNU Screen: run arbitrary command in the status bar

gnu-screen

Is it possible to get GNU Screen to display the output of an arbitrary command, e.g. who | wc -l, in the status bar, refreshing it, say, every minute?

Best Answer

Yes you can using the backtick feature. Backtick

You put a line in your screenrc file:

backtick 1 0 5 /bin/date

If I understand correctly, it means backtick id 1, which runs command /bin/date, produces output valid for 0 seconds and the caption/hardstatus should be updated every 5 seconds.

Now, you can use the string %1` inside your hardstatus for substitution, eg

hardstatus alwayslastline "date output: %1`"

In your case, I think you'll have to write a script. For example, $HOME/my_script.sh:

#!/bin/bash
who | wc -l

In your ~/.screenrc:

backtick 1 0 60 $HOME/my_script.sh
hardstatus alwayslastline "who|wc -l output: %1`"

Obviously you won't want exactly that, but just add %1` to whatever else you have. Note that your script output can't include string escapes for screen to expand, e.g. if your script is echo "%{bg}blue on green%{dd}" it won't be coloured, you'll just see ${bg} and ${dd} in your status line.

Related Question