Edit remote files with your local editor
npm install editr
|3||downloads in the last month|
|Version||0.1.3 last updated 2 years ago|
|Keywords||cli, remote, editor, rmate, tools|
EDIT Remote files
Edit remote files with TextMate (mate -w), Sublime Text 2 (subl -w), Chocolat (choc -w) and more!
Server: nodejs >= 0.8
Client: bash, cURL
On your home machine
# Install $ npm -g install editr # Run the daemon $ editr-server --editor "mate -w" --background
On the remote machine
# Connect with the forwarded port $ ssh remote.host.com -R 32123:localhost:32123 # Get the client script $ curl localhost:32123 > ./editr.sh; chmod u+x ./editr.sh # Test it out $ ./editr.sh testfile.txt # Your editor should open. Type something. Save and close your editor # Check out the edited file $ cat testfile.txt
There are two parts to editr: the server and the client. Both will work out of the box with the defaults if TextMate is installed. For other editors such as Sublime Text 2 and Chocolat, be sure to set the editor option on the server.
The server will pick an editor based on a hierarchy of variables (in order of precedence):
--editorcommand line argument
- hard coded
For security reasons, the server will listen on the local interface by default.
If you would like to listen on all interfaces, set the
--ip option or
EDITR_IP environment variable to
The port can be changed via the
--port argument or
EDITR_PORT environment variable.
Usage: editr-server [--editor 'EDITOR'] [--ip INTERFACE] [--port PORT] [-b] Options: -e, --editor Local editor to spawn (don't forget -w) [default: "mate -w"] --ip Interface to listen on [default: "127.0.0.1"] --port Port for server to listen on [default: 32123] -b, --background Run server as a daemon (background) [boolean] -h, --help Show this help message [boolean]
EDITR_HOST server hostname to connect to
EDITR_PORT server port to connect to
Usage: ./editr.sh [-H hostname] [-p port] [-f] file-path -H connect to host (default: localhost) -p port number to use for connection (default: 32123) -f open even if file is not writable -h display this usage information
You can edit your ssh config (~/.ssh/config) to setup remote forwarding to every host you connect to:
Host * RemoteForward 32123 localhost:32123 Host github.com ClearAllForwardings yes
Need to pass your custom port through
# Use the port argument sudo editr -p 42561 file.txt # Or pass your environment variables (EDITR_PORT) sudo -E editr file.txt
Infrequently Asked Questions
Ok smart ass, why HTTP then?
I'm lazy and didn't want to implement my own protocol, so I thought it would be easier. This way the client could just be cURL.
WTF is the extra "X" that gets appended to the response?
Setting bash variables strips trailing new lines. This makes sure they don't get stripped. Don't worry though, because the client script removes it before saving.
Then why the hell didn't you just have cURL save the file?
cURL doesn't save empty responses (even with a status of 200). So if you zero out a file with your editor, cURL won't save your change.
Couldn't you do it this way instead?
I've kinda tested this, so feel free to try it, but don't come crying to me if you wipe out your server configs. Also, I have no idea what will happen if you try to edit binary files. Open an issue if you want to bitch.