zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: Skip singleton directories when tab completing
Date: Thu, 24 Aug 2017 14:15:34 -0700	[thread overview]
Message-ID: <CAH+w=7bOhssS5Fy8mHNenyjQHC0HmR7TksVjcBAh436ZbPHQRQ@mail.gmail.com> (raw)
In-Reply-To: <CAN_nDg67HOSAWif-CKeidkj2B3S3KGdzhCBVxRs8+vUZF8z3+Q@mail.gmail.com>

On Thu, Aug 24, 2017 at 12:37 PM, Daniel Li <dan@tubitv.com> 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< ---
#autoload

# 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.


      reply	other threads:[~2017-08-24 21:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-24 19:37 Daniel Li
2017-08-24 21:15 ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7bOhssS5Fy8mHNenyjQHC0HmR7TksVjcBAh436ZbPHQRQ@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).