Emacs shell命令与tramp模式等效

发布于 2024-10-05 16:48:52 字数 680 浏览 1 评论 0原文

在 emacs 中,我可以交互地执行类似的操作:

Mx eshell;

cd /sudo:privileged@myserver:
/path/to/mycommand

这很令人愉快,但我真的很希望能够在 elisp 代码中做这样的事情,作为自动化平凡任务的函数的一部分:

(shell-command "/sudo:privileged@myserver:/ path/to/mycommand")

这不太有效。显然 shell 命令试图找到路径 /sudo:privileged@myserver: 并且可以理解地抱怨。

是否有一种机制可以让我以编程方式在远程服务器上运行任意命令?我知道,在紧要关头,我可以求助于调用 `(shell-command "sshprivileged@myserver /path/to/mycommand")。不幸的是,由于我所处的网络怪癖,我在某种程度上依赖于流浪者多跳代理功能,因此从流浪者中执行此操作似乎更简单。

我查看了tramp.el以了解他们如何实现tramp-handle-shell-command拦截器,但看起来他们并没有考虑这种情况,或者也许我需要先欺骗它使用正确的缓冲区。我有什么选择?

(我使用的是 GNU Emacs,而不是 xemacs,以防万一)。

In emacs, I can do something like this interactively:

M-x eshell <return>

cd /sudo:privileged@myserver:
/path/to/mycommand

That's pleasant and everything, but I'd really like to be able to do something like this in elisp code, as part of a function to automate a mundane task:

(shell-command "/sudo:privileged@myserver:/path/to/mycommand")

This doesn't quite work. Apparently shell-command tries to find the path /sudo:privileged@myserver: and understandably complains.

Is there a mechanism by which I can run an arbitrary command on a remote server programmatically? I know that, in a pinch, I could resort to calling `(shell-command "ssh privileged@myserver /path/to/mycommand"). Unfortunately, due to network quirks where I'm in, I'm somewhat dependent on the tramp multihop proxy feature, so it would seem simpler to do this from tramp.

I've looked at tramp.el to see how they implement their tramp-handle-shell-command intercepter, but it doesn't look like they consider this kind of case, or maybe I need to trick it into using the right buffer first. What are my options?

(I'm using GNU Emacs, rather than xemacs, in case it matters).

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

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

发布评论

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

评论(1

謸气贵蔟 2024-10-12 16:48:52

如果您想在 eshell 中运行命令,请使用 eshell-command

Use eshell-command if you want to run your command in eshell.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文