Open
Description
Here's the implementation of ZSH_HIGHLIGHT_DIRS_BLACKLIST:
zsh-syntax-highlighting/highlighters/main/main-highlighter.zsh
Lines 1229 to 1240 in e851724
That runs a nested loop for each ordinary (non-option) word on the command line. I suspect that's not very performant.
- Confirm whether that's performing acceptably or not
In case that's an issue, ideas:
- Special case the common case that ZSH_HIGHLIGHT_DIRS_BLACKLIST is empty.
- Join the blacklist entries into a pattern that uses alternations.
- Join the blacklist entries with NULs and use plain substring matching
The last option should be something like this:
readonly NUL=$'\0'
local -a t=( "" "${ZSH_HIGHLIGHT_DIRS_BLACKLIST[@]}" "" )
haystack="${(pj.\0.)^ZSH_HIGHLIGHT_DIRS_BLACKLIST[@]%/}/"
needle=${NUL}${expanded_arg%/}/${NUL}
if [[ $haystack == *$needle* ]]; then
That munges both the needle and the haystack by ensuring each path has a trailing slash and is both prefixed and suffixed by NULs (the latter is because /foo
shouldn't match /foobar
or /baz/foo
).
Activity