3

I have setopt extended_glob, I want to exclude all files under ~/.config/zsh that either start with _ or filename is completion.zsh or options.zsh

I have this command:

for f (${${(%):-%x}:P:h:h}/**/([^_|^completion|^options])*.zsh) print $f

It does the job but above command also exclude lazyload.zsh, why above command exclude this pattern? I expected it will print out lazyload.zsh.

1 Answer 1

5

Just:

${${(%):-%x}:P:h:h}/**/(^(_|completion|options)*).zsh

^ is the extendedglob negation operator.

Remember [anything] only ever matches one character¹.

[a|b] matches a, | or b, [^a|b] matches any character but a, | or b.

So your pattern excludes lazyload.zsh because l is in the list of character excluded by your [^...] single-character-matching operator.


¹ (in zsh; in some other shells, it may also match multi-character collating elements in some locales; zsh's [...] can also match bytes not forming parts of valid characters, YMMV with other shells)

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.