Saturday, May 5, 2012

My GNU Screen Configuration

First an update on my latest setup. I switched to Arch Linux a while back and I'm rather happy with it so I'm not thinking of going back to Ubuntu at the moment despite the fact that I'm hearing it's in a good condition.

Second I've started using screen a lot more than before. Specifically, I began running my emacs session inside screen a while back, so that I can connect to my home computer from other places and attach to my screen session and use the running emacs instance. More recently, I've switched to using tmux instead of screen but for the sake of keeping history, I'm posting the code and configuration I used to use here. tmux will be the subject of another post.

This is the .screenrc I used:

escape ^Oo                                                                                                                                                                                     
vbell off                                                                                                                                                                                      
                                                                                                                                                                                               
# Scrollback buffer size in lines                                                                                                                                                              
defscrollback 5000                                                                                                                                                                             
                                                                                                                                                                                               
startup_message off                                                                                                                                                                            
                                                                                                                                                                                               
hardstatus alwayslastline                                                                                                                                                                      
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'                                                       
                                                                                                                                                                                               
# enable support for 256 colors                                                                                                                                                                
term screen-256color                                                                                                                                                                           
terminfo rxvt-unicode 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'                                                                                                                                   
                                                                                                                                                                                               
# fix for residual editor text. sometimes when you run an editor and                                                                                                                           
# close it, some of its text may stay visible. this fixes that                                                                                                                                 
# problem.                                                                                                                                                                                     
altscreen on                                                                                                                                                                                   
                                                                                                                                                                                               
screen -t  emacs       0        emacs -nw                                                                                                                                                      
screen -t  shell0
It changes the screen prefix to ^O so that it doesn't clash with the emacs shortcut. It turns off the visual bell, enlarges to scrollback buffer, turns off the welcome screen, adds a status line, enables 256 color support inside screen, enables alternate screen (so that residual text from some editors will not stay visible after closing them), and finally starts a shell and an emacs instance.

I also added this code to my .stumpwmrc so that I can switch to emacs in the usual way (by pressing C-t C-e):
(defcommand emacs-in-screen () ()                                                                                                                                                              
  "attempts to switch to an emacs instance run in a gnu screen window                                                                                                                          
called 'emacs', itself inside a urxvt instance."                                                                                                                                               
  (let ((ret                                                                                                                                                                                   
         (run-shell-command "screen -X select emacs > /dev/null ; echo $?" t)))                                                                                                                
    (if (eql (elt ret 0) #\0)                                                                                                                                                                  
        (run-or-raise "urxvt" '(:class "URxvt"))                                                                                                                                               
        (message "no screen session found."))))                                                                                                                                                
(define-key *root-map* (kbd "C-e") "emacs-in-screen")
For some reason this sometimes fails to switch to emacs properly, but it usually does!

And one last thing. The GNU Screen version shipped with Arch lacks vertical split support. This AUR package contains the patch for vertical splitting. Unfortunately, it lacks another patch that stops screen from complaining about long $TERM values, so I made a new AUR package that applies this other patch, too. I found that the process of creating Arch packages is surprisingly easy. In this case, I just downloaded the other package, updated its PKGFILE, and made the source tarball using makepkg --source.

No comments:

Post a Comment

Better Console Font (in Arch)

In order to use Terminus as my console (tty) font, I simply installed the package terminus-font with pacman (includes both console and X11 ...