zsh-users
 help / color / mirror / code / Atom feed
* constructing a zsh array from a specific tree structure
@ 2017-08-23  0:25 Filipe Silva
  2017-08-23  1:15 ` Daniel Shahaf
  0 siblings, 1 reply; 2+ messages in thread
From: Filipe Silva @ 2017-08-23  0:25 UTC (permalink / raw)
  To: Zsh Users

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

Hi,

I want to construct a zsh array using a tree structure as a source. like so:


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?

thanks in advance,

Filipe Silva

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

* Re: constructing a zsh array from a specific tree structure
  2017-08-23  0:25 constructing a zsh array from a specific tree structure Filipe Silva
@ 2017-08-23  1:15 ` Daniel Shahaf
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Shahaf @ 2017-08-23  1:15 UTC (permalink / raw)
  To: Filipe Silva, Zsh Users

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


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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-23  0:25 constructing a zsh array from a specific tree structure Filipe Silva
2017-08-23  1:15 ` Daniel Shahaf

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