Zsh 书签目录具有制表符补全功能?
我想要的:
cd c/ra
完成到 ~/code/rails-app
和 cd c/
显示~/code
中的目录列表
我当前拥有的:
c ra
如果我有一个目录~/code/rails-app
和 c
显示 ~/code
中的目录列表
通过将其放在我的 中>.zshrc
:
c() { cd ~/code/$1; }
_c() { _files -W ~/code -/; }
compdef _c c
这个工具看起来很有前途:https://github.com/flavio/jump 但我想要更轻量的东西。
What I want:
cd c/ra<tab>
completes to ~/code/rails-app
and cd c/<tab>
shows a list of dirs within ~/code
What I currently have:
c ra<tab>
completes to c rails-app
if I have a directory ~/code/rails-app
and c <tab>
shows a list of dirs within ~/code
By having this in my .zshrc
:
c() { cd ~/code/$1; }
_c() { _files -W ~/code -/; }
compdef _c c
This tool looks promising: https://github.com/flavio/jump but I'd like something more lightweight.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所描述的那样,至少对于目录来说,制表符补全应该可以通过 zsh 完成,而无需编写 zsh 函数。
例如,此链接指出输入
/u/l/b
,然后在提示符下 tab 扩展为/usr/local/bin
。这对我有用 - 如果我创建一个目录
~/code/rails-app
这样:那么:
我无法指出这是哪个
zsh
选项 - 我使用经过大量修改的~/.zshrc
和一些oh -my-zsh
。这可能是zsh
提供的功能,无需启用;如果没有,请在第一个链接或oh-my-zsh
中的某个位置或什至 中查看详细信息某些版本的 ZSH 手册 应该会有所帮助。 (不过,至少可以说,我发现该手册有点……令人不知所措)。我不认为您需要编写一个函数来实现此行为 -
zsh
绝对能够做到这一点。Tab completion such as you've described, at least for directories, should be doable by
zsh
without the need to write azsh
function.This link, for example, notes that typing
/u/l/b
then tab expands to/usr/local/bin
on the prompt.This works for me - if I make a directory
~/code/rails-app
such:then:
I can't point out which
zsh
option this is - I'm using a fairly heavily modified~/.zshrc
and bits ofoh-my-zsh
. This might be functionality given byzsh
without needing to be enabled; if not, details in either the first link or somewhere inoh-my-zsh
or even some version of the ZSH manual should help. (I find the manual a little ... overwhelming, to say the least, though).I don't believe that you need to write a function to achieve this behaviour -
zsh
is definitely able to do it.