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

Re: Completing a unique prefix of "script" completes "script"



"Nikolai Weibull" wrote:
> On 8/10/06, Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> 
> > zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[.,_-]=**r:|=
> **'
> 
> What exactly are the 'r's doing here?

That's become a bit garbled: the bit we're referring to should look like

'r:|[.,_-]=** r:|=**'

There's a fairly full description of this in MATCHING CONTROL in the
zshcompwid manual page---in something of the sense of "I couldn't walk
across the English Channel because the sea was fairly full", so I'll
summarise here.  The general form is

r:LPAT|RANCHOR=TPAT

where LPAT has to occur on the left of the string already on the command
line, RANCHOR indicates something at the right hand end of the string on
the line, and TPAT says what sort of pattern to use to try to match the
stuff in the middle when looking for possible completions.  The LPAT
isn't commonly used and if it's empty it has no particularly special
meaning.  The [.,_-] says look for any part of the code on the command
line which has any of the those characters to the right.  The ** then
says match anything there; a single * wouldn't allow the anchor,
i.e. the character out of that set in square brackets, to be matched
itself, so you'd have to have typed any anchor characters yourself.

The result is that something like u-l-o-h is matched as u*-l*-o*-h.
(If we'd used r:|[.,_-]=* those *'s wouldn't have matched further -'s,
as we've doubled the * they can.)

The r:|=** matches at the end of the string:  that's only necessary if
you're completing in the middle and want to act as if there was a *
there.  In other words, without it, u-l-o<CURSOR>-h would have been
treated as u*-l*-o*-h, with it it's treated as u*-l*-o*-h*.  (This
supposedly depends on COMPLETE_IN_WORD being set; if it isn't completion
always takes place at the end.)

Quite why this forces a distinction between script as an executablle and
script as a directory is one of the great mysteries of the modern world.

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



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