无论 Zsh 中的上下文如何,都将密钥绑定到完整的文件名

发布于 2024-08-29 13:54:07 字数 260 浏览 2 评论 0原文

有时我想要一个文件名,而不是 zsh 为我猜测的文件名。例如,我有一个 PNG 文件,没有正确的 .png 后缀,这使得 zsh 认为它不是图片,并且当我键入 Tab 时不会列出它display 的完整参数。

我想知道是否有一个关键序列可以在任何上下文中完成文件名,例如 ^XC 代表 _ Correct_filename,或者如何配置 zsh 来完成该操作?

Sometimes I want a filename instead of what zsh guesses for me. For example, I have a PNG file without a proper .png suffix, which makes zsh think it isn't a picture and won't list it when I type Tab to complete arguments of display.

I am wondering if there is a key sequence that completes for a filename wherever the context is, like ^XC for _correct_filename, or how to configure zsh to do the thing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

冷夜 2024-09-05 13:54:07

您可以添加键绑定来执行您想要的操作:

zle -C complete complete-word complete-files
bindkey '^X\t' complete
complete-files () { compadd - $PREFIX* }

编辑:添加$PREFIX

您可以将这些行添加到您的~/.zshrc文件中。

这使得当您在每个步骤中按 Ctrl-x Tab 而不是 Tab 时,补全会列出所有文件。您可以选择其他适合您的击键组合。

或者要使 ImageMagick 补全始终包含所有文件,请尝试编辑(首先备份)文件 /usr/share/zsh/functions/Completion/Unix/_imagemagick (或类似文件)并将其更改为注释删除以 _files 开头的现有行并添加所示的新行:

if (( $# )); then
  # _files "$@" -g "*.(#i)(${~formats//:/|})(-.)"
  _files "$@"
  return
fi

You can add a key binding to do what you want:

zle -C complete complete-word complete-files
bindkey '^X\t' complete
complete-files () { compadd - $PREFIX* }

Edit: Added $PREFIX

You can add those lines to your ~/.zshrc file.

That makes the completion list all files when you press Ctrl-x Tab at each step instead of Tab. You could choose another keystroke combination that suits you.

Or to make ImageMagick completions always include all files, try editing (make a backup first) the file /usr/share/zsh/functions/Completion/Unix/_imagemagick (or similar) and change this to comment out the existing line that begins with _files and add the new one shown:

if (( $# )); then
  # _files "$@" -g "*.(#i)(${~formats//:/|})(-.)"
  _files "$@"
  return
fi
天生の放荡 2024-09-05 13:54:07

丹尼斯的回答没有为我扩展波形符,所以当我尝试在 foo ~/ma 上调用它时,我会得到类似 complete-files: no matches find: ~/ma* 的内容。我确实在 zsh FAQ 中找到了一个替代方案,可以扩展它们:

zle -C complete-file complete-word _generic
zstyle ':completion:complete-file::::' completer _files
bindkey '^xF' complete-file

Dennis' answer didn't expand tilde for me, so I would get stuff like complete-files: no matches found: ~/ma* when I tried to invoke it on foo ~/ma. I did find an alternate in the zsh FAQ that will expand them, though:

zle -C complete-file complete-word _generic
zstyle ':completion:complete-file::::' completer _files
bindkey '^xF' complete-file
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文