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

Re: [PATCH] Restrict named directories to scalar parameters.



On Mon, Jun 15, 2026 at 9:27 AM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>
> On Mon, Jun 15, 2026 at 5:40 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >
> > The question is ...
> >
> > setopt autonamedirs
> > foo=bar  # is it important that foo is (or is not yet) linked to the nameddir table?
> > foo=$HOME/foo # because now it's linked ...
> > foo=bar  # and now this (forever) has a different side-effect than before
>
> I guess it only matters to users who used hash foo=/bar explicitly,
> and would like unrelated parameters to not interfere.
> [...] maybe it would be reasonable to remove the
> PM_NAMEDDIR flag from foo after it is found to not be a named dir
> anymore?

Consider this sequence:

setopt autonamedirs
dirname=$HOME/mynameddir
unsetopt autonamedirs
hash -d dirname=/tmp

Now assign something to dirname.  Describe what should happen
-- when the value begins with a slash
-- when the value does not begin with slash

For "unset dirname", does it behave like the latter case?  Why or why not?

Now describe what happens in those 3 cases when that last "hash -d" is
"hash -r".

Now dispense with autonamedirs but use ~dirname before "hash -d" or
after "hash -r".

What I'm digging for is:

> (such that after your foo=bar assignment, I can restore my
> hash foo=/bar and subsequent assignments to foo don't erase it).

To make that actually work, I believe at some point in a few of the
cases above you end up sweeping the entire parameter table to clear
all PM_NAMEDDIR flags.

I think your earlier suggestion, which I'm going to state as:
  Enable ~name only for user homes and existing nameddir entries
Is the only approach that begins to make sense, and even then only if
autonamedirs is avoided.

I've started a few times down the thought-path of doing away with
PM_NAMEDDIR entirely, but that leaves us with no way to remove entries
from nameddir once they exist (except for the very hackish "nogob
unset nameddir[name]" or a blanket "hash -r").

As a further aside,
  hash [-d] name
does nothing it all ... it neither prints the entry for name, nor
changes it.  That does feel like something that could be changed.




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