GNU 'screen' backtick commands

GNU screen allows a way to define commands whose output can then be replayed into the status bar (see "GNU 'screen' Status Line(s)"). This is getting complex and obscure - and also much harder to look up on the Internet. So I hope this will help those of you who are trying to figure out what the hell a screen backtick command is and how it's used.

I wanted to get my battery percentage into the screen status bar. Backtick commands are probably more flexible than my implementation implies, but the easiest way to deal with them seems to be to write a shell script that outputs exactly what you want (as opposed to trying to implement shell code in your ~/.screenrc).

Here's a shell script to output just the battery percent:

#    I saved this as 'screen_backtick_battery'
# 2018-12-29: generate a number for a backtick command in screen, just
# the current battery percentage.
if [ -d /sys/class/power_supply/BAT?/ ]
    cat /sys/class/power_supply/BAT?/capacity

(This is bad code on so many levels: it won't work on a Mac, BAT? doesn't expand properly ... but it mostly works.) The script is in my ~/bin/ folder and thus on my PATH, so it can be called easily. It outputs a single number between 0 and 100 that's the current battery percentage. Now we add a couple lines to the screen config file:

# backtick id lifespan autorefresh cmd args...
backtick 1 30 30 screen_backtick_battery
hardstatus alwayslastline "%{= bY}%1`%:%%"

Honestly, I don't fully understand this myself. %{= bY} is just an embellishment as explained in the previous screen entry, a blue background and yellow foreground. And %% prints a single percent sign. So it appears that what we need to get the output of the backtick command number 1 is %1`%: (don't miss the trailing colon). This is NOT well explained in the man page, thus my uncertainty. The "30 30" is the "lifespan" and "autorefresh" times in seconds.

As for the backtick id lifespan autorefresh cmd - that part is ... somewhat explained in the man page, so that source is probably better than me trying to muddle through an explanation.