zsh-users
 help / color / mirror / code / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Thomas Lauer <thomas.lauer@virgin.net>
Cc: Bart Schaefer <schaefer@brasslantern.com>, Zsh Users <zsh-users@zsh.org>
Subject: Re: _pick_variant
Date: Fri, 13 Nov 2020 11:42:07 +0100	[thread overview]
Message-ID: <CAN=4vMq45pnkpKFx9ntbfP68zGjq5gO5e_43r-F3hoiJcFSiqw@mail.gmail.com> (raw)
In-Reply-To: <20201113093443.afd8d11e641eedb409c2ee37@virgin.net>

On Fri, Nov 13, 2020 at 10:35 AM Thomas Lauer <thomas.lauer@virgin.net> 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
          _comps[$k]=_default
        fi
      done
    }

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.

Roman.


  reply	other threads:[~2020-11-13 10:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13 17:41 _pick_variant Thomas Lauer
2020-11-12 18:35 ` _pick_variant Bart Schaefer
2020-11-12 18:40   ` _pick_variant Roman Perepelitsa
2020-11-12 19:07     ` _pick_variant Ray Andrews
2020-11-12 19:17       ` _pick_variant Roman Perepelitsa
2020-11-12 19:20       ` Fwd: _pick_variant JAMES R CUTLER
2020-11-13  9:34   ` _pick_variant Thomas Lauer
2020-11-13 10:42     ` Roman Perepelitsa [this message]
2020-11-13 10:57       ` _pick_variant Thomas Lauer
2020-11-13 11:18       ` _pick_variant Roman Perepelitsa
2020-11-13 22:26       ` _pick_variant Bart Schaefer
2020-11-14  9:56         ` _pick_variant Thomas Lauer
2020-11-14 19:21           ` _pick_variant Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN=4vMq45pnkpKFx9ntbfP68zGjq5gO5e_43r-F3hoiJcFSiqw@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=thomas.lauer@virgin.net \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).