问题
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-tcp
Tab 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