Mike (drunkpotato) wrote,
Mike
drunkpotato

SSH forwarding, GNU Screen, and emacs -nw

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.
Tags: emacs, lisp, programming, screen, ssh
Subscribe

  • Swine flu

    We are no longer allowed to call Swine Flu Swine Flu. We must now call Swine Flu by its flu ID #, and not Swine Flu. So don't call Swine Flu…

  • Kudos

    I wanted to balance my ranting with a shout out to two of my current favorite brands: 1) JanSport: Nothing but love for you Why? They take their…

  • Lawyer up?

    Note: I am not a lawyer and do not know how effective or legal this is, but if for some reason it becomes important I want a record of this.…

  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments