Netsight Blog

Cool stuff Netsight are up to in Zope and Plone

Avatar

Open remote files in your local emacs from a remote terminal

written by Matthew Sital-Singh, on Mar 25, 2008 11:54:00 AM.

Emacs 'tramp' (remote file loading) is great, but what if you are in an ssh session and want to open a file without having to work out the full remote path you're in and type it into your local emacs?

Here's my magical solution:

location="/`whoami`@`hostname`:`pwd`/$2"
ssh $1 emacsclient $location --no-wait

Put the above two lines into a script (called emacs-remote or something) and save it on the remote server you want to work on (make sure its in the PATH or your home dir or somewhere easy to reference). Also make sure your local copy of emacs is in server mode (type Meta-x server-start, or put (server-start) in your .emacs file and reload)

Then you can do the following:

  1. Load up ssh to a remote server (ssh username@host)
  2. Navigate to a directory
  3. Type "/emacs-remote localusername@localmachine filetoopen.txt"

Where localusername@localmachine are your login to the machine which is running the emacs you want to use

Et voila - the remote file should load up in your chosen copy of emacs!! This works best if you have SSH ControlMaster setup to re-use your ssh connections, otherwise you'll need to type your remote password again into emacs before it can load the file.

Leave a Reply