

如何让Tramp支持访问Termux
source link: https://www.lujun9972.win/blog/2018/09/30/%E5%A6%82%E4%BD%95%E8%AE%A9tramp%E6%94%AF%E6%8C%81%E8%AE%BF%E9%97%AEtermux/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

如何让Tramp支持访问Termux
Tramp ssh协议访问Termux
当使用Tramp通过ssh访问Termux上的文件时,你可能会发现出现下面这样的错误:
tramp-file-name-handler: Method ‘ssh’ should specify both encoding and decoding command or an scp program
这是因为Termux是一个prefixed Linux环境,它的目录结构是构建在 /data/data/com.termux/files/usr
下的.
若你在Termux上查看它的 PATH
环境变量会发现它的 PATH
环境变量并不是我们常见的 /bin:/usr/bin
这种位于根目录下的路径
echo $PATH
/sbin:/data/data/com.termux/files/usr/bin:/data/data/com.termux/files/usr/bin/applets
因此,当Tramp尝试在这些常见的 bin
目录中搜索Decode和Encode程序时就会找不到。
解决方法其实很简单,往 tramp-remote-path
变量中加入 tramp-own-remote-path
就行了.
(setq tramp-remote-path `(,@tramp-remote-path tramp-own-remote-path))
Tramp 根据 tramp-remote-path
中配置的路径来搜索远程主机上的程序,当它看到 tramp-own-remote-path
时会将其替换成远程主机上的 PATH
变量中定义的路径。
Tramp 与 org-babel 联用
即使经过上面的配置,当将Tramp与org-babel联用时,依然会有类似下面的错误出现:
tramp-file-name-handler: Couldn’t write region to ‘/ssh:phone#8022:/tmp/ob-input-87lP37’, decode using ‘base64 -d >%s’ failed
根据错误信息很容易知道这是因为Tramp尝试往Termux的 /tmp
目录中写内容导致的。
你可能会觉得这很好解决,只需要改一下 tramp-connection-properties
向Tramp指明 tmpdir
的路径就行了,像这样:
(add-to-list 'tramp-connection-properties (list (regexp-quote "/ssh:phone#8022:") "tmpdir" "/data/data/com.termux/files/usr/tmp"))
然而很可惜,你会发现这样是没用的。这其实是 org-babel
中的一个 BUG(可以参见这里的讨论)
你需要修改 org-babel-remote-temporary-directory
的值指向新的路径.
我们首先看一下 Termux 中定义的 tmpdir 是哪个路径
echo $TMPDIR
/data/data/com.termux/files/usr/tmp
然后将其设置为 org-babel-remote-temporary-directory
的值
(set-default 'org-babel-remote-temporary-directory "/data/data/com.termux/files/usr/tmp")
这里有一点需要注意,那就是由于ob-shell在执行时不是在当前buffer中执行的,因此你通过 file-variable 机制将其临时修改为其他值是不顶用的.
这也是这里使用 set-default
进行赋值的原因
Recommend
-
118
README.md Termux Dotfiles Installation Screenshot
-
72
Termux不仅是一个终端模拟器,还是一个完善的Linux终端环境(进一步说,一个完善且活跃的社区).也就是说,有了Termux,我们就可以做到不用root并且不用折腾就体验纯正的Linux. 在手机性能过剩的当下,配合Termux将我们的手机打造成一个...
-
916
README.md TBomb This is a SMS Bomber for Debian Based Linux And Termux.. This Script is Only For Educational Purposes or To Prank. Do not Use Th...
-
51
手机文件,比如照片和视频,如何下载到桌面电脑?...
-
38
手机文件,比如照片和视频,如何下载到桌面电脑? 普通用户可以使用手机线,将手机和电脑连起来。作为开发者,其实有更方便的方法,就是在手机架设一个 HTTP 服务,然后从桌面浏览器访问手机。 本文讲解如何使用
-
19
Emacs is amazing. It’s a very different sort of thing than a code text editor like Vim or an IDE like VSCode. It’s a different way of thinking of how to interact with a computer, where you build up techniques on top of simple tricks that let you...
-
11
tramp的一般用法 Table of Contents 1 使用tramp编辑远程文件 借助TRAMP,你可以像编辑本地文件一样来编辑远程文件. tramp的用法很简单,只要你在 C-x C-f 选择文件时使用一种特...
-
31
termux-api让你的Termux访问手机系统功能 Termux可以让你的手机变成一台Linux服务器,这很好玩。但是另一方面手机拥有某些特殊的能力是一般Linux服务器所不具备的,比如打电话、发短信、照相等。 Termux 默认可以调用的手机功能不多,只有...
-
7
tl;dr: Securely preside over your EC2 darlings with TRAMP mode.Cattle not petsThe majority of AWS EC2 I need to operate these days are members of Kubernetes clusters. For remote access to them I’m more com...
-
4
Emacs tramp Mon, Feb 9, 2009 • Tooling 很好用的东东,可以方便的打开需要root权限或...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK