zsh-users
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Filipe Silva <filipe.silva@gmail.com>, Zsh Users <zsh-users@zsh.org>
Subject: Re: constructing a zsh array from a specific tree structure
Date: Wed, 23 Aug 2017 01:15:39 +0000	[thread overview]
Message-ID: <1503450939.3587810.1081920008.63F59421@webmail.messagingengine.com> (raw)
In-Reply-To: <CAEwkUWOdKgOG2mVfuxLmFpAwGjLzwBMDGGNiFv=53oASq=vK4g@mail.gmail.com>

Filipe Silva wrote on Tue, 22 Aug 2017 21:25 -0300:
> zsh $ tree -L 2
> .
> |-- ninrod
> | |-- docker-compose-zsh-completion
> | |-- docker-zsh-completion
> | |-- k
> | `-- zsh-bd
> |-- seebi
> | `-- dircolors-solarized
> |-- zdharma
> | `-- fast-syntax-highlighting
> `-- zsh-users
> |-- zsh-completions
> `-- zsh-history-substring-search
> 
> 12 directories, 0 files
> zsh $
> 
> 
> from this structure, I want to construct this array:
> 
> plugin_paths+=(ninrod/docker-zsh-completion)
> plugin_paths+=(ninrod/docker-compose-zsh-completion)
> plugin_paths+=(ninrod/zsh-bd)
> plugin_paths+=(zsh-users/zsh-completions)
> plugin_paths+=(zdharma/fast-syntax-highlighting)
> plugin_paths+=(ninrod/k)
> 
> is there a way to do that in zsh?

What's the rule?  Why is zsh-users/zsh-completion there and
seebi/dircolors-solarized not?

I'm guessing you want:
.
    plugin_paths+=( */*/.git(N:h) )

or:
.
    typeset -aU plugin_paths
    plugin_paths+=( */*/*.plugin.zsh(N:h) )

Explanation: */*/.git expands to the names of all directories named foo/bar/.git.
If there are none, it will append nothing, because of the (N) qualifier
(otherwise an error would have been raised).  The (:h) qualifier drops the last
path component, leaving just foo/bar.  The second solution is similar, but
uses the -U flag to make the array unique, in case the glob has more than
one match in a single directory.

Cheers,

Daniel


      reply	other threads:[~2017-08-23  1:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-23  0:25 Filipe Silva
2017-08-23  1:15 ` Daniel Shahaf [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=1503450939.3587810.1081920008.63F59421@webmail.messagingengine.com \
    --to=d.s@daniel.shahaf.name \
    --cc=filipe.silva@gmail.com \
    --cc=zsh-users@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).