如何让ZSH在“终端"框架中显示当前目录? [英] How do I get ZSH to display the current directory in the Terminal frame?

查看:1356
本文介绍了如何让ZSH在“终端"框架中显示当前目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在逐渐从Bash切换到ZSH,并尝试通过复制功能来学习.似乎找不到这个.

I'm gradually switching from Bash to ZSH, and trying to learn by replicating features. Can't seem to find this one though.

我应该放什么,我应该放哪里?这有可能吗?谢谢.

What should I put, and where should I put it? Is this even possible? Thanks.

推荐答案

尝试一下:

settitle() { printf "\e]0;$@\a" }
dir_in_title() { settitle $PWD }
chpwd_functions=(dir_in_title)

现在,您的cd命令将运行dir_in_title函数,该函数将打印一个转义序列,要求Terminal.app更新标题. (奇怪的是,至少使用在urxvt中也适用的转义序列.这些序列必须比我预期的更加标准化.)

Now, your cd commands will run the dir_in_title function, which will print an escape sequence that asks Terminal.app to update the title. (Oddly enough, using an escape sequence that also works in urxvt, at least. These must be more standardized than I expected.)

如果您喜欢这种效果,则需要在~/.zshrc中添加这些行,以使其在将来的终端上正常工作.

If you like the effect, you'll need to add these lines to your ~/.zshrc for it to work on future terminals.

我抓取了正确的转义序列来自我对类似但不同的问题的回答. Chris Page就该问题给出了自己的答案,其中包含与OS X 10.7完全不同的详细信息.升级时,您可能会想使用他的机制.

I grabbed the correct escape sequence from Chris Page on superuser and the style of functions from my answer to similar but different question. Chris Page gave his own answer on that question with details on OS X 10.7 that are drastically different. When you upgrade you'll probably want to use his mechanism instead.

这篇关于如何让ZSH在“终端"框架中显示当前目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆