mirror of
				https://github.com/zsh-users/zsh-syntax-highlighting.git
				synced 2025-10-30 15:56:28 +08:00 
			
		
		
		
	Merge 8825fb4d73 into 1715f39a46
				
					
				
			This commit is contained in:
		
						commit
						e190b4291b
					
				
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										41
									
								
								highlighters/main/test-data/hashed-command-ambiguous.zsh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								highlighters/main/test-data/hashed-command-ambiguous.zsh
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,41 @@
 | 
			
		||||
# -------------------------------------------------------------------------------------------------
 | 
			
		||||
# Copyright (c) 2015 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
 | 
			
		||||
# -------------------------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
hash sh=/bin/sh
 | 
			
		||||
BUFFER='sh'
 | 
			
		||||
 | 
			
		||||
if zmodload -e zsh/parameter; then
 | 
			
		||||
  expected_region_highlight=(
 | 
			
		||||
    "1 2 hashed-command 'hashed command found in PATH classified as plain command'"
 | 
			
		||||
  )
 | 
			
		||||
else
 | 
			
		||||
  expected_region_highlight=(
 | 
			
		||||
    "1 2 hashed-command"
 | 
			
		||||
  )
 | 
			
		||||
fi
 | 
			
		||||
							
								
								
									
										46
									
								
								highlighters/main/test-data/hashed-command-relative.zsh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								highlighters/main/test-data/hashed-command-relative.zsh
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,46 @@
 | 
			
		||||
# -------------------------------------------------------------------------------------------------
 | 
			
		||||
# Copyright (c) 2020 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
 | 
			
		||||
# -------------------------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
if [[ $OSTYPE == msys ]]; then
 | 
			
		||||
  skip_test='Cannot chmod +x in msys2'
 | 
			
		||||
else
 | 
			
		||||
  mkdir foo
 | 
			
		||||
  print >foo/bar
 | 
			
		||||
  chmod +x foo/bar
 | 
			
		||||
  hash zsyh-hashed-command=foo/bar
 | 
			
		||||
  hash subdir/zsyh-hashed-command=foo/bar
 | 
			
		||||
 | 
			
		||||
  BUFFER='zsyh-hashed-command; subdir/zsyh-hashed-command'
 | 
			
		||||
 | 
			
		||||
  expected_region_highlight=(
 | 
			
		||||
    "1 19 hashed-command"
 | 
			
		||||
    "20 20 commandseparator"
 | 
			
		||||
    "22 47 unknown-token"
 | 
			
		||||
  )
 | 
			
		||||
fi
 | 
			
		||||
							
								
								
									
										35
									
								
								highlighters/main/test-data/hashed-command-valid.zsh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								highlighters/main/test-data/hashed-command-valid.zsh
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,35 @@
 | 
			
		||||
# -------------------------------------------------------------------------------------------------
 | 
			
		||||
# Copyright (c) 2015 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
 | 
			
		||||
# -------------------------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
hash zsh_syntax_highlighting_hash=/usr/bin/env
 | 
			
		||||
BUFFER='zsh_syntax_highlighting_hash'
 | 
			
		||||
 | 
			
		||||
expected_region_highlight=(
 | 
			
		||||
  "1 28 hashed-command"
 | 
			
		||||
)
 | 
			
		||||
@ -31,5 +31,5 @@ hash zsh_syntax_highlighting_hash=/doesnotexist
 | 
			
		||||
BUFFER='zsh_syntax_highlighting_hash'
 | 
			
		||||
 | 
			
		||||
expected_region_highlight=(
 | 
			
		||||
  "1 28 hashed-command 'zsh/parameter cannot distinguish between hashed and command'"
 | 
			
		||||
  "1 28 unknown-token"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										44
									
								
								highlighters/main/test-data/new-command.zsh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								highlighters/main/test-data/new-command.zsh
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,44 @@
 | 
			
		||||
# -------------------------------------------------------------------------------------------------
 | 
			
		||||
# Copyright (c) 2020 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
 | 
			
		||||
# -------------------------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
if [[ $OSTYPE == msys ]]; then
 | 
			
		||||
  skip_test='Cannot chmod +x in msys2'
 | 
			
		||||
else
 | 
			
		||||
  path+=($PWD/foo)
 | 
			
		||||
  : $+commands[zsyh-new-command]
 | 
			
		||||
  mkdir foo
 | 
			
		||||
  print >foo/zsyh-new-command
 | 
			
		||||
  chmod +x foo/zsyh-new-command
 | 
			
		||||
 | 
			
		||||
  BUFFER='zsyh-new-command'
 | 
			
		||||
 | 
			
		||||
  expected_region_highlight=(
 | 
			
		||||
    "1 16 command"
 | 
			
		||||
  )
 | 
			
		||||
fi
 | 
			
		||||
							
								
								
									
										39
									
								
								highlighters/main/test-data/no-rehash.zsh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								highlighters/main/test-data/no-rehash.zsh
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,39 @@
 | 
			
		||||
# -------------------------------------------------------------------------------------------------
 | 
			
		||||
# Copyright (c) 2020 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
 | 
			
		||||
# -------------------------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
hash zsyh-hashed-command=/usr/bin/env
 | 
			
		||||
BUFFER='doesnotexist; zsyh-hashed-command'
 | 
			
		||||
 | 
			
		||||
# Test that highlighting "doesnotexist" does not invoke the "rehash" builtin,
 | 
			
		||||
# which would delete hashed commands (such as "zsyh-hashed-command").
 | 
			
		||||
expected_region_highlight=(
 | 
			
		||||
  "1 12 unknown-token"     # doesnotexist
 | 
			
		||||
  "13 13 commandseparator" # ;
 | 
			
		||||
  "15 33 hashed-command"   # zsyh-hashed-command
 | 
			
		||||
)
 | 
			
		||||
@ -28,7 +28,7 @@
 | 
			
		||||
# vim: ft=zsh sw=2 ts=2 et
 | 
			
		||||
# -------------------------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
hash sudo=false
 | 
			
		||||
hash sudo=/usr/bin/env
 | 
			
		||||
touch foo
 | 
			
		||||
 | 
			
		||||
BUFFER='sudo -e ./foo'
 | 
			
		||||
 | 
			
		||||
@ -28,7 +28,7 @@
 | 
			
		||||
# vim: ft=zsh sw=2 ts=2 et
 | 
			
		||||
# -------------------------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
hash sudo=false
 | 
			
		||||
hash sudo=/usr/bin/env
 | 
			
		||||
 | 
			
		||||
BUFFER='sudo -e /does/not/exist'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										45
									
								
								highlighters/main/test-data/removed-command.zsh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								highlighters/main/test-data/removed-command.zsh
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,45 @@
 | 
			
		||||
# -------------------------------------------------------------------------------------------------
 | 
			
		||||
# Copyright (c) 2020 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
 | 
			
		||||
# -------------------------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
if [[ $OSTYPE == msys ]]; then
 | 
			
		||||
  skip_test='Cannot chmod +x in msys2'
 | 
			
		||||
else
 | 
			
		||||
  mkdir foo
 | 
			
		||||
  print >foo/zsyh-new-command
 | 
			
		||||
  chmod +x foo/zsyh-new-command
 | 
			
		||||
  path+=($PWD/foo)
 | 
			
		||||
  : $+commands[zsyh-new-command]
 | 
			
		||||
  rm foo/zsyh-new-command
 | 
			
		||||
 | 
			
		||||
  BUFFER='zsyh-new-command'
 | 
			
		||||
 | 
			
		||||
  expected_region_highlight=(
 | 
			
		||||
    "1 16 unknown-token"
 | 
			
		||||
  )
 | 
			
		||||
fi
 | 
			
		||||
@ -28,7 +28,7 @@
 | 
			
		||||
# vim: ft=zsh sw=2 ts=2 et
 | 
			
		||||
# -------------------------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
hash sudo='false'
 | 
			
		||||
hash sudo=/usr/bin/env
 | 
			
		||||
BUFFER='sudo --askpass ls'
 | 
			
		||||
 | 
			
		||||
expected_region_highlight=(
 | 
			
		||||
 | 
			
		||||
@ -91,6 +91,11 @@ _zsh_highlight_add_highlight()
 | 
			
		||||
  region_highlight+=("$1 $2 $3")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
_zsh_highlight_main_calculate_styles()
 | 
			
		||||
{
 | 
			
		||||
  # Do nothing
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Activate the highlighter.
 | 
			
		||||
ZSH_HIGHLIGHT_HIGHLIGHTERS=($1)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -173,26 +173,48 @@ _zsh_highlight()
 | 
			
		||||
    region_highlight[-1]=()
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  # Reset region_highlight to build it from scratch
 | 
			
		||||
  if (( zsh_highlight__memo_feature )); then
 | 
			
		||||
    region_highlight=( "${(@)region_highlight:#*memo=zsh-syntax-highlighting*}" )
 | 
			
		||||
  else
 | 
			
		||||
    # Legacy codepath.  Not very interoperable with other plugins (issue #418).
 | 
			
		||||
    region_highlight=()
 | 
			
		||||
  fi
 | 
			
		||||
 | 
			
		||||
  # Remove all highlighting in isearch, so that only the underlining done by zsh itself remains.
 | 
			
		||||
  # For details see FAQ entry 'Why does syntax highlighting not work while searching history?'.
 | 
			
		||||
  # This disables highlighting during isearch (for reasons explained in README.md) unless zsh is new enough
 | 
			
		||||
  # and doesn't have the pattern matching bug
 | 
			
		||||
  if [[ $WIDGET == zle-isearch-update ]] && { $zsh_highlight__pat_static_bug || ! (( $+ISEARCHMATCH_ACTIVE )) }; then
 | 
			
		||||
  if [[ $WIDGET == zle-isearch-update ]] && { $zsh_highlight__pat_static_bug || ! (( $+ISEARCHMATCH_ACTIVE )) } ||
 | 
			
		||||
      # Do not highlight if there are more than 300 chars in the buffer. It's most
 | 
			
		||||
      # likely a pasted command or a huge list of files in that case..
 | 
			
		||||
      [[ -n ${ZSH_HIGHLIGHT_MAXLENGTH:-} ]] && (( ${#BUFFER} > ZSH_HIGHLIGHT_MAXLENGTH )) ||
 | 
			
		||||
      # Do not highlight if there are pending inputs (copy/paste).
 | 
			
		||||
      (( PENDING )); then
 | 
			
		||||
    # Reset region_highlight to build it from scratch
 | 
			
		||||
    if (( zsh_highlight__memo_feature )); then
 | 
			
		||||
      region_highlight=( "${(@)region_highlight:#*memo=zsh-syntax-highlighting*}" )
 | 
			
		||||
    else
 | 
			
		||||
      # Legacy codepath.  Not very interoperable with other plugins (issue #418).
 | 
			
		||||
      region_highlight=()
 | 
			
		||||
    fi
 | 
			
		||||
    return $ret
 | 
			
		||||
  fi
 | 
			
		||||
 | 
			
		||||
  # Before we 'emulate -L', save the user's options
 | 
			
		||||
  local -A zsyh_user_options
 | 
			
		||||
  if zmodload -e zsh/parameter; then
 | 
			
		||||
    zsyh_user_options=("${(kv)options[@]}")
 | 
			
		||||
    if [[ -n ${ZSH_HIGHLIGHT_HIGHLIGHTERS:#(brackets|cursor|line|main|pattern|regexp|root)} ]]; then
 | 
			
		||||
      # Copy all options if there are user-defined highlighters
 | 
			
		||||
      zsyh_user_options=("${(kv)options[@]}")
 | 
			
		||||
    else
 | 
			
		||||
      # Copy a subset of options used by the bundled highlighters.  This is faster than
 | 
			
		||||
      # copying all options.
 | 
			
		||||
      zsyh_user_options=(
 | 
			
		||||
        ignorebraces        "${options[ignorebraces]}"
 | 
			
		||||
        ignoreclosebraces   "${options[ignoreclosebraces]-off}"
 | 
			
		||||
        pathdirs            "${options[pathdirs]}"
 | 
			
		||||
        interactivecomments "${options[interactivecomments]}"
 | 
			
		||||
        globassign          "${options[globassign]}"
 | 
			
		||||
        multifuncdef        "${options[multifuncdef]}"
 | 
			
		||||
        autocd              "${options[autocd]}"
 | 
			
		||||
        equals              "${options[equals]}"
 | 
			
		||||
        multios             "${options[multios]}"
 | 
			
		||||
        rcquotes            "${options[rcquotes]}"
 | 
			
		||||
      )
 | 
			
		||||
    fi
 | 
			
		||||
  else
 | 
			
		||||
    local canonical_options onoff option raw_options
 | 
			
		||||
    raw_options=(${(f)"$(emulate -R zsh; set -o)"})
 | 
			
		||||
@ -210,20 +232,17 @@ _zsh_highlight()
 | 
			
		||||
  fi
 | 
			
		||||
  typeset -r zsyh_user_options
 | 
			
		||||
 | 
			
		||||
  local -a new_highlight
 | 
			
		||||
  if (( zsh_highlight__memo_feature )); then
 | 
			
		||||
    new_highlight=( "${(@)region_highlight:#*memo=zsh-syntax-highlighting*}" )
 | 
			
		||||
  fi
 | 
			
		||||
 | 
			
		||||
  emulate -L zsh
 | 
			
		||||
  setopt localoptions warncreateglobal nobashrematch
 | 
			
		||||
  setopt warncreateglobal nobashrematch
 | 
			
		||||
  local REPLY # don't leak $REPLY into global scope
 | 
			
		||||
 | 
			
		||||
  # Do not highlight if there are more than 300 chars in the buffer. It's most
 | 
			
		||||
  # likely a pasted command or a huge list of files in that case..
 | 
			
		||||
  [[ -n ${ZSH_HIGHLIGHT_MAXLENGTH:-} ]] && [[ $#BUFFER -gt $ZSH_HIGHLIGHT_MAXLENGTH ]] && return $ret
 | 
			
		||||
 | 
			
		||||
  # Do not highlight if there are pending inputs (copy/paste).
 | 
			
		||||
  [[ $PENDING -gt 0 ]] && return $ret
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
    local cache_place
 | 
			
		||||
    local -a region_highlight_copy
 | 
			
		||||
    local cache_place pred
 | 
			
		||||
 | 
			
		||||
    # Select which highlighters in ZSH_HIGHLIGHT_HIGHLIGHTERS need to be invoked.
 | 
			
		||||
    local highlighter; for highlighter in $ZSH_HIGHLIGHT_HIGHLIGHTERS; do
 | 
			
		||||
@ -233,38 +252,37 @@ _zsh_highlight()
 | 
			
		||||
      typeset -ga ${cache_place}
 | 
			
		||||
 | 
			
		||||
      # If highlighter needs to be invoked
 | 
			
		||||
      if ! type "_zsh_highlight_highlighter_${highlighter}_predicate" >&/dev/null; then
 | 
			
		||||
        echo "zsh-syntax-highlighting: warning: disabling the ${(qq)highlighter} highlighter as it has not been loaded" >&2
 | 
			
		||||
        # TODO: use ${(b)} rather than ${(q)} if supported
 | 
			
		||||
        ZSH_HIGHLIGHT_HIGHLIGHTERS=( ${ZSH_HIGHLIGHT_HIGHLIGHTERS:#${highlighter}} )
 | 
			
		||||
      elif "_zsh_highlight_highlighter_${highlighter}_predicate"; then
 | 
			
		||||
 | 
			
		||||
        # save a copy, and cleanup region_highlight
 | 
			
		||||
        region_highlight_copy=("${region_highlight[@]}")
 | 
			
		||||
        region_highlight=()
 | 
			
		||||
 | 
			
		||||
        # Execute highlighter and save result
 | 
			
		||||
        {
 | 
			
		||||
          "_zsh_highlight_highlighter_${highlighter}_paint"
 | 
			
		||||
        } always {
 | 
			
		||||
          : ${(AP)cache_place::="${region_highlight[@]}"}
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        # Restore saved region_highlight
 | 
			
		||||
        region_highlight=("${region_highlight_copy[@]}")
 | 
			
		||||
 | 
			
		||||
      pred="_zsh_highlight_highlighter_${highlighter}_predicate"
 | 
			
		||||
      if (( ! $pred )); then
 | 
			
		||||
        if type $pred >&/dev/null; then
 | 
			
		||||
          typeset -gri $pred=1
 | 
			
		||||
        else
 | 
			
		||||
          echo "zsh-syntax-highlighting: warning: disabling the ${(qq)highlighter} highlighter as it has not been loaded" >&2
 | 
			
		||||
          # TODO: use ${(b)} rather than ${(q)} if supported
 | 
			
		||||
          ZSH_HIGHLIGHT_HIGHLIGHTERS=( ${ZSH_HIGHLIGHT_HIGHLIGHTERS:#${highlighter}} )
 | 
			
		||||
          continue
 | 
			
		||||
        fi
 | 
			
		||||
      fi
 | 
			
		||||
 | 
			
		||||
      # Use value form cache if any cached
 | 
			
		||||
      region_highlight+=("${(@P)cache_place}")
 | 
			
		||||
      if $pred; then
 | 
			
		||||
        # Execute highlighter and save result
 | 
			
		||||
        region_highlight=()
 | 
			
		||||
        "_zsh_highlight_highlighter_${highlighter}_paint"
 | 
			
		||||
        : ${(AP)cache_place::="${region_highlight[@]}"}
 | 
			
		||||
        new_highlight+=($region_highlight)
 | 
			
		||||
      else
 | 
			
		||||
        # Use value form cache if any cached
 | 
			
		||||
        new_highlight+=("${(@P)cache_place}")
 | 
			
		||||
      fi
 | 
			
		||||
 | 
			
		||||
    done
 | 
			
		||||
 | 
			
		||||
    region_highlight=($new_highlight)
 | 
			
		||||
 | 
			
		||||
    # Re-apply zle_highlight settings
 | 
			
		||||
 | 
			
		||||
    # region
 | 
			
		||||
    () {
 | 
			
		||||
      (( REGION_ACTIVE )) || return
 | 
			
		||||
    (( REGION_ACTIVE )) && () {
 | 
			
		||||
      integer min max
 | 
			
		||||
      if (( MARK > CURSOR )) ; then
 | 
			
		||||
        min=$CURSOR max=$MARK
 | 
			
		||||
@ -284,13 +302,13 @@ _zsh_highlight()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    # yank / paste (zsh-5.1.1 and newer)
 | 
			
		||||
    (( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END"
 | 
			
		||||
    (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END"
 | 
			
		||||
 | 
			
		||||
    # isearch
 | 
			
		||||
    (( $+ISEARCHMATCH_ACTIVE )) && (( ISEARCHMATCH_ACTIVE )) && _zsh_highlight_apply_zle_highlight isearch underline "$ISEARCHMATCH_START" "$ISEARCHMATCH_END"
 | 
			
		||||
    (( ISEARCHMATCH_ACTIVE )) && _zsh_highlight_apply_zle_highlight isearch underline "$ISEARCHMATCH_START" "$ISEARCHMATCH_END"
 | 
			
		||||
 | 
			
		||||
    # suffix
 | 
			
		||||
    (( $+SUFFIX_ACTIVE )) && (( SUFFIX_ACTIVE )) && _zsh_highlight_apply_zle_highlight suffix bold "$SUFFIX_START" "$SUFFIX_END"
 | 
			
		||||
    (( SUFFIX_ACTIVE )) && _zsh_highlight_apply_zle_highlight suffix bold "$SUFFIX_START" "$SUFFIX_END"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    return $ret
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user