绑定密钥可以在Zsh中的上下文中完成文件名 [英] bind key to complete filename wherever the context is in Zsh

查看:98
本文介绍了绑定密钥可以在Zsh中的上下文中完成文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我想知道是否有一个密钥序列可以在上下文中的任何地方完成文件名,例如^XC代表_correct_filename,或者如何配置zsh来完成该任务?

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?

推荐答案

您可以添加键绑定以执行所需的操作:

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* }

编辑:添加了$PREFIX

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

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

在每个步骤中按 Ctrl - x Tab 而不是 Tab .您可以选择其他适合您的按键组合.

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.

或者要使ImageMagick补全总是包含所有文件,请尝试编辑(首先进行备份)文件/usr/share/zsh/functions/Completion/Unix/_imagemagick(或类似文件),然后更改它以注释掉以_files开头的现有行并添加新的行显示:

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

这篇关于绑定密钥可以在Zsh中的上下文中完成文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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