Right aligning text in GNU Screen caption or hardstatusline
I have this in my .screenrc
caption always "%{= Kw} [%0c] %-Lw%{= KW}[%50>%n%f* %t]%{= Kw}%+Lw%=| %l | ${FULLHOST}"
It normally displays something like this:
[01:06] 0$ vim 1$ top 2-$ tail [3$* ~] | 0.26 0.54 0.36 | machine.domain.com
However, when I have lots of windows open, the data on the right is pushed off the edge and truncated:
[01:07] 0$ vim 1$ top 2$ tail 3$ ~ 4$ ~ 5$ ~ 6-$ ~ [7$* ~] | 0.21 0.46 0.34 | mac
How can I change the caption command so it will truncate the window list if neccessary, rather than pushing the right information off the edge? Bonus points if the active window is always displayed too.
Another solution, that I'm currently using. Instead of '%=' as in the original line, or '%-30=' in bender's (which aligns to the -30% (aka 70%) mark), I'm using '%-043=' (which aligns to the -43 character mark). But of course this has the same problem as bender's, where the amount I need to offset changes for each server. The solution is to edit the .screenrc per-server, with a command like this:
sed -i "s/043/0$(( 19 + $#FULLHOST ))/" ~/.screenrc
(The 19 is the number of characters used by the load display and spacing)
Since my .screenrc is generated by my shell's .rc file if it's not there, I can immediately run this command after doing so and end up with a correctly offset alignment for each server. Not elegant, but it works!
Remaining problems, that I don't really care about enough to solve:
- The window list (and anything to the left, including the time) gets pushed off the left now. I solved this by removing the clock.
- If the hostname of the machine changes, I need to regenerate the .screenrc, which involves deleting it and then starting a new shell.
I use:
caption always "%-Lw%{= Yk}%50>%n%f*%t%{-}%+Lw%<%-12= %?%F%?%{b}%c %m/%d%?"
This displays something like:
0*bender@armitage 1 bender@rikki 2 bender@gibson 15:11 05/30
This keeps the time and date on the status line and the active window in the list as the window list size grows. The magic bit you're missing is a defined width for the part that you want to keep on the right hand side. This is the "%-12=" width directive in my caption command.
Try something like:
caption always "%{= Kw} [%0c] %-Lw%{= KW}[%50>%n%f* %t]%{= Kw}%+Lw%-30=| %l | ${FULLHOST}"
You'll need to play with the width (%-30= above) to get your complete hostname to display.