Autocomplete 如何使zsh自动完成到compdef_文件的故障切换

Autocomplete 如何使zsh自动完成到compdef_文件的故障切换,autocomplete,zsh,zsh-completion,Autocomplete,Zsh,Zsh Completion,我需要使用以下方法获取ssh密钥的指纹: $ ssh-keygen -lf ~/.ssh/id_rsa_user.pub 键入:ssh-keygen-lf~/.ssTAB后,它没有给出任何选项 我必须做: $ compdef _files ssh-keygen 在此之后,我可以使用文件路径自动完成,但命令autocomplete停止工作,因此如果我键入ssh-keygen-Tab,我将看不到任何其他输出: $ ssh-keygen - -- option -- -B -- show th

我需要使用以下方法获取ssh密钥的指纹:

$ ssh-keygen -lf ~/.ssh/id_rsa_user.pub
键入:
ssh-keygen-lf~/.ss
TAB后,它没有给出任何选项

我必须做:

$ compdef _files ssh-keygen
在此之后,我可以使用文件路径自动完成,但命令autocomplete停止工作,因此如果我键入
ssh-keygen-
Tab,我将看不到任何其他输出:

$ ssh-keygen -
 -- option --
-B  -- show the bubblebabble digest of key
-C  -- provide new comment
-D  -- download key stored in smartcard reader
-N  -- provide new passphrase
-P  -- provide old passphrase
-U  -- upload key to smartcard reader
-b  -- specify number of bits in key
-c  -- change comment in private and public key files
-e  -- export key to SECSH file format
-f  -- key file
-i  -- import key to OpenSSH format
-l  -- show fingerprint of key file
-p  -- change passphrase of private key file
-q  -- silence ssh-keygen
-t  -- specify the type of the key to create
-y  -- get public key from private key
因此,我想知道是否有一种方法可以同时启用这两个选项,以便我可以执行以下操作:

$ ssh-keygen -lf ~/.ssh/id_rsa_user.pub
ssh-keyg
选项卡,该选项卡将提供:

$ ssh-keygen
那我就可以了

$ssh-keygen-
选项卡

这将打印选项菜单,并可执行以下操作:

$ssh keygen-lf~/.ss
选项卡

并且有一个可行的选项列表,所以在最后我会得到如下结果:

$ ssh-keygen -lf ~/.ssh/id_rsa_user.pub
现在,我只需在我的
~/.zshrc
中添加以下内容:

compdef _files ssh-keygen
compdef _files adb
compdef _files mysql
...
但是我必须这样做,因为avery命令我想使用_filescompletion,因此我想知道是否有一种方法可以始终使用
\u files
或故障切换到它

有什么想法吗


在按Ctrl+d显示文件选项的情况下,是否可以使其行为类似于
csh

更新:

我注意到,如果最后一个参数是
-f
,则自动完成会起作用:

ssh-keygen-l-f~/.ssh
TAB


但是对于自定义脚本、命令和什么功能,widget alias可以帮助强制完成
\u文件。

解决方案是更新到
zsh
,我就是这样做的:

# check the zsh info
brew info zsh

# install zsh
brew install zsh

# add shell path
sudo vim /etc/shells

# add the following line into the very end of the file(/etc/shells)
/usr/local/bin/zsh

# change default shell
chsh -s /usr/local/bin/zsh
我在完成
git流时遇到问题
,这通过使用
重新安装而得到修复,无需完成

$ brew install git --without-completions

“在按下Ctrl+d显示文件选项的情况下,是否可能使其行为类似于csh?”-我认为您可以使用“我知道这不一定对您有帮助”中给出的示例来实现这一点,但您使用ssh keygen所追求的正是我的zsh的行为,因此这绝对是可能的。ssh-keygen-lf~/.ssh给了我一个文件完成列表。@NilsLuxton您好,您既可以获取选项
ssh-keygen-
选项卡,也可以在执行
ssh-keygen-lt~/.s
选项卡时获取文件,如果是,请告诉我您是怎么做的。是的,没错,但我对这一切的运作方式知之甚少,无法告诉你怎么做……对不起!如果你在#zsh回到IRC,我们可以一起尝试解决这个问题——我觉得我找到了一些东西