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

Re: Skip singleton directories when tab completing

On Thu, Aug 24, 2017 at 12:37 PM, Daniel Li <dan@xxxxxxxxxx> wrote:
> Is there a Zsh feature that autocompletes all the singleton
> directories so that I can directly go to the leaf dir?

Assuming you've set up compinit ...

I've been using the following function in conjunction with the
_user_expand completer:

--- 8< --- _glob_expand --- 8< ---

# Plugin for the _user_expand completer.
# Recommended usage:
# zstyle ':completion:*:user-expand:*:' user-expand _glob_expand
# zstyle ':completion:*:user-expand:*:' tag-order 'expansions all-expansions'

# Attempt expansion with an additional "*" inserted at the cursor.
reply=( $~1* )
--- >8 --- _glob_expand --- >8 ---

The zstyles as shown in the comments above plus:

zstyle ':completion:*' completer _oldlist _expand _complete _match
_user_expand _ignored _approximate _prefix

(adjust for your preference).

What this allows you to do is to use the ** recursive glob operator in
your completion, e.g.

% cd src/**/meta

will tab-complete to

% cd src/main/scala/com/tubitv/metadata

Normally this would fail because for **/ to expand the final component
has to match more than a prefix, but by appending * it tries it as a
prefix match and expands the full recursion.

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