Skip to content

Commit 1fc2082

Browse files
committed
main: Add ZSH_HIGHLIGHT_DIRS_BLACKLIST
Closes zsh-users#379.
1 parent 1f1e629 commit 1fc2082

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

docs/highlighters/main.md

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ The syntax for values is the same as the syntax of "types of highlighting" of
7171
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
7272
manual page][zshzle-Character-Highlighting].
7373

74+
#### Parameters
75+
76+
To avoid partial path lookups on a path, add the path to the `ZSH_HIGHLIGHT_DIRS_BLACKLIST` array.
77+
78+
ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/slow_share)
79+
7480
### Useless trivia
7581

7682
#### Forward compatibility.

highlighters/main/main-highlighter.zsh

+15-1
Original file line numberDiff line numberDiff line change
@@ -756,14 +756,27 @@ _zsh_highlight_main_highlighter_highlight_path_separators()
756756
_zsh_highlight_main_highlighter_check_path()
757757
{
758758
_zsh_highlight_main_highlighter_expand_path $arg;
759-
local expanded_path="$REPLY"
759+
local expanded_path="$REPLY" tmp_path
760760

761761
REPLY=path
762762

763763
[[ -z $expanded_path ]] && return 1
764764
[[ -L $expanded_path ]] && return 0
765765
[[ -e $expanded_path ]] && return 0
766766

767+
# Check if this is a blacklisted path
768+
if [[ $expanded_path[1] == / ]]; then
769+
tmp_path=$expanded_path
770+
else
771+
tmp_path=$PWD/$expanded_path
772+
fi
773+
tmp_path=$tmp_path:a
774+
775+
while [[ $tmp_path != / ]]; do
776+
[[ -n "${(M)ZSH_HIGHLIGHT_DIRS_BLACKLIST:#$tmp_path}" ]] && return 1
777+
tmp_path=$tmp_path:h
778+
done
779+
767780
# Search the path in CDPATH
768781
local cdpath_dir
769782
for cdpath_dir in $cdpath ; do
@@ -1063,3 +1076,4 @@ else
10631076
# Make sure the cache is unset
10641077
unset _zsh_highlight_main__command_type_cache
10651078
fi
1079+
typeset -ga ZSH_HIGHLIGHT_DIRS_BLACKLIST
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -------------------------------------------------------------------------------------------------
2+
# Copyright (c) 2018 zsh-syntax-highlighting contributors
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without modification, are permitted
6+
# provided that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice, this list of conditions
9+
# and the following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice, this list of
11+
# conditions and the following disclaimer in the documentation and/or other materials provided
12+
# with the distribution.
13+
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
14+
# may be used to endorse or promote products derived from this software without specific prior
15+
# written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
18+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23+
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
24+
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
# -------------------------------------------------------------------------------------------------
26+
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
27+
# vim: ft=zsh sw=2 ts=2 et
28+
# -------------------------------------------------------------------------------------------------
29+
30+
mkdir foo
31+
touch foo/bar
32+
BUFFER=": foo/bar $PWD/foo foo/b"
33+
ZSH_HIGHLIGHT_DIRS_BLACKLIST=($PWD/foo)
34+
35+
expected_region_highlight=(
36+
'1 1 builtin' # :
37+
'3 9 path' # foo/bar
38+
"11 $(( 14 + $#PWD )) path" # $PWD/foo
39+
"$(( 16 + $#PWD )) $(( 20 + $#PWD )) default" # foo/b
40+
)

0 commit comments

Comments
 (0)