Mindless Blathering

Using Gnu Screen

To start a session in Screen for the first time open a terminal and type “screen”. You should now get the standard start up message simply press the space bar and it will take you to the next screen which is your basic shell prompt. Now you can start an application by simply typing the name of it as you would normally do in a terminal.

I’ll use Mutt my cli based email client for this example.

becker@crunchbang:-$ mutt

Now I have mutt running but my status bar at the bottom of the window which shows me all the windows I have open doesn’t reflect that. The problem is by default they all say (x$bash) where x is a number starting at 0. Now that’s not very helpful if I forget what window I opened something in so the easiest way to remedy this is to set a window title. To do that we use the key combination

C-a A. this means you press the Ctrl key at the same time as the “a” then you release both keys and press shift (to get capitals) & “a” again. This allows you to set the window title which in this case I’ll call Mutt although email would work as well.

Another command that you need to know to get the most out of Screen is

C-a c This is how we create new windows inside of Screen. You’ll remember from the previous example that the C-a means press Ctrl and “a” together then release and then press “c”

Now we have a few windows open obviously we need a way to move through them. The easiest way to do that is using the “Previous” & “Next” commands C-a p & C-a n respectively

Now the final tip for now. What do you do when your girlfriend wants to quickly check her email and you’ve got 3 or 4 different programs running inside your screen session? The easiest way to protect it from any unplanned interaction is to use the command C-a x. What this does is lock the screen session and require your user password before it can be accessed again making sure nothing changes whilst your away from the keyboard.

If you spend any time at the command line I’m sure you will see the value in learning and using the Screen program. It cleans up your desktop by getting rid of those multiple terminal windows you used to have open and putting them all into 1 window. Having everything controlled by keyboard shortcuts means you leave your hands on the keyboard instead of always moving away to grab the mouse making you more productive.

Edit: I made reference earlier in this post to the status line at the bottom of your Screen window. What I failed to mention is that Screen doesn’t have a status line by default but you can add one yourself. Now I must confess I didn’t write this myself and in pure code form I really have no idea what it all means but when it’s up and running it gives me my system load averages in the bottom left corner, the window titles of all open windows in the centre of the screen and the time and date in the bottom right corner. So as you can see it is actually very useful.

Here is the code:
hardstatus alwayslastline
hardstatus string ‘%{= kG}[ %{G}%l %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]‘

To use this code you simply add it too your .screenrc file. If you don’t already have one just create it then paste in the code and save it to your home directory.

Advertisement

Single Post Navigation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.