如果使用 bash 以外的任何命令,我如何才能拥有 term.el (ansi-term) 跟踪目录
当使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其放入您的 .zshrc 中:
每次 pwd 更改时都会运行 chpwd() 函数。以 %d 结尾的行允许您跟踪当前目录——我在函数外重复它以确保它在 zsh 第一次初始化时运行。但 Emacs 要求我们首先告诉它当前用户是谁(以 %n 结尾的行)。
这实际上在 term.el 中进行了解释,如果您使用的是 Ubuntu,它应该位于 /usr/share/emacs//lisp 内。
希望这有帮助。
Put this in your .zshrc:
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.
对于这个问题有多种解决方案。我碰巧更喜欢我的实现,它将提示更改为包含当前路径,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: