eldelto
Created:

Emacs' TRAMP is Awesome

A couple of weeks ago I tried switching my whole development setup from Visual Studio Code over to NeoVIM as two collegues where quite persuasive and I've already been using VIM keybindings in VS Code for a couple of years.

It worked out quite well but I still kept using Emacs for its amazing Org-Mode plugin (which also is the backbone of this blog you're reading) which convinced me to switch all my development over to Emacs in the end.

This little maneuver is gonna cost us 51 years meme

But Org-Mode is not the only great thing about Emacs. Recently I've grown quite fond of TRAMP while configuring my home server and it really made me question what efficient UIs actually look like.

What is it?

TRAMP (Transparent Remote Access, Multiple Protocols) is Emacs' built-in functionality to access remote hosts (mainly via SSH) in a transparent way. This means, when you connect to a remote host, most actions within Emacs will just work™, even across network boundaries.

That's pretty rad because it allows us to use Dired or Eshell (and others) exactly as we would on our local machine. If we, for example, copy a remote file via Eshell to local path, TRAMP ensures that the file is downloaded from the remote host, without us needing to do anything special.

This enables us to edit multiple files on multiple hosts without having to fiddle around with maintaining multiple tabs with open SSH connections in our terminal emulator or using tmux for maintaining multiple active sessions.

But enough of all the hollow promises, let's take a look at some examples.

A Quick Introduction

The easiest way to get started with TRAMP is by opening a Dired buffer on a remote host. Let's assume 192.168.77.24 is the IP of our server we want to administer, then we can connect to it by launching Dired (C-x d or M-x dired) and entering /ssh:eldelto@192.168.77.24:.

As soon as we enter the last :, Emacs will prompt us for the password of the user eldelto. After entering it, we can either keep typing to point Dired to another directory or hit return, which lands us in the home directory:

Dired via TRAMP

At this point it is no different than a local Dired session except that every action traverses the network in the background, pretty amazing if you ask me. Even more so because copying files from and to the remote host works as we would expect.

Let's say we now want to fire up a shell on the remote host to check our systemd timers. With our Dired buffer still open, all we need to do is type in M-x eshell to launch a new Eshell session as usual and voilà - it will automatically be opened in the current directory on the remote host:

Remote Eshell session

The last imaginary thing on our to-do list is to edit our hosts file at /etc/hosts. If we simply try opening it via C-x C-f or M-x find-file we will fail miserably as the file will be opened in read-only mode as it requires root privileges to edit.

But of course TRAMP got us covered - if we append |sudo:: to our host address we will be prompted for our password again and be elevated to the root user. The full file path now becomes /ssh:eldelto@192.168.77.32|sudo::/etc/hosts and we're in.

If we were now to launch another Eshell from our open hosts file buffer, it would of course also run under the root user - rad!

A real breath of fresh air when you have to wrestle your home (or work) server into submission.

UIs For a More Civilised Age

I've always been a pretty die-hard fan of the terminal and command-line-interface (CLI) tools (and I still think it is pretty hard to match their composability) but setting up my home server with Emacs' TRAMP just blew every previous workflow I had out of the water.

Maybe there are still UI paradigms left to explore, that straddle the line between being as composable as CLI tools but not being hamstrung by pretending to be a teletype of yore.

Emacs is definitely a good step in that direction by being able to tap into a plethora of Lisp functions that can be sequentially applied to achieve similar results as stringing CLI commands together with Unix pipes. Here it even bears some resemblance to the Canon Cat as described by Jef Raskin in his book The Humane Interface.

But enough of me rambling about obscure user-interface concepts - give Emacs's TRAMP functionality a try, it seriously rocks!