SSH forwarding, GNU Screen, and emacs -nw

Apr 26, 2009 10:46

I live life in GNU screen for remote development, and much of that in emacs without a GUI, but I occasionally need to run some graphics Python or Lisp code from inside screen.

The problem is when I would forward X connections over ssh, and then login from another machine, I could no longer forward any X programs. I found the following lifesaving article for how to fix X forwarding while using a persistent screen session:

SSH-Agent Forwarding and GNU Screen

Follow those directions, and then to enable X forwarding in emacs running in screen, I use the following elisp function:

(defun fixssh ()
"Run fixssh script for use in GNU screen with X forwarding"
(interactive)
(save-excursion
(let ((buffer (find-file-noselect "~/bin/fixssh")))
(set-buffer buffer)
(setq buffer-read-only t)
(goto-char (point-min))
(while (re-search-forward
"\\([A-Z_][A-Z0-9_]*\\) *= *\"\\([^\"]*\\)\"" nil t)
(let ((key (match-string 1))
(val (match-string 2)))
(setenv key val)))
(kill-buffer buffer))))

Put that in your .emacs file and run it with "M-x fixssh" and your ssh X forwarding environment variables will be imported for use in emacs!

Special thanks to Sam Rowe for the original article.

emacs, ssh, programming, lisp, screen

Previous post Next post
Up