zsh-users
 help / color / mirror / code / Atom feed
* Function names prefixed with "%"
@ 2022-05-27  1:14 Zach Riggle
  2022-05-27  1:36 ` Mikael Magnusson
  2022-05-27  3:49 ` Bart Schaefer
  0 siblings, 2 replies; 7+ messages in thread
From: Zach Riggle @ 2022-05-27  1:14 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 466 bytes --]

It seems that it's completely valid to declare a function with a leading
percent, but it's not able to be called due to be interpreted as job
control.

    $ %paste() { echo hi }

    $ declare -f '%paste'
    %paste () {
        echo hi
    }

    $ %paste
    fg: job not found: paste

Is there any way around this behavior?  I've found that this can be worked
around with aliases...

alias '%p=%paste'


But I expect there are other / better ways.

*Zach Riggle*

[-- Attachment #2: Type: text/html, Size: 1032 bytes --]

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

* Re: Function names prefixed with "%"
  2022-05-27  1:14 Function names prefixed with "%" Zach Riggle
@ 2022-05-27  1:36 ` Mikael Magnusson
  2022-05-27  1:57   ` Zach Riggle
  2022-05-27  3:49 ` Bart Schaefer
  1 sibling, 1 reply; 7+ messages in thread
From: Mikael Magnusson @ 2022-05-27  1:36 UTC (permalink / raw)
  To: Zach Riggle; +Cc: Zsh Users

On 5/27/22, Zach Riggle <zachriggle@gmail.com> wrote:
> It seems that it's completely valid to declare a function with a leading
> percent, but it's not able to be called due to be interpreted as job
> control.
>
>     $ %paste() { echo hi }
>
>     $ declare -f '%paste'
>     %paste () {
>         echo hi
>     }
>
>     $ %paste
>     fg: job not found: paste
>
> Is there any way around this behavior?  I've found that this can be worked
> around with aliases...
>
> alias '%p=%paste'
>
>
> But I expect there are other / better ways.

\%paste

-- 
Mikael Magnusson


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

* Re: Function names prefixed with "%"
  2022-05-27  1:36 ` Mikael Magnusson
@ 2022-05-27  1:57   ` Zach Riggle
  2022-05-27  2:40     ` Lawrence Velázquez
  0 siblings, 1 reply; 7+ messages in thread
From: Zach Riggle @ 2022-05-27  1:57 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 777 bytes --]

Unfortunately that kills the utility of the prefix :(

On Thu, May 26, 2022 at 8:36 PM Mikael Magnusson <mikachu@gmail.com> wrote:

> On 5/27/22, Zach Riggle <zachriggle@gmail.com> wrote:
> > It seems that it's completely valid to declare a function with a leading
> > percent, but it's not able to be called due to be interpreted as job
> > control.
> >
> >     $ %paste() { echo hi }
> >
> >     $ declare -f '%paste'
> >     %paste () {
> >         echo hi
> >     }
> >
> >     $ %paste
> >     fg: job not found: paste
> >
> > Is there any way around this behavior?  I've found that this can be
> worked
> > around with aliases...
> >
> > alias '%p=%paste'
> >
> >
> > But I expect there are other / better ways.
>
> \%paste
>
> --
> Mikael Magnusson
>
-- 

*Zach Riggle*

[-- Attachment #2: Type: text/html, Size: 1529 bytes --]

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

* Re: Function names prefixed with "%"
  2022-05-27  1:57   ` Zach Riggle
@ 2022-05-27  2:40     ` Lawrence Velázquez
  0 siblings, 0 replies; 7+ messages in thread
From: Lawrence Velázquez @ 2022-05-27  2:40 UTC (permalink / raw)
  To: Zach Riggle, Mikael Magnusson; +Cc: zsh-users

On Thu, May 26, 2022, at 9:57 PM, Zach Riggle wrote:
> Unfortunately that kills the utility of the prefix :(

Consider using prefixes that don't conflict with shell syntax.

-- 
vq


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

* Re: Function names prefixed with "%"
  2022-05-27  1:14 Function names prefixed with "%" Zach Riggle
  2022-05-27  1:36 ` Mikael Magnusson
@ 2022-05-27  3:49 ` Bart Schaefer
  2022-05-27 11:08   ` Mikael Magnusson
  1 sibling, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2022-05-27  3:49 UTC (permalink / raw)
  To: Zach Riggle; +Cc: Zsh Users

On Thu, May 26, 2022 at 6:15 PM Zach Riggle <zachriggle@gmail.com> wrote:
>
> It seems that it's completely valid to declare a function with a leading percent, but it's not able to be called due to be interpreted as job control.

The very first entry in Etc/BUGS says:

The pattern %?* matches names beginning with %? instead of names with at
least two characters beginning with %. This is a hack to allow %?foo job
substitution without quoting. This behaviour is incompatible with sh
and ksh and may be removed in the future.

You've noticed a corollary that command names can't be matched for the
same reason.

> Is there any way around this behavior?  I've found that this can be worked around with aliases...

You can check in an accept-line wrapper widget or in a zle-line-finish
hook for whether there actually is a job matching the pattern and
insert the necessary leading backslash if there is not.  Or if you
never use that job lookup syntax, you can just always edit every word
that begins with % to instead use \% via one of those functions.


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

* Re: Function names prefixed with "%"
  2022-05-27  3:49 ` Bart Schaefer
@ 2022-05-27 11:08   ` Mikael Magnusson
  2022-05-27 17:09     ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Mikael Magnusson @ 2022-05-27 11:08 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zach Riggle, Zsh Users

On 5/27/22, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Thu, May 26, 2022 at 6:15 PM Zach Riggle <zachriggle@gmail.com> wrote:
>>
>> It seems that it's completely valid to declare a function with a leading
>> percent, but it's not able to be called due to be interpreted as job
>> control.
>
> The very first entry in Etc/BUGS says:
>
> The pattern %?* matches names beginning with %? instead of names with at
> least two characters beginning with %. This is a hack to allow %?foo job
> substitution without quoting. This behaviour is incompatible with sh
> and ksh and may be removed in the future.

I think this is unrelated, the problem Zach has is that
% %foo() { echo hi }; %foo
outputs
fg: job not found: foo

While the bug is that
% echo %?foo
outputs
%?foo
instead of
zsh: no matches found: %?foo
eg, the ? in %?* is not a pattern character effectively.

You can combine these two problems but the result is quite anti-synergistic:
% %?foo() { echo hi }
% %?foo
fg: job not found: ?foo
% echo %?foo
%?foo

-- 
Mikael Magnusson


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

* Re: Function names prefixed with "%"
  2022-05-27 11:08   ` Mikael Magnusson
@ 2022-05-27 17:09     ` Bart Schaefer
  0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2022-05-27 17:09 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Zach Riggle, Zsh Users

On Fri, May 27, 2022 at 4:08 AM Mikael Magnusson <mikachu@gmail.com> wrote:
>
> On 5/27/22, Bart Schaefer <schaefer@brasslantern.com> wrote:
> >
> > The very first entry in Etc/BUGS says:
>
> I think this is unrelated

I think one could consider it from either direction.  The problem in
both cases is that "%" as the first character of a word is magic; the
difference is whether the word is in command position.

That might suggest a way to fix the glob problem that wouldn't fix the
job problem.


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

end of thread, other threads:[~2022-05-27 17:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-27  1:14 Function names prefixed with "%" Zach Riggle
2022-05-27  1:36 ` Mikael Magnusson
2022-05-27  1:57   ` Zach Riggle
2022-05-27  2:40     ` Lawrence Velázquez
2022-05-27  3:49 ` Bart Schaefer
2022-05-27 11:08   ` Mikael Magnusson
2022-05-27 17:09     ` Bart Schaefer

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