How can I have term.el (ansi-term) track directories if using anyhting other than bash

孤街浪徒 提交于 2019-11-30 21:00:18

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.

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:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!