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

Re: constructing a zsh array from a specific tree structure



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