zsh-workers
 help / color / mirror / code / Atom feed
* Skip singleton directories when tab completing
@ 2017-08-24 19:37 Daniel Li
  2017-08-24 21:15 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Li @ 2017-08-24 19:37 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 729 bytes --]

Hi all,

I frequently find myself navigating directories such as the following:

src
└── main
    └── scala
        └── com
            └── tubitv
                └── metadata
                    ├── users
                    │   ├── SomeFile.scala
                    │   └── SomeOtherFile.scala
                    └── Application.scala

I'll have to manually type out src/main/scala/com/tubitv/metadata each
time.  Is there a Zsh feature that autocompletes all the singleton
directories so that I can directly go to the leaf dir?

Regards,

*Daniel Li*
Senior Backend Engineer at Tubi TV

560 Mission St, Suite 1301

San Francisco, CA 94105

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Skip singleton directories when tab completing
  2017-08-24 19:37 Skip singleton directories when tab completing Daniel Li
@ 2017-08-24 21:15 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2017-08-24 21:15 UTC (permalink / raw)
  To: zsh-workers

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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-24 21:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-24 19:37 Skip singleton directories when tab completing Daniel Li
2017-08-24 21:15 ` Bart Schaefer

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