Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Possible bug: HASH_CMDS has no observable effect
- X-seq: zsh-workers 47373
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- Subject: Re: Possible bug: HASH_CMDS has no observable effect
- Date: Sat, 12 Sep 2020 01:35:12 -0700
- Archived-at: <https://zsh.org/workers/47373>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2020-09/CAH%2Bw%3D7YDbOLz8Vp9v1tuweX9rGynS19GQ3FDiSryvqX%3Diz2sNA%40mail.gmail.com>
- Authentication-results: zsh.org; iprev=pass (mail-oi1-f174.google.com) smtp.remote-ip=209.85.167.174; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oVPZdUHe+qG30PLr/93321F9SShBbY/OPzB+UzDEBgU=; b=WHUfnbLnmBIfJ+rTKJcuWyrOtaRQF0IQC7uVUEVIeoS5yC24xYvXTpfRGXn9saweNZ dtek7FiUyA631GjrCiOJ/iMj+r1GgycnPPRvy0t/cczDobRbtfIOVTxeLmBF63b1sFvN AIktvhsbm3nmWSsaehQYz7BNPACpzYyyIED1RXoTfpTnhplBX4D/QizLxgdXHQJu9QSx 72Vmww+8EJGDtffbdYsOmDZnhhrX6FL6XBW9WDz/z8C96qeYINjUhIQHNuSxmVazH0AU 8vxNqdIYMIV3i82O03YxKTnj68TAz/zFnKzeZASJeHqe5keFDlEAR8La0EQ4aldfZeQP O6Nw==
- In-reply-to: <CAN=4vMrC2QjfxWaPUE9QS9tENBu=7BB=Hmp5rY6SaFahFThq=Q@mail.gmail.com>
- List-archive: <http://www.zsh.org/sympa/arc/zsh-workers>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-workers.zsh.org>
- List-owner: <mailto:zsh-workers-request@zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-workers>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-workers>
- References: <CAN=4vMqM-2Vu0n+QTbA9B_9z=3DKDdiOKbDRRaGGOG2rbY7-jA@mail.gmail.com> <20200911144852.GA1669764@fullerene.field.pennock-tech.net> <CAN=4vMrFhmKitKbdPdabZ1Ey9cjmEf62GVaGVMxn6T9AjZVc8Q@mail.gmail.com> <20200911161000.GA1679994@fullerene.field.pennock-tech.net> <CAN=4vMq-prFqopCW8apuYO8YUnuKL8G=WX+jBXFwgiFkfY=5Pw@mail.gmail.com> <CAH+w=7Y2VQpidVcinSXkQQqng0XjOwYtWL7a8jiYFx+te7fQCw@mail.gmail.com> <CAN=4vMrC2QjfxWaPUE9QS9tENBu=7BB=Hmp5rY6SaFahFThq=Q@mail.gmail.com>
- Sender: zsh-workers-request@xxxxxxx
On Sat, Sep 12, 2020 at 12:02 AM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
> Do I understand it correctly that this is working as intended? It
> appears to contradict the documentation for HASH_CMDS, which states
> that commands are hashed when they are invoked for the first time.
What it really means is that commands are hashed the first time a path
search finds them.
If you have only HASH_CMDS, then "a path search finds" just the single
command you invoked. If you tend to be using one, or a few, commands
repeatedly, and never invoke anything else, this is all you need to
avoid path search overhead for commands that exist. It remains
"expensive" to discover that a command does not exist.
If you also have HASH_DIRS set, then "a path search finds" every entry
in every directory that is searched. This eliminates the search
overhead for any external command you might use in the future. In
order to avoid the expense of a useless search when for example you
make a typo, the assumption is made that if the command is not already
in the cache then it must not be in any part of the path that has
previously been searched. The whole search-and-cache process is
short-circuited.
This really is the intended behavior, because for most people most of
the time new commands do not appear in the path during a shell
session. It's also the reason that HASH_EXECUTABLES_ONLY eventually
got added, because the "every entry in every directory" part tends to
be too aggressive for some path elements.
Historically, HASH_CMDS predates HASH_DIRS by several years, and the
documentation for the former still uses the wording that encompassed
that state.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author