It’s been quiet around the Zed editor project for a while, but over the past days I’ve put some time into it again. As it turns out, I ended using it less and less over time. The reason is simple: it was too much hassle to get started editing files. The procedure always consisted of cloning the Zed repository on the remote server where I wanted to edit files, cd ing into the right directory and then firing up a Python script to start the WebFS server. Then figuring out if the server want to edit files on is directly accessible from the Zed editor over HTTP or I have to open up some ports on a firewall. Bleh. Too much hassle.
Last week I figured out a way to improve this situation while reading a ZeroMQ book. Even though I did not end up using ZeroMQ (which is amazing by the way) to keep dependencies low, it did lead me onto the idea of a proxy solution. But before I get into the technical nitty gritty, let’s have a look at what the flow looks like now.
Back to instructions on how to use this.
As Google has now enabled publishing packaged apps in the Chrome Web Store, you can now install Zed from the Chrome Web Store. Right now you launch it from the New tab screen, but in future versions of Chrome (try Chrome Canary for a preview) these applications will have a proper application icon in the dock (on Mac).
After you’ve installed the application and launched it, a text entry box will appear asking for a URL. So, what URL should you enter in here? That brings us to the second part of the puzzle: the Zed client. On the machine where you want to edit files, cd into the directory to edit. Then, to download the Zed client, simply run the following command:
curl <a href="http://get.zedapp.org" target="_blank">http://get.zedapp.org</a> | sh
This will download a zed client binary for your platform (Linux, FreeBSD and Mac) into the current directory. A Windows binary is also available. Ideally, you run or copy this binary into a directory in your PATH, but you don’t have to.
Then, you run the client:
$ ./zed<br>Editing /somepath/to/somedir<br>In the Zed Chrome application copy and paste following URL to edit:<br><br><a href="http://server.zedapp.org:7337/fs/a7a437ba10f84dc08256ff20e771c9de" target="_blank">http://server.zedapp.org:7337/fs/a7a437ba10f84dc08256ff20e771c9de</a><br><br>Press Ctrl-c to quit.
And there it is: the URL we need to drop into the Zed project URL box. Copy and paste the URL into the input box and press Enter. If all went well, a Zed editor will now open exposing the files in the directory you ran the ./zed command from. Use Cmd-E/Ctrl-E or Alt-T to explore files, to open them, and edit them as you like. When you’re done, close the Zed editor and Ctrl-C in the console where the Zed client is running.
So, how does this work? Let’s start with some terminology:
- Zed app: the Chrome application
- Zed client: the program we just ran from the command line
- Zed server: a server program (same program we just ran, but with the — server flag) that proxies requests from the app to the client
The idea is that the Zed server is the stable part of this infrastructure. You can run your own, or you can use the default one I’m running on http://server.zedapp.org:7337 (as you can see in the URL the Zed client returned). The Zed server is the stable part of this infrastructure in the sense that it’s always running, and it’s directly accessible from the Internet (or at least: from wherever you run the Zed app and client).
Chrome app <-> Zed server <-> Zed client(s)
Clients can run anywhere and connect to a server, assigning themselves a GUID. Once the URL (containing both the Zed server and the client’s GUID) is entered into the app, the server will proxy any HTTP (WebFS) request received from the app to associated client, and proxy back the result as well. Therefore clients don’t need to run on public IPs nor do they need public ports open, as long as an outbound connection can be made to the Zed server it works.
To run a Zed server, you can use:
And the launch the client with a -u ws://ip:port flag to connect to your new Zed server instead of the default.
There’s also a local mode for editing local files more easily.
The Zed client/server program is written in Go. The reason to use Go are twofold:
- The Go compiler produces a statically linked binary without any dependencies making deployment easy (which is why it can be installed using the single curl | sh command I gave earlier).
- I wanted to use Go for something.
Currently this new system works and performs quite well. There may still be a bit of a memory/goroutine leak in the Zed server, which I have to look into. For the rest there’s still a lot of hacking and improving of the app, client and server to be done.