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

Re: Function names prefixed with "%"

On Thu, May 26, 2022 at 6:15 PM Zach Riggle <zachriggle@xxxxxxxxx> 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.

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