使用 emacs ranp 从 ssh 会话对远程文件进行原始编辑

发布于 2024-08-21 00:25:33 字数 633 浏览 9 评论 0原文

这可能是一个有点古怪的问题。我使用 Tramp 来编辑远程文件,但我也打开几个终端 ssh-ing 到该远程计算机以及其他工作(我在 emacs 中运行 ssh shell 时遇到问题)。

在终端工作期间,我经常想编辑一些文件,而我当前的过程是复制文件名,然后使用 emacs ranp 打开该文件(在搞乱了获取 trap 格式的文件路径之后)。对于快速编辑来说,这工作量太大,而且在路径处理部分很容易出错。

问题是:我可以在远程 ssh 会话中执行一些命令,该命令获取文件名,将其转换为流浪格式(这是简单的部分),然后运行本地命令(例如emacsclient blahblahblah)以便我可以在本地 emacs 中使用 trapp 编辑远程文件?

我不确定我说得是否足够清楚。我不想在远程计算机上运行 emacs(无论是在终端上还是通过 x 会话),但我确实想从远程提示符将文件发送到本地 emacs,如下所示:

user@remote-machien ~/ $ run_local_emacs somefile
# then the file "/ssh:user@remote-machine/:/home/user/somefile" shows up 
# in my local emacs

This is probably a somewhat out-of-wack question. I use tramp to edit remote files, but I also open several terminals ssh-ing to that remote machine as well for other works (I had problems running ssh shell inside emacs).

Often times during the terminal work I would like to edit some file, and my current procedure is to copy the file name, and then use emacs tramp to open that file (after messing all around with getting the file path in the tramp format). This is way too much work for a quick edit and quite error prone in the path handling part.

The question is: Can I execute some command in the remote ssh session that takes the filename, transform that to tramp format (that's the easy part), and run a local command (like emacsclient blahblahblah) so that I can edit the remote file using tramp in my local emacs?

I'm not sure if I'm clear enough. I don't want to run emacs on the remote machine (either on the terminal or through an x session), but I do want to send file to my local emacs from a remote prompt, like this:

user@remote-machien ~/ $ run_local_emacs somefile
# then the file "/ssh:user@remote-machine/:/home/user/somefile" shows up 
# in my local emacs

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

嘿看小鸭子会跑 2024-08-28 00:25:33

您可以将您的 emacs-server 设置为使用 tcp 连接(不仅仅是本地套接字),然后在远程端告诉 emacsclient 连接到该 tcp 连接:

在您的 .emacs 中

(setq server-use-tcp t)
(setq server-host "name_of_local_machine")
(server-start)

在远程端:

emacsclient -f ~/.emacs.d/server/server /`hostname`:/path/to/local/file

然后 对 emacsclient 的调用会在“本地”计算机上运行的 Emacs 中调出“远程”计算机本地的文件。显然,您可以将对 emacsclient 的调用包装在您想要的任何类型的脚本中,以使其更容易。

如果您的主目录在远程计算机上不可见,您将需要
自定义 server-auth-dir 变量,如下所示:

(setq server-auth-dir "/some/path/visible/on/both/machines")

有关更多文档,请参阅 Emacsclient 选项

You can set up your emacs-server to use a tcp connection (not just a local socket), and then on the remote side, tell emacsclient to connect to that tcp connection:

In your .emacs

(setq server-use-tcp t)
(setq server-host "name_of_local_machine")
(server-start)

And then on the remote side:

emacsclient -f ~/.emacs.d/server/server /`hostname`:/path/to/local/file

The above call to emacsclient brings up a file local to the "remote" machine in your Emacs running in the "local" machine. Obviously you can wrap the call to emacsclient in whatever kind of script you want to make it easier.

If your home directory is not visible on the remote machine, you will need
to customize the server-auth-dir variable like so:

(setq server-auth-dir "/some/path/visible/on/both/machines")

For more documentation, see Emacsclient options.

一瞬间的火花 2024-08-28 00:25:33

还有 http://www.emacswiki.org/emacs/AnsiTermHints#toc4

包含远程目录跟踪,让 Tramp 打开远程文件,就好像它是本地文件一样

Theres also http://www.emacswiki.org/emacs/AnsiTermHints#toc4

Incorporates remote directory tracking which lets tramp open remote files as if it was local

木格 2024-08-28 00:25:33

即使远程计算机上没有安装 emacsclient,您也可以使用 urxvt(一个优秀的终端仿真器)并编写一个 perl 扩展来执行此操作。

You can use urxvt (an excellent terminal emulator) and write a perl extension to do this even if emacsclient isn't installed on the remote machine.

梦中楼上月下 2024-08-28 00:25:33

也许您已经知道这一点,并且它对您来说效果不佳,但是当我需要做这类事情时,TRAMP 中的文件名完成已经足够有用了,我从未想到过寻找替代方案。

CxCf/ssh:remotehost:/TabTab

当您已设置 SSH 密钥或类似的无密码访问设置,但听起来您已经拥有了。

Maybe you already know about this and it doesn't work well for you, but when I've needed to do that sort of thing the filename completion in TRAMP has been helpful enough that I've never thought of looking for alternatives.

C-xC-f/ssh:remotehost:/TabTab

This works best when you've got SSH keys or similar passwordless access set up, but it sounds like you have that already.

韶华倾负 2024-08-28 00:25:33

我在这里所做的是从远程到本地的反向 ssh 连接并在本地运行 emacsclient:

me@remote-machine$ ssh -f me@local-machine emacsclient /ssh:remote-machine/$(realpath my-file-name)

What I am doing here is a reverse ssh connection from remote to local and running emacsclient locally:

me@remote-machine$ ssh -f me@local-machine emacsclient /ssh:remote-machine/$(realpath my-file-name)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文