-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
Description
Here's the implementation of ZSH_HIGHLIGHT_DIRS_BLACKLIST:
zsh-syntax-highlighting/highlighters/main/main-highlighter.zsh
Lines 1229 to 1240 in e851724
# Check if this is a blacklisted path | |
if [[ $expanded_path[1] == / ]]; then | |
tmp_path=$expanded_path | |
else | |
tmp_path=$PWD/$expanded_path | |
fi | |
tmp_path=$tmp_path:a | |
while [[ $tmp_path != / ]]; do | |
[[ -n ${(M)ZSH_HIGHLIGHT_DIRS_BLACKLIST:#$tmp_path} ]] && return 1 | |
tmp_path=$tmp_path:h | |
done |
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 notTo pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
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
).
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity