Restricting zstyle completion to functions in a zsh plugin

巧了我就是萌 提交于 2020-04-18 05:44:17

问题


I want to add smart completion to a custom Oh My Zsh plugin. Presently, the plugin contains >150 functions like this:

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

This answer helpfully explained how to get e.g. qq-tcpTab to complete to the three tcpdump options. This works:

zstyle ':completion:*' matcher-list 'r:|[-]=**'

However, setting this in the plugin overwrites the matcher-list provided by Oh My Zsh. I'd like to be a good citizen, which seems like it would mean only invoking this special completion when the user has already entered qq-. I've used the zstyle completion trick to explore how to restrict the specification, e.g.:

zstyle :completion:Tab

And it seems that e.g. zstyle :completion::complete:_____ only accepts one of the commands in your path. And since the things I'm matching are zsh functions, they aren't available to restrict by.

I have gotten this working by adding the matcher-list argument to the end of the pre-existing zstyle command:

➜  ~ OLD=`zstyle -L ':completion:\*' matcher-list`
➜  ~ echo $OLD
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*'
➜  ~ NEW="${OLD} 'r:|[-]=**'"
➜  ~ eval ${NEW}
➜  ~ zstyle -L ':completion:\*' matcher-list
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*' 'r:|[-]=**'

But I'm not sure if this is the recommended way to make this sort of change.

来源:https://stackoverflow.com/questions/60728961/restricting-zstyle-completion-to-functions-in-a-zsh-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!