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

Re: zsh and RPM: a case of study (for me)

Francis GALIEGUE (fg@xxxxxxxxxxxxxxxx) wrote:
> Hi,
> I'm a new subscriber to this list. I've used zsh for only 4 days now,
> but to my opinion it plain rocks.

It sure does :-)

> It already saves me a lot of time, no
> doubt on this, and I've even hacked a bit the base distribution that
> comes with it so that it can handle lftp (a change in a #compdef, no big
> deal) and .tar.bz2 archives cleanly.
> But all the rest is obscure to me.
> I've d/led the postscript of the manual and printed out, guess what,
> chapters 20, 21 and 23. But I haven't got what I want. Like all manuals,
> unfortunately, it's exhaustive but doesn't give enough examples :(

Agreed - I've been using zsh for quite a while now, but I found it
very tough at first even understanding the new completion system in
3.1.6.  At the end of the day, zsh is a very intricate shell and
there's no getting away from its complexity, but examples do go a long
way, and I found the ones given very helpful.

However, it's probably good to keep the distinction between a
(reference) manual and a tutorial/guide, and fortunately Peter's just
published an unfinished first draft of one
(http://www.ifh.de/~pws/computing/zshguide_intro.html if you missed
the post) which if first looks are to go by, will be a wonderful
complement to the very well written but tough manual.

> What are really completion widgets? Even after rereading the
> aforementioned chapters 3, 4 times I still couldn't figure it out. When
> are they called, what do they do, etc, and more importantly, HOW TO
> Just for example, lets say I have a:
> compctl -X bar -k "(a b)" foo

That's your first problem.  `compctl' is the old style of programmable
completion, which (in terms of configuration) is completely separate
and different to the new, widget-based style.  What version do you
have installed?  It sounds like you have a 3.1.something.  What I say
below applies to 3.1.6; if you don't mind using a development version
with warts and all, I'd recommend you try 3.1.6 or even the latest pws
patch from http://www.ifh.de/~pws/computing/, which has all the latest
bells and whistles.

Try an experiment: type `bindkey' from your zsh.  You'll get a list of
keys, and what widgets those keys are bound to.  For example,

  "^[f" forward-word

means when you press ESC f (or meta-f), it will invoke the
forward-word widget, which moves the cursor forward to the next word.
A completion widget is one which starts the cogs of the new
shell-script-based completion system whirring.

However, you don't normally need to make your own completion widgets;
you just incorporate your new completion into the existing system of
widgets.  For example, to convert your compctl example to the new

  function _foo {
    # Generate completion matches `a' and `b' with the explanation `bar'
    compadd -X bar - a b

  # Make the command `foo' complete arguments using the function `_foo'
  compdef _foo foo

(Note that all such functions like _foo above should start with an

Oh, the above won't work unless you've configured your setup to work
with the new completion system.  Read the `zshcompsys' man page for
details on how to do this (or just type `compinstall' if you can't be
bothered to read it :-)

In practice, because there are so many shell functions written for
completing all (well, some of) the different UNIX commands, it would
be inefficient for every invocation of zsh to load them all in at
startup.  So the `autoload' feature is used, where functions such as
_foo above are only loaded in when they're needed.

> Another probably dumb example: I'm used to the bash key sequences
> (C-x|Esc)(!|@|~|/|$), how can I reproduce them in a simple manner?

You should find that many (most?) of them already work in zsh.  If you
find you're really missing any of them, let us know and I'm sure one
of us will be only to happy to help.

> And for the hardest part now: a set of functions|widgets|whatever for
> rpm...


You're not the only one who wanted this behaviour, and so you'll be
glad to hear that someone's already done the hard work.  There's an
_rpm function distributed with 3.1.6-pws-6 which does all you want,
and much more.

> The problem is that I can generate each of these arrays individually (a
> mano for the options), but not tie them together so that it completes
> correctly in each of these cases... And I fear that the compctl function
> may not be enough for this :(

Actually it is, but the new system handles complex completions much
more effortlessly, and with greater success.

Damn, I can see similar questions arising when I get my friends going
on 3.1.6.  Peter, is any of that re-usable in the guide?  Probably

> I don't want this message to look like a rant, it's not - I really love
> this shell, but I wish there were a good, explanative, to-the-point
> programming guide too...

It's on its way!

> # rm *;o
> o: command not found


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