zsh-workers
 help / color / mirror / code / Atom feed
* dynamic named directories clobber $reply
@ 2011-06-04 12:24 Mikael Magnusson
  2011-06-04 18:45 ` Bart Schaefer
  2011-06-04 21:24 ` Peter Stephenson
  0 siblings, 2 replies; 4+ messages in thread
From: Mikael Magnusson @ 2011-06-04 12:24 UTC (permalink / raw)
  To: zsh workers

I noticed that after a successful ~[something] substitution, ~[] or
~[invalid] would return the same substitution, because $reply leaks to
the parent shell, and my function doesn't unset $reply when it doesn't
find anything valid. If I make it local in the function it doesn't
work at all, is there some way it can be local in the hook somehow?

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: dynamic named directories clobber $reply
  2011-06-04 12:24 dynamic named directories clobber $reply Mikael Magnusson
@ 2011-06-04 18:45 ` Bart Schaefer
  2011-06-04 21:24 ` Peter Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2011-06-04 18:45 UTC (permalink / raw)
  To: zsh workers

On Jun 4,  2:24pm, Mikael Magnusson wrote:
} Subject: dynamic named directories clobber $reply
}
} I noticed that after a successful ~[something] substitution, ~[] or
} ~[invalid] would return the same substitution, because $reply leaks to
} the parent shell, and my function doesn't unset $reply when it doesn't
} find anything valid. If I make it local in the function it doesn't
} work at all, is there some way it can be local in the hook somehow?

I'd say the short answer to that is "no".  Nothing else that uses
reply/REPLY internally to the shell invokes any kind of local context
for them.

However, the hook conceivably could explicitly unset reply before the
call to the shell function.  This would have to happen in Src/utils.c
subst_string_by_hook(), and presumably only if a function or variable
named zsh_directory_name was actually found.

I'm undecided whether that's the correct thing to do, or whether it
really should be up to the shell function to make sure reply is correct
regardless of whether it found a match or not.  It's unclear because in
the case of an array of zsh_directory_name_hook functions, you may not
want each to go clobbering the results of the one before.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: dynamic named directories clobber $reply
  2011-06-04 12:24 dynamic named directories clobber $reply Mikael Magnusson
  2011-06-04 18:45 ` Bart Schaefer
@ 2011-06-04 21:24 ` Peter Stephenson
  2011-06-04 21:34   ` Mikael Magnusson
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2011-06-04 21:24 UTC (permalink / raw)
  To: zsh workers

On Sat, 4 Jun 2011 14:24:14 +0200
Mikael Magnusson <mikachu@gmail.com> wrote:
> I noticed that after a successful ~[something] substitution, ~[] or
> ~[invalid] would return the same substitution, because $reply leaks to
> the parent shell, and my function doesn't unset $reply when it doesn't
> find anything valid.

In addition to Bart's reply, this would only be an actual bug if it was
happening when your function returned non-zero, which is what it's supposed to
do if it doesn't have a match.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: dynamic named directories clobber $reply
  2011-06-04 21:24 ` Peter Stephenson
@ 2011-06-04 21:34   ` Mikael Magnusson
  0 siblings, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2011-06-04 21:34 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh workers

On 4 June 2011 23:24, Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> On Sat, 4 Jun 2011 14:24:14 +0200
> Mikael Magnusson <mikachu@gmail.com> wrote:
>> I noticed that after a successful ~[something] substitution, ~[] or
>> ~[invalid] would return the same substitution, because $reply leaks to
>> the parent shell, and my function doesn't unset $reply when it doesn't
>> find anything valid.
>
> In addition to Bart's reply, this would only be an actual bug if it was
> happening when your function returned non-zero, which is what it's supposed to
> do if it doesn't have a match.

Yeah, it turned out I forgot to return 1 on failure in my function. I
was worried about the hooks not having any way to unset reply so they
wouldn't clobber eachothers' results, but then I realized I was
confusing it with the completion case where they all get to add stuff.
In the n case though, as soon as one hook returns true no more hooks
are called so it should be fine.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-06-04 21:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-04 12:24 dynamic named directories clobber $reply Mikael Magnusson
2011-06-04 18:45 ` Bart Schaefer
2011-06-04 21:24 ` Peter Stephenson
2011-06-04 21:34   ` Mikael Magnusson

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).