在zsh中完成命令名称本身 [英] Completing command name itself in zsh

查看:154
本文介绍了在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命令的参数.但是,有什么更简单的方法让我丢失吗?

解决方案

您可以使用 nofollow noreferrer> zstyle 内置.默认情况下,完成仅尝试添加后缀,但是您可以使用完全匹配控制规范. Zsh按顺序尝试它们,并在找到匹配项后立即停止.使用空规范仅添加一个后缀;您通常会首先需要这样做,除非在非常特殊的情况下很难做到这一点.您可以使用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-tcpTab 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-tcpTab 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屋!

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