Ruby, etc

Learn all the things

He who enjoys doing and enjoys what he has done is happy. - Fortune Cookie

Getting Around With GNU Screen

In past few months, I worked on a project developed entirely on linux. Previously, I mostly did rails development on mac with textmate. I had a brief period of rails and perl where I did vim and screen…oh maybe 4 years ago. Anyways, so I didn’t forget much vim over the years, but I had forgotten how to use screen. I looked some documentation to refresh my memory and this post is mainly notes for me :)

Most commands start with CTRL-a I refer to each spawning of a new screen in the current session as a window.

Detach

One things i really like about screen is I can detach it on one computer… then log in somewhere else and reattach. Also handy when you are on a wifi card on the train and you get disconnected. (doh!)

1
ctrl-a d   to detach

then start with -r to reattach:

1
 screen -r

Create window

This creates a new terminal window

1
ctrl-a c

Name that window

Name your window, so its easier to keep organized

1
ctrl-a A (Yep, ctrl-a then SHIFT-a)

List the windows

See a list of your sessions and their number (this is why you name them) and you can use arrows to select)

1
ctrl-a "

Navigating Windows

You can flip through the windows in order or specify the number:

1
2
3
ctrl-a p   #previous window
ctrl-a n, ctrl-a [spacebar]  #next window
ctrl-a #   #the number you want to go to (starts at 0). 

multiple regions in one

1
2
3
4
5
ctrl-a S   #create a split, creates a new region
ctrl-a TAB #switch to next region
ctrl-a c   #create a terminal session in region 
ctrl-a X   #close the region
ctrl-a C   #clear, this is like typing clear at the prompt to clear the screen

Closing

To exit a window, simply type exit. To exit and kill all windows do

1
ctrl-a ctrl-\

Scrolling

Using terminal on mac or linux won’t capture the scroll back…. so you must do it through screen

1
ctrl-a [    #use the arrow key to navigate up 

Refresh

1
ctrl-a l  #refresh the current display

HELP!!

To see the two (!!) pages of screen commands type:

1
ctrl-a ?

Command mode

Do you like typing?

1
ctrl-a :   #to get to command mode, then you can type commands instead of the ctrl foo jibberish

Need the time?

1
ctrl-a t   #displays the current system time

Named Screen Sessions

Maybe you are working on two separate projects at once, give each one its own screen session

1
2
3
screen -S ProjectOne
screen -S ProjectTwo
screen -list

then later you can do

1
screen -r ProjectOne

to reattach it and continue

One thing you can do it make it easier is to add this to your .screenrc

1
hardstatus alwayslastline "%?%{yk}%-Lw%?%{wb}%n*%f %t%?(%u)%?%?%{yk}%+Lw%?"

It will show the names of the windows you have and highlight the current one. You can see the numbers too so you can do ctrl-a # quickly to jump around.

Anyways, hope this was useful to someone. Let me know any suggestions or anything I can do better!

Sources: * Unix Screen * Screen Man Page