如果使用 bash 以外的任何命令,我如何才能拥有 term.el (ansi-term) 跟踪目录

发布于 2024-09-14 23:25:40 字数 240 浏览 1 评论 0原文

当使用 eshell 或 ansi-term 和 bash emacs 时,emacs 会根据您所在的目录更改默认目录变量。

因此,如果我移动到 /home/user/code/project ,然后使用 ido-find -file 打开一个文件,它以 CWD 启动 ido。如果我使用 ksh (我的普通 shell)或 zsh (尝试进行测试),它不起作用。是否有设置或者仅在 bash 下支持?

谢谢

When using eshell or ansi-term and bash emacs changes the default-directory variable depending on what directory you are in.

So if I move to /home/user/code/project and then use ido-find-file to open a file it starts ido with the CWD. If I use ksh (my normal shell) or zsh (tried for testing) it doesnt work. Is there a setting or is this just supported under bash?

Thanks

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

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

发布评论

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

评论(2

够运 2024-09-21 23:25:40

将其放入您的 .zshrc 中:

chpwd() { print -P "\033AnSiTc %d" }

print -P "\033AnSiTu %n"
print -P "\033AnSiTc %d"

每次 pwd 更改时都会运行 chpwd() 函数。以 %d 结尾的行允许您跟踪当前目录——我在函数外重复它以确保它在 zsh 第一次初始化时运行。但 Emacs 要求我们首先告诉它当前用户是谁(以 %n 结尾的行)。

这实际上在 term.el 中进行了解释,如果您使用的是 Ubuntu,它应该位于 /usr/share/emacs//lisp 内。

希望这有帮助。

Put this in your .zshrc:

chpwd() { print -P "\033AnSiTc %d" }

print -P "\033AnSiTu %n"
print -P "\033AnSiTc %d"

The chpwd() function is run every time the pwd changes. The line ending in %d is the one that allows you to track the current directory--I repeat it outside the function to make sure it is run when zsh first initializes. But Emacs requires us to first tell it who the current user is (the line ending in %n).

This is actually explained in term.el, which should be inside /usr/share/emacs//lisp, if you're using Ubuntu.

Hope this helps.

骄兵必败 2024-09-21 23:25:40

对于这个问题有多种解决方案。我碰巧更喜欢我的实现,它将提示更改为包含当前路径,Emacs 可以识别并使用它来获得您想要的行为。此外,我的解决方案隐藏了包含路径的提示部分,因为我觉得它很难看。

我的解决方案可以在博客文章中找到: Emacs Tip #25 Shell Dirtrack By Prompt

但是,可以在 Emacs Wiki 或其他地方找到许多其他解决方案:

There are a number of solutions to this problem. I happen to prefer my implementation which changes the prompt to contain the current path, which Emacs recognizes and uses to get the behavior you want. Additionally, my solution hides the portion of the prompt which contains the path because I find it ugly.

My solution can be found in the blog post: Emacs Tip #25 Shell Dirtrack By Prompt.

However, there are a number of other solutions which can be found on the Emacs Wiki or other places:

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