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

Re: BUG: locals remove setopt autonamedirs



On Fri, Apr 3, 2026 at 7:32 AM Charles Blake <charlechaud@xxxxxxxxx> wrote:
>
> #!/bin/zsh -i
> setopt autonamedirs # -i necessary, but..
> hash -d nm=/a/path  #..No $HOME||global rc

This is your problem.  You've asked (autonamedirs) that changes to
parameters are automatically reflected in the named directory table,
but then you've directly inserted something into that table with no
associated variable.  Then you get here:

> function test_local_nm {
>   local nm="/b/path"
> }

Autonamedirs is going to update the named directory table on
assignment to "nm".  When the function scope ends, "nm" becomes unset,
and the named directory table is again automatically updated.

Any of the following will "fix" this:
1. do not setopt autonamedirs
2. use { nm=/a/path } at top level rather than poke with hash -d
3. in the function, setopt localoptions noautonamedirs (before
assigning any other locals)

Everything here seems to be working as intended.

> It looks kind of bad for the usual idea of `local`.

Keep in mind that both parameters and setopts are dynamically scoped,
so you must handle both of them when you don't want them to combine.




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