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

RE: some directory changing tools to share

Just to add some more sugar and correct some mistakes :-)

> mkkwong@xxxxxxxxxx wrote:
> >non-directory filenames that also begins with "Le" (you can get
> around one
> >of the problems by redefining the completion rules for "cd").
> Actually most of what your "c" function does can be done with completion
> in zsh.  The standard completion for cd only completes to names of
> directories anyway.  With
> 	zstyle ':completion:*:cd:*' matcher-list 'm:{A-Z}={a-z}'

This won't work for two reasons.

1. to allow lower case on _command_line_ to match upper case in _file_names_
(in our case) matcher is exactly other way round

2. the 'matcher-list' is gobal and cannot be set on per-command basis. The
above will be ignored by Zsh. If you want it to apply to just cd - use
"matcher" style (you even can specify, that only local directories and not
directories in CDPATH should be treated this way).

So, the correct way is

zstyle ':completion:*:cd:*' matcher 'm:{a-z}={A-Z}'

Oh, yes, and this will work for any directory in your CDPATH - not just for
subdirectory of your current dir.

> completion on cd is one-way case insensitive, the way you want it.
> With menu completion, you can have the lexically first match inserted
> straight away (or with AUTO_MENU on the second or third tab), so you don't
> even have to type an unambiguous prefix.  Continuing menu completion,
> you can get to matches other than the lexically first, still without
> typing an unambiguous prefix.  And the big advantage of completion over
> your functions is that if you make a mistake, you can see it before
> actually executing the command.

And you can turn on visual full screen selection so that you can select
match from the list using customary Up/Down/Left/Right key binding (cursor
keys). This may save you some TABs if list is long.

> >Using my tool, you just type
> >
> >   c l
> With MENU_COMPLETE and the zstyle noted above, "cd l<tab>".  If you use
> AUTO_CD, you can actually drop the "cd " part.
> >Rule 1 works recursively down the directory tree one level at a
> time, with
> >unlimited depth.
> Same for completion.  It'll add a trailing "/" to any complete match
> it inserts, after which you can press tab again to complete the next
> level down.  If in the middle of menu completion, and you don't want
> to type any actual letters, type the "/" yourself to break out of menu
> completion and then tab will start completion at the next level.

And if you use menu selection mentioned above, you can press "/" and this
will try to complete next level immediately.

> >   c p t g
> >
> >takes you all the way to Perl/Test/Gui.
> "cd p<tab>t<tab>g<tab>".

Actually, with current completion and the above matcher this is even

cd p/t/g<TAB>

If the Perl/Test/Gui is unambiguous, it will be immediately expanded. If you
happen to have

Perl/Test/Gui and

Zsh will expand the longest prefix. What happens then, is configurable - I
personally set it to start menu selection, so I get something like

cd Perl/T<CURSOR here>/G
Test Trash

and can select Test, press "/" and immediately start completing inside of
Perl/Test. Or enter "e" (note - cursor is exactly at the right place) and
hit TAB once more - and it will expand the whole input. And, as mentioned by
Zefram, you have full control and see exactly what thye result is. And can
always cancel command you you made a mistake.

Hey, is not this cool! :))


Have a nice DOS!
B >>

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