Zsh Mailing List Archive
Messages sorted by:
Re: compctl tips needed on words with common prefix
- X-seq: zsh-users 1629
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- To: Paul Lew <lew@xxxxxxxxxxxxxxxxxx>, zsh-users@xxxxxxxxxxxxxxx
- Subject: Re: compctl tips needed on words with common prefix
- Date: Wed, 17 Jun 1998 11:27:24 -0700
- In-reply-to: <9806171633.AA09038@xxxxxxxxxxxxxxxxxx>
- References: <9806171510.AA08785@xxxxxxxxxxxxxxxxxx> <980617090730.ZM15226@xxxxxxxxxxxxxxxxxxxxxxx> <9806171633.AA09038@xxxxxxxxxxxxxxxxxx>
On Jun 17, 12:33pm, Paul Lew wrote:
} Subject: Re: compctl tips needed on words with common prefix
} >>>>> "Bart" == Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> writes:
} Bart> What you mean to say, I think, is that any of (co1 co2 co3)
} Bart> may appear *after* "co ". Right? In that case, what you
} Bart> want is "c[-1,co]":
} Bart> compctl -k "(ci co construct cinema)" \
} Bart> -x "c[-1,co]" -k "(co1 co2 co3)" \
} Bart> - "c[-1,construct]" -k "(cons1 cons2)" -- xxx
} That works. But my situation is a little different, what I would like
} is to have "co1 co2 co3" be part of the completion words as long as
} there is a word "co" in front, i.e.,
} xxx co co1 co2 or
} xxx co co3 co1 co2
} Do c[offset,string] require a fixed offset or can be a range?
Yes, the offset must be fixed for c.
} Also, I still want to be able to complete the 'construct'.
Your best bet might be to go with compctl -K and write yourself a function
to perform the pattern matching. The built-in mechanisms aren't designed
to deal easily with so many words with common prefixes. (If your command
looked like "xxx -co co1 co2 -construct cons1" then it'd be much easier.)
Here's a sample that illustrates two possible approaches to your problem
that don't use a -K function:
compctl -k "(ci co construct cinema)" \
-x "c[-1,co]" -k "(co1 co2 co3)" \
- "C[-1,co]" -k "(co1 co2 co3 construct)" \
- "c[-1,construct], C[-1,cons]" -k "(cons1 cons2)" -- xxx
The first approach is to use separate rules "c[-1,co]" and "C[-1,co]"
which tell what to complete after a word matching "co" and after a word
matching the glob pattern "co", respectively. This requires that you
maintain the (co1 co2 co3) list in two places, and also keep the glob up
to date, if those items in the -k list ever change.
The second uses alternative patterns "c[-1,construct], C[-1,cons]"
which match either "construct" or the glob "cons". This is a bit
simpler to maintain (one list and the equivalent glob) but does not permit
you e.g. to complete "co" following "cons1".
Good luck. (I hesitate to inquire further about the "xxx cinema" part ...)
Bart Schaefer Brass Lantern Enterprises
Messages sorted by: