Emacs terminal 远程编辑文件方案

刚才在本地试了下,一台笔记本(mac)当作本机,一台台式机(pc)当作服务器,从 mac SSH 到 pc 之后,pc 也可以直接 SSH 到 mac。于是在 pc 中加入这样一条命令:

ec () { ssh mac "emacsclient --no-wait /ssh:pc:$(readlink -f $1)"; }

然后就可以用 ec ~/.bashrc 用 mac 上的 Emacs 打开 pc 上的 ~/.bashrc 了。


一个完整的工作流:

打开 Emacs,开启 Server (M-x server-start),打开终端 (M-x term)

~$ ssh pc
Welcome to Ubuntu 17.04 (GNU/Linux 4.10.0-22-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

 * Ubuntu 12.04 LTS ('precise') end-of-life was April 28, 2017
   ongoing security updates for 12.04 are available with Ubuntu Advantage
   - https://ubu.one/U1204esm
 * Aaron Honeycutt from the Kubuntu Council on art and design in Kubuntu
   - https://ubu.one/kubuart
 * The Ubuntu Desktop team wants your feedback on the move to Gnome
   - https://ubu.one/2GNome

4 packages can be updated.
0 updates are security updates.

Last login: Tue Jun 13 13:01:21 2017 from 192.168.0.101
xcy@pc:~$ ssh mac 'uname -a'
Darwin Chunyangs-MacBook-Air.local 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64
xcy@pc:~$ ec () { ssh mac "emacsclient --no-wait /ssh:pc:$(readlink -f $1)"; }
xcy@pc:~$ ec .bashrc 
xcy@pc:~$

Emacs 就会自动打开 /ssh:pc:.bashrc 了。

6 个赞