Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: constructing a zsh array from a specific tree structure
- X-seq: zsh-users 22852
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Filipe Silva <filipe.silva@xxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: constructing a zsh array from a specific tree structure
- Date: Wed, 23 Aug 2017 01:15:39 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=bs1667 gjDIi79Z79ZbqEkRbp2c4fZS8WyXim4Y4jnto=; b=mEPqcYCUh2TRGk31fBQlGt oDq8OUUNYzKHgxaotb5/w9HRN4GnDXjraoCtwPcs3c18jZwHPcMkiw1G7jNLNuFd mo6cC4+/5vkKpSQaVgWhHMvJyZV+NscIBD+rTEkAWUsNG5OB7yVk772lOz80MPaO df5boABFML9PyvRdu0LNqurCFZvWsOpUuCY9HHwnN4oRGSJuqGRSPIo2avCK9hRl qXPmyxo31LYvUECbiqC/4qFnxWbQ9U03CNpJ5UyXOG81iaEWzvz18gE3lexgMRDq PW/7IRuokKtS7j9xvJ+qtE9kOib3jro0/HvFt4Wa8UBVSoI6hdu/D1rShEhE1hDQ ==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=bs1667 gjDIi79Z79ZbqEkRbp2c4fZS8WyXim4Y4jnto=; b=ikHZZlzGj52vF5ZU05KHaA PF/+NsWDkhlT7rCCXqxP3n0THtiaRJMYe+Hk4GD0Kg+QU2G1Gg6mCUH29DiwYJo4 4YuaeNy5xHqpkMVLhvf1k6wPyPNh0fJ8O9pWK6sv613hRfJmS4JhZwzVZufz12/7 rcVfktIVIN7aq/fjrfgP5oZGb8SwMRCBkK3W5+ByFnjVZZVZaVM7qQXoaEfxEvBI nzUoZQD+LW70wBWjGB0fb6LoBupxA6AHeu+xXdNmO78xgwO6E1QoZRPGgLzCGiJt yXQGLFl2Y/wHAjBsHtbgOjrqCxAzDAWI++Onf47lSrlvwwHjm6zLi/6aiOtYuW9Q ==
- In-reply-to: <CAEwkUWOdKgOG2mVfuxLmFpAwGjLzwBMDGGNiFv=53oASq=vK4g@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author