Setting the status line for the Screen program

0

In my recent article about the Screen program, I mention that one of the best things about the Screen program is that it gets out of the way and lets you just do your work. I’ve found that, on some hosts, there may be no on-screen indication that you’re in a Screen session. You may like that, but it can cause a bit of bother for users like me who prefer to see some on-screen indication that we’re in a Screen terminal session. On other hosts there is at least a minimal status line at the bottom of the terminal in the screen session.

My investigation

I decided to investigate. I did some research and discovered that the status line that I normally see on new Fedora installations is the default one configured in /etc/screenrc by Red Hat. Figure 1 shows the lines in screenrc that define the status line location and content. The comments are in the original screenrc file.

# hardstatus alwaysignore
# hardstatus alwayslastline "%Lw"

# Red Hat's normal status line
hardstatus string "[screen %n%?: %t%?] %h"

Figure 1: The default Red Hat configuration for the Screen status line.

The configuration in Figure 1 results in no status line. Can you determine why before proceeding?

The “problem” is the second line in Figure 1. It’s commented out so that the status line is not displayed. I think this is intentional as many Screen users prefer to have no status line, which results in more terminal display lines available for data. I changed those lines in the /etc/screenrc file to that in Figure 2. The Screen program must be restarted to activate changes to the configuration file.

# hardstatus alwaysignore
hardstatus alwayslastline "%Lw"

# Red Hat's normal status line
hardstatus string "[screen %n%?: %t%?] %h"

Figure 2: Remove the # symbol to uncomment the second line to enable the Screen status line.

The revised screenrc file produces the results with the status line in Figure 3. The default Red Hat status line is shown on the bottom of the Screen terminal session. It displays the Screen terminal session number, the user ID and hostname, and the present working directory (PWD). It’s displayed in reverse video to enhance its visibility.

Figure 3: The default Red Hat status line displays the Screen terminal number, the user ID and PWD. Click to enlarge.

My research also uncovered a more complex and colorful status line configuration. I added the lines in Figure 4 to the end of my /etc/screenrc. I left the other hardstatus lines in place so I could revert, but commented them out.

# Customize the hard status line by David Both
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'

Figure 4: This hardstatus string is used to create the interesting and colorful Screen status line.

The configuration in Figure 4 produces the status in Figure 5. This includes the hostname in green on the left, the Screen terminal number and username and hostname in the center, and the date and time on the right.

Figure 5: The hardstatus string in Figure 4 generates this Screen status line. Click to enlarge.

No, I didn’t create that long string of characters that defines the contents of the status line. I found it on the Internet. Information about creating the Screen status line and the character sequences for many types of data fields can be found in the Resources section.

Closing thoughts

Not everyone wants a status line in their Screen terminal sessions. I do and I also like to try different ones. I like the simplicity of the Red Hat default. I also like the colors in the alternate status configuration in Figure 5.

I haven’t yet tried to create my own status line configuration or even tried to modify the existing two. I plan to try that and I’ll let you know how that turns out.


Resources

Leave a Reply