main: Add ZSH_HIGHLIGHT_DIRS_BLACKLIST

Closes #379.
This commit is contained in:
Matthew Martin 2018-01-21 14:48:47 -06:00
parent 90b09f88ee
commit 6713727742
3 changed files with 61 additions and 1 deletions

View file

@ -71,6 +71,12 @@ The syntax for values is the same as the syntax of "types of highlighting" of
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
manual page][zshzle-Character-Highlighting].
#### Parameters
To avoid partial path lookups on a path, add the path to the `ZSH_HIGHLIGHT_DIRS_BLACKLIST` array.
ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/slow_share)
### Useless trivia
#### Forward compatibility.

View file

@ -757,7 +757,7 @@ _zsh_highlight_main_highlighter_highlight_path_separators()
_zsh_highlight_main_highlighter_check_path()
{
_zsh_highlight_main_highlighter_expand_path $arg;
local expanded_path="$REPLY"
local expanded_path="$REPLY" tmp_path
REPLY=path
@ -765,6 +765,19 @@ _zsh_highlight_main_highlighter_check_path()
[[ -L $expanded_path ]] && return 0
[[ -e $expanded_path ]] && return 0
# 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
# Search the path in CDPATH
local cdpath_dir
for cdpath_dir in $cdpath ; do
@ -1070,3 +1083,4 @@ else
# Make sure the cache is unset
unset _zsh_highlight_main__command_type_cache
fi
typeset -ga ZSH_HIGHLIGHT_DIRS_BLACKLIST

View file

@ -0,0 +1,40 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2018 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
mkdir foo
touch foo/bar
BUFFER=": foo/bar $PWD/foo foo/b"
ZSH_HIGHLIGHT_DIRS_BLACKLIST=($PWD/foo)
expected_region_highlight=(
'1 1 builtin' # :
'3 9 path' # foo/bar
"11 $(( 14 + $#PWD )) path" # $PWD/foo
"$(( 16 + $#PWD )) $(( 20 + $#PWD )) default" # foo/b
)