I show the hard-disk free space in hardstatus screen. But also I want change the color of this value when it's less than a value to alert me.
I have done a script that it checks this and it returns a string if it's true or nothing if it's false.
But the problem is change the color in hardstatus screen. This is the line:

hardstatus alwayslastline "%?%27`%{+B r}%?Velocidad"

The hardstatus works but I won't show the output of script check (%27), only change the color. But %? needs a not empty string to do this. How can I do this?


Can't find a real solution for this, but there's a workaround if you can live with one extra space in your hardstatus line: make your script run in two modes, based on a command line argument.

  • In checking mode, echo only a space when you want the color changed (e.g. when the disk is full).
  • In normal mode, echo the free space or fill rate you want displayed.

Then you can do something like this in your .screenrc:

backtick 1 1 1 /tmp/script.sh check
backtick 2 1 1 /tmp/script.sh normal
hardstatus alwayslastline "%?%1`%{r}%: %?%2`"

The idea is to use the else (%:) clause to always output the same number of characters so the status line doesn't jump around, and use two invocations of the script (one to get the color optionally changed, one to print the actual value to display).

I tested this with this script, just to make sure it works:

#! /bin/bash
secs=$(date +%s)
if [ "${1:-check}" = "check" ] ; then
    if (( $secs % 2 == 0 )) ; then
        echo " "
    exit 0
echo $secs

With that, the hardstatus line gives the current time (in seconds since 01/01/1970, very practical...) in red for even seconds, or in normal color for odd seconds.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.