Zsh 书签目录具有制表符补全功能?

发布于 2025-01-06 10:16:13 字数 585 浏览 4 评论 0原文

我想要的:

cd c/ra 完成到 ~/code/rails-appcd c/ 显示~/code 中的目录列表


我当前拥有的:

c ra 如果我有一个目录~/code/rails-appc 显示 ~/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 技术交流群。

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

发布评论

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

评论(1

淡笑忘祈一世凡恋 2025-01-13 10:16:13

正如您所描述的那样,至少对于目录来说,制表符补全应该可以通过 zsh 完成,而无需编写 zsh 函数。

例如,此链接指出输入 /u/l/b,然后在提示符下 tab 扩展为 /usr/local/bin

这对我有用 - 如果我创建一个目录 ~/code/rails-app 这样:

zsh% ls ~/code
another-app       another-dir rails-app
zsh% ls ~/code/rails-app
one two

那么:

zsh% cd c/ra<TAB> # this expands to 'cd code/rails-app'
zsh% cd c/<TAB><TAB> # Double tab, one to expand "c" to "code", 
zsh% #               # second gives me the zsh-completion menu

我无法指出这是哪个 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 a zsh 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:

zsh% ls ~/code
another-app       another-dir rails-app
zsh% ls ~/code/rails-app
one two

then:

zsh% cd c/ra<TAB> # this expands to 'cd code/rails-app'
zsh% cd c/<TAB><TAB> # Double tab, one to expand "c" to "code", 
zsh% #               # second gives me the zsh-completion menu

I can't point out which zsh option this is - I'm using a fairly heavily modified ~/.zshrc and bits of oh-my-zsh. This might be functionality given by zsh without needing to be enabled; if not, details in either the first link or somewhere in oh-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.

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