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

Re: Multipart autocomplete, zstyle, and cd



On Sun, Dec 5, 2021 at 5:29 PM Zach Riggle <zachriggle@xxxxxxxxx> wrote:
>
>             _wanted -V popular-directories expl 'popular directories' \
>                 compadd -Q -a dirs
> #-------------------------- COMPLETION ENHANCEMENT ---------------------------
> This completion works well, though I would like to know how to get the
> completion to not do word-separated completion and upon e.g.
>
>     $ foobarbaz bi<tab>
>
> ... to not add a space, but instead allow further specification e.g.,

You should add the -f option to compadd, so that it knows the results
are file names (which includes directories).  I suspect you also do
not really need/want the -Q option.

You should also NOT include the trailing slash in the values returned
from zshz-cd-completion.  Either -f will cause compadd to figure that
out, or you should be passing the options -S "/" and -q to compadd (if
the strings returned by zshz-cd-completion might not refer to existing
directories).

> #-------------------------- CURRENT CD AUTOCOMPLETE --------------------------
> I would like to know how to get these results added to "cd"
> autocompletion.
>
> zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories
>
> When I do "cd <tab>", I get a single section, "-- local directory --".

With that tag-order, you will only see path-directories if $cdpath is
non-empty and there are no local directories.  Is that what you
wanted?  (Directory-stack completes shorthands like "+1" so it
normally doesn't matter where it appears in tag-order as long as it's
there at all.  [Someone please demonstrate how I've got this wrong, if
I have.])

> #-------------------------- ADDING A SECTION TO CD ---------------------------
>
> Any pointers would be useful -- it's not clear if I need to define a
> new tag somehow (via _tags?) or modify the _cd function and put my
> modified copy earlier in $fpath.  I hope / expect that this is
> something that can be MOSTLY achieved via zstyle, but I'm not clear
> how.

There are a bunch of ways depending on the effect you want to get ...
probably the easiest would be to use compdef to put a wrapper around
_cd that also calls your function.  Something like this:

compdef '_alternative \
  "popular-directories:popular directories:( $(zshz-cd-completion) )" \
  ::_cd' \
  cd

Caveat, this will misbehave if zshz-cd-completion outputs strings
containing double quotes or equal signs.




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