Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: _pick_variant

On Fri, Nov 13, 2020 at 10:35 AM Thomas Lauer <thomas.lauer@xxxxxxxxxx> wrote:
> There's no md5 command anywhere on my system. I have md5{sum,pass} and that's it.

The clash isn't with an existing command but rather with a completion
function that's included in zsh. Zsh will use the completion function
_cksum whenever you are completing arguments of the command md5. It
doesn't matter (to Zsh) where the md5 command came from.

My latest similar clash was with the open command. This is a macOS
command but I'm using Linux, so I cannot even have the open command
that _open expects.

> Well, the quick solution is to change the name, as I did. However, when you say my "function doesn't handle that" this seems to imply that there's a way it could handle that situation. How?

If you want to complete only files when invoking md5, add this to
~/.zshrc (make sure it's after compinit):

    compdef _default md5

Alternatively, replace $1 with "$@" in the definition of your md5 and
tell zsh to complete md5 as md5sum:

    compdef md5=md5sum

The first solution can be generalized:

    () {
      local k v
      for k v in "${(kv)_comps[@]}"; do
        if [[ ${functions_source[$k]:-$commands[$k]} == ~/* &&
              $functions_source[$v] != ~/* ]]; then

This will disable programmable completions for all commands and
functions defined under $HOME that don't have their own completions.
If you have compdef calls in your dotfiles, you'll need to move them
below this stanza.


Messages sorted by: Reverse Date, Date, Thread, Author