Instead of special-casing HOSTNAME, I would prefer a more general solution. If I needed to be able to read and set HOSTNAME to something else inside a screenrc such that it applied to new windows, it's not very straightforward to me.
I can get 80% of the way there by something like
eval "readreg h /etc/hostname" "register g ':setenv HOSTNAME '" "register i '\r'" "paste ghi j" command "process j"
but this is ugly and wastes a few registers, and requires knowing 6 different commands. I couldn't find a nice way to just put a register into an environment variable.
Env to register is easy:
register s $SHELL
It would be nice to have the reverse, maybe add a -r (for register) flag to setenv, giving this solution:
readreg h /etc/hostname
setenv -r HOSTNAME h