在zsh中完成命令名称本身 [英] Completing command name itself in zsh
问题描述
我有一堆非常详细的ZSH函数,我想在它们上使用zsh补全.示例:
qq-enum-dns-txfr-host
qq-enum-dns-brute-rev
qq-enum-dns-tcpdump
qq-enum-web-php-lfi-logfile
qq-enum-smb-tcpdump
qq-enum-web-php-ffuf-common-php
qq-enum-ftp-tcpdump
当我键入qq-tcp
Tab 时,我想获得以下内容的补全:
qq-enum-dns-tcpdump
qq-enum-smb-tcpdump
qq-enum-ftp-tcpdump
我能找到的所有文档都涉及如何完成给定命令或函数的参数,但没有说明如何使用子字符串(而不是前缀)完成来首先确定要使用哪个函数./p>
我想我可以重构,以便每个函数都代替qq
命令的参数.但是,有什么更简单的方法让我丢失吗?
您可以使用zstyle
r
规范允许标点符号左侧的部分完成:r:|[-+./_]=*
表示只要要完成的字符串包含字符-+./_
之一,匹配的完成就可以有任何内容(任何与*
匹配的内容) ,它匹配所有内容)在该标点符号的左侧.例如,qq-tcp
Tab 完成与qq*-tcp*
匹配的任何内容(最后的*
来自常规后缀完成).
zstyle ':completion:*' matcher-list '' 'r:|[-+./_]=*'
您可以通过交互式基本自定义界面compinstall
在匹配控制"下将其激活为部分单词完成".
I have a bunch of ZSH functions which are pretty verbose, and I'd like to use zsh completion on them. Example:
qq-enum-dns-txfr-host
qq-enum-dns-brute-rev
qq-enum-dns-tcpdump
qq-enum-web-php-lfi-logfile
qq-enum-smb-tcpdump
qq-enum-web-php-ffuf-common-php
qq-enum-ftp-tcpdump
When I type qq-tcp
Tab I'd like to get completions of:
qq-enum-dns-tcpdump
qq-enum-smb-tcpdump
qq-enum-ftp-tcpdump
All the documentation I can find deals with how to complete arguments to a given command or function, but doesn't say how to use the substring (not prefix) completion to figure out which function to use in the first place.
I guess I could refactor so that each function is instead an argument to a qq
command. But is there a simpler way I'm missing?
You can configure the completion system extensively with the zstyle
builtin. By default, completion only tries to add a suffix, but you can change this with a matcher-list
style. To apply the style to all completions:
zstyle ':completion:*' matcher-list …
To apply the style only when the context is a command, and only for commands that are functions:
zstyle ':completion:*:*:-command-:*:functions matcher-list …
What goes after matcher-list
is a list of completion matching control specifications. Zsh tries them in order, and stops as soon as one finds a match. Use the empty specification to just add a suffix; you'll usually want this first except in very specific contexts where this makes it hard to reach some completions. You can use an r
specification to allow partial completion to the left of punctuation characters: r:|[-+./_]=*
means that wherever the string to complete contains one of the characters -+./_
, a matching completion can have anything (anything matching *
, which matches everything) to the left of this punctuation character. For example, qq-tcp
Tab completes to anything matching qq*-tcp*
(the final *
is from regular suffix completion).
zstyle ':completion:*' matcher-list '' 'r:|[-+./_]=*'
You can activate this through the interactive basic customization interface compinstall
, under "Matching control", as "partial-word completion".
这篇关于在zsh中完成命令名称本身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!