mirror of
https://github.com/zsh-users/zsh-syntax-highlighting.git
synced 2025-04-17 11:35:32 +08:00
Merge 2580a8bd8b
into c969a1f26a
This commit is contained in:
commit
06eb4b14ef
@ -165,6 +165,19 @@ _zsh_highlight_main__type() {
|
|||||||
if (( $+_zsh_highlight_main__command_type_cache )); then
|
if (( $+_zsh_highlight_main__command_type_cache )); then
|
||||||
_zsh_highlight_main__command_type_cache[(e)$1]=$REPLY
|
_zsh_highlight_main__command_type_cache[(e)$1]=$REPLY
|
||||||
fi
|
fi
|
||||||
|
[[ -n $REPLY ]]
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
# Checks whether $1 is something that can be run.
|
||||||
|
#
|
||||||
|
# Return 0 if runnable, 1 if not runnable, 2 if trouble.
|
||||||
|
_zsh_highlight_main__is_runnable() {
|
||||||
|
if _zsh_highlight_main__type "$1"; then
|
||||||
|
[[ $REPLY != none ]]
|
||||||
|
else
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check whether the first argument is a redirection operator token.
|
# Check whether the first argument is a redirection operator token.
|
||||||
@ -220,10 +233,9 @@ _zsh_highlight_highlighter_main_paint()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
## Variable declarations and initializations
|
## Variable declarations and initializations
|
||||||
local start_pos=0 end_pos highlight_glob=true arg style
|
local start_pos=0 end_pos highlight_glob=true arg arg_raw style
|
||||||
local in_array_assignment=false # true between 'a=(' and the matching ')'
|
local in_array_assignment=false # true between 'a=(' and the matching ')'
|
||||||
typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR
|
typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR
|
||||||
typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS
|
|
||||||
typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW
|
typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW
|
||||||
local -a options_to_set # used in callees
|
local -a options_to_set # used in callees
|
||||||
local buf="$PREBUFFER$BUFFER"
|
local buf="$PREBUFFER$BUFFER"
|
||||||
@ -239,6 +251,30 @@ _zsh_highlight_highlighter_main_paint()
|
|||||||
# ":" for 'then'
|
# ":" for 'then'
|
||||||
local braces_stack
|
local braces_stack
|
||||||
|
|
||||||
|
# $flags_with_argument is a set of letters, corresponding to the option letters
|
||||||
|
# that would be followed by a colon in a getopts specification.
|
||||||
|
local flags_with_argument
|
||||||
|
# $flags_sans_argument is a set of letters, corresponding to the option letters
|
||||||
|
# that wouldn't be followed by a colon in a getopts specification.
|
||||||
|
local flags_sans_argument
|
||||||
|
# $precommand_options maps precommand name to values of $flags_with_argument and
|
||||||
|
# $flags_sans_argument for that precommand, joined by a colon.
|
||||||
|
#
|
||||||
|
# Currently, setting $flags_sans_argument is only important for commands that
|
||||||
|
# have a non-empty $flags_with_argument; see test-data/precommand4.zsh.
|
||||||
|
local -A precommand_options
|
||||||
|
precommand_options=(
|
||||||
|
'command' :pvV # as of zsh 5.4.2
|
||||||
|
'nice' n # as of current POSIX spec
|
||||||
|
'sudo' Cgprtu:AEHKPSVbhiklnsv # as of sudo 1.8.21p2
|
||||||
|
'doas' aCu:Lns # as of OpenBSD's doas(1) dated September 4, 2016
|
||||||
|
'builtin' '' # as of zsh 5.4.2
|
||||||
|
'exec' a:cl # as of zsh 5.4.2
|
||||||
|
'nocorrect' '' # as of zsh 5.4.2
|
||||||
|
'noglob' '' # as of zsh 5.4.2
|
||||||
|
'pkexec' '' # doesn't take short options; immune to #121 because it's usually not passed --option flags
|
||||||
|
)
|
||||||
|
|
||||||
if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then
|
if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then
|
||||||
local right_brace_is_recognised_everywhere=false
|
local right_brace_is_recognised_everywhere=false
|
||||||
else
|
else
|
||||||
@ -256,10 +292,6 @@ _zsh_highlight_highlighter_main_paint()
|
|||||||
# ### 'case' syntax, but followed by a pattern, not by a command
|
# ### 'case' syntax, but followed by a pattern, not by a command
|
||||||
# ';;' ';&' ';|'
|
# ';;' ';&' ';|'
|
||||||
)
|
)
|
||||||
ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=(
|
|
||||||
'builtin' 'command' 'exec' 'nocorrect' 'noglob'
|
|
||||||
'pkexec' # immune to #121 because it's usually not passed --option flags
|
|
||||||
)
|
|
||||||
|
|
||||||
# Tokens that, at (naively-determined) "command position", are followed by
|
# Tokens that, at (naively-determined) "command position", are followed by
|
||||||
# a de jure command position. All of these are reserved words.
|
# a de jure command position. All of these are reserved words.
|
||||||
@ -285,8 +317,9 @@ _zsh_highlight_highlighter_main_paint()
|
|||||||
#
|
#
|
||||||
# The states are:
|
# The states are:
|
||||||
# - :start: Command word
|
# - :start: Command word
|
||||||
# - :sudo_opt: A leading-dash option to sudo (such as "-u" or "-i")
|
# - :sudo_opt: A leading-dash option to a precommand, whether it takes an
|
||||||
# - :sudo_arg: The argument to a sudo leading-dash option that takes one,
|
# argument or not. (Example: sudo's "-u" or "-i".)
|
||||||
|
# - :sudo_arg: The argument to a precommand's leading-dash option,
|
||||||
# when given as a separate word; i.e., "foo" in "-u foo" (two
|
# when given as a separate word; i.e., "foo" in "-u foo" (two
|
||||||
# words) but not in "-ufoo" (one word).
|
# words) but not in "-ufoo" (one word).
|
||||||
# - :regular: "Not a command word", and command delimiters are permitted.
|
# - :regular: "Not a command word", and command delimiters are permitted.
|
||||||
@ -328,6 +361,9 @@ _zsh_highlight_highlighter_main_paint()
|
|||||||
args=(${(z)buf})
|
args=(${(z)buf})
|
||||||
fi
|
fi
|
||||||
for arg in $args; do
|
for arg in $args; do
|
||||||
|
# Save an unmunged copy of the current word.
|
||||||
|
arg_raw="$arg"
|
||||||
|
|
||||||
# Initialize $next_word.
|
# Initialize $next_word.
|
||||||
if (( in_redirection )); then
|
if (( in_redirection )); then
|
||||||
(( --in_redirection ))
|
(( --in_redirection ))
|
||||||
@ -438,6 +474,65 @@ _zsh_highlight_highlighter_main_paint()
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Expand aliases.
|
||||||
|
# TODO: this should be done iteratively, e.g., 'alias x=y y=z z=w\n x'
|
||||||
|
# And then the entire 'alias' branch of the 'case' statement should
|
||||||
|
# be done here.
|
||||||
|
# TODO: path expansion should happen _after_ alias expansion
|
||||||
|
_zsh_highlight_main_highlighter_expand_path $arg
|
||||||
|
_zsh_highlight_main__type "$REPLY"
|
||||||
|
local res="$REPLY"
|
||||||
|
if [[ $res == "alias" ]]; then
|
||||||
|
_zsh_highlight_main__resolve_alias $arg
|
||||||
|
() {
|
||||||
|
# Use a temporary array to ensure the subscript is interpreted as
|
||||||
|
# an array subscript, not as a scalar subscript
|
||||||
|
local -a reply
|
||||||
|
# TODO: the ${interactive_comments+set} path needs to skip comments; see test-data/alias-comment1.zsh
|
||||||
|
reply=( ${interactive_comments-${(z)REPLY}}
|
||||||
|
${interactive_comments+${(zZ+c+)REPLY}} )
|
||||||
|
arg=$reply[1]
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Expand parameters.
|
||||||
|
#
|
||||||
|
# ### For now, expand just '$foo' or '${foo}', possibly with braces, but with
|
||||||
|
# ### no other features of the parameter expansion syntax. (No ${(x)foo},
|
||||||
|
# ### no ${foo[x]}, no ${foo:-x}.)
|
||||||
|
() {
|
||||||
|
# That's not entirely correct --- if the parameter's value happens to be a reserved
|
||||||
|
# word, the parameter expansion will be highlighted as a reserved word --- but that
|
||||||
|
# incorrectness is outweighed by the usability improvement of permitting the use of
|
||||||
|
# parameters that refer to commands, functions, and builtins.
|
||||||
|
local -a match mbegin mend
|
||||||
|
local MATCH; integer MBEGIN MEND
|
||||||
|
local parameter_name
|
||||||
|
if [[ $arg[1] == '$' ]] && [[ ${arg[2]} == '{' ]] && [[ ${arg[-1]} == '}' ]]; then
|
||||||
|
parameter_name=${${arg:2}%?}
|
||||||
|
elif [[ $arg[1] == '$' ]]; then
|
||||||
|
parameter_name=${arg:1}
|
||||||
|
fi
|
||||||
|
if [[ $res == none ]] && zmodload -e zsh/parameter &&
|
||||||
|
[[ ${parameter_name} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]] &&
|
||||||
|
(( ${+parameters[${MATCH}]} ))
|
||||||
|
then
|
||||||
|
# Set $arg.
|
||||||
|
case ${(tP)MATCH} in
|
||||||
|
(*array*|*assoc*)
|
||||||
|
local -a words=( ${(P)MATCH} )
|
||||||
|
arg=${words[1]}
|
||||||
|
;;
|
||||||
|
(*)
|
||||||
|
# scalar, presumably
|
||||||
|
arg=${(P)MATCH}
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
_zsh_highlight_main__type "$arg"
|
||||||
|
res=$REPLY
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Special-case the first word after 'sudo'.
|
# Special-case the first word after 'sudo'.
|
||||||
if (( ! in_redirection )); then
|
if (( ! in_redirection )); then
|
||||||
if [[ $this_word == *':sudo_opt:'* ]] && [[ $arg != -* ]]; then
|
if [[ $this_word == *':sudo_opt:'* ]] && [[ $arg != -* ]]; then
|
||||||
@ -448,16 +543,23 @@ _zsh_highlight_highlighter_main_paint()
|
|||||||
# Parse the sudo command line
|
# Parse the sudo command line
|
||||||
if (( ! in_redirection )); then
|
if (( ! in_redirection )); then
|
||||||
if [[ $this_word == *':sudo_opt:'* ]]; then
|
if [[ $this_word == *':sudo_opt:'* ]]; then
|
||||||
case "$arg" in
|
if [[ -n $flags_with_argument ]] &&
|
||||||
|
[[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument] ]]; then
|
||||||
# Flag that requires an argument
|
# Flag that requires an argument
|
||||||
'-'[Cgprtu]) this_word=${this_word//:start:/};
|
this_word=${this_word//:start:/}
|
||||||
next_word=':sudo_arg:';;
|
next_word=':sudo_arg:'
|
||||||
|
elif [[ $arg == '-'* ]]; then
|
||||||
|
# Flag that requires no argument, or unknown flag.
|
||||||
# This prevents misbehavior with sudo -u -otherargument
|
# This prevents misbehavior with sudo -u -otherargument
|
||||||
'-'*) this_word=${this_word//:start:/};
|
this_word=${this_word//:start:/}
|
||||||
next_word+=':start:';
|
next_word+=':start:'
|
||||||
next_word+=':sudo_opt:';;
|
next_word+=':sudo_opt:'
|
||||||
*) ;;
|
else
|
||||||
esac
|
# Not an option flag; nothing to do. (If the command line is
|
||||||
|
# syntactically valid, ${this_word//:sudo_opt:/} should be
|
||||||
|
# non-empty now.)
|
||||||
|
this_word=${this_word//:sudo_opt:/}
|
||||||
|
fi
|
||||||
elif [[ $this_word == *':sudo_arg:'* ]]; then
|
elif [[ $this_word == *':sudo_arg:'* ]]; then
|
||||||
next_word+=':sudo_opt:'
|
next_word+=':sudo_opt:'
|
||||||
next_word+=':start:'
|
next_word+=':start:'
|
||||||
@ -470,35 +572,14 @@ _zsh_highlight_highlighter_main_paint()
|
|||||||
style=reserved-word # de facto a reserved word, although not de jure
|
style=reserved-word # de facto a reserved word, although not de jure
|
||||||
next_word=':start:'
|
next_word=':start:'
|
||||||
elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word
|
elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word
|
||||||
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then
|
if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg; then
|
||||||
style=precommand
|
|
||||||
elif [[ "$arg" = "sudo" ]] && { _zsh_highlight_main__type sudo; [[ -n $REPLY && $REPLY != "none" ]] }; then
|
|
||||||
style=precommand
|
style=precommand
|
||||||
|
flags_with_argument=${precommand_options[$arg]%:*}
|
||||||
|
flags_sans_argument=${precommand_options[$arg]#*:}
|
||||||
next_word=${next_word//:regular:/}
|
next_word=${next_word//:regular:/}
|
||||||
next_word+=':sudo_opt:'
|
next_word+=':sudo_opt:'
|
||||||
next_word+=':start:'
|
next_word+=':start:'
|
||||||
else
|
else
|
||||||
_zsh_highlight_main_highlighter_expand_path $arg
|
|
||||||
local expanded_arg="$REPLY"
|
|
||||||
_zsh_highlight_main__type ${expanded_arg}
|
|
||||||
local res="$REPLY"
|
|
||||||
() {
|
|
||||||
# Special-case: command word is '$foo', like that, without braces or anything.
|
|
||||||
#
|
|
||||||
# That's not entirely correct --- if the parameter's value happens to be a reserved
|
|
||||||
# word, the parameter expansion will be highlighted as a reserved word --- but that
|
|
||||||
# incorrectness is outweighed by the usability improvement of permitting the use of
|
|
||||||
# parameters that refer to commands, functions, and builtins.
|
|
||||||
local -a match mbegin mend
|
|
||||||
local MATCH; integer MBEGIN MEND
|
|
||||||
if [[ $res == none ]] && (( ${+parameters} )) &&
|
|
||||||
[[ ${arg[1]} == \$ ]] && [[ ${arg:1} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]] &&
|
|
||||||
(( ${+parameters[${MATCH}]} ))
|
|
||||||
then
|
|
||||||
_zsh_highlight_main__type ${(P)MATCH}
|
|
||||||
res=$REPLY
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
case $res in
|
case $res in
|
||||||
reserved) # reserved word
|
reserved) # reserved word
|
||||||
style=reserved-word
|
style=reserved-word
|
||||||
@ -554,8 +635,9 @@ _zsh_highlight_highlighter_main_paint()
|
|||||||
;;
|
;;
|
||||||
'suffix alias') style=suffix-alias;;
|
'suffix alias') style=suffix-alias;;
|
||||||
alias) () {
|
alias) () {
|
||||||
|
# Make sure to use $arg_raw here, rather than $arg.
|
||||||
integer insane_alias
|
integer insane_alias
|
||||||
case $arg in
|
case $arg_raw in
|
||||||
# Issue #263: aliases with '=' on their LHS.
|
# Issue #263: aliases with '=' on their LHS.
|
||||||
#
|
#
|
||||||
# There are three cases:
|
# There are three cases:
|
||||||
@ -569,12 +651,15 @@ _zsh_highlight_highlighter_main_paint()
|
|||||||
esac
|
esac
|
||||||
if (( insane_alias )); then
|
if (( insane_alias )); then
|
||||||
style=unknown-token
|
style=unknown-token
|
||||||
|
# Calling 'type' again; since __type memoizes the answer, this call is just a hash lookup.
|
||||||
|
elif _zsh_highlight_main__type "$arg" && [[ $REPLY == 'none' ]]; then
|
||||||
|
style=unknown-token
|
||||||
else
|
else
|
||||||
# The common case.
|
# The common case.
|
||||||
style=alias
|
style=alias
|
||||||
_zsh_highlight_main__resolve_alias $arg
|
if (( ${+precommand_options[(re)"$arg"]} )) && (( ! ${+precommand_options[(re)"$arg_raw"]} )); then
|
||||||
local alias_target="$REPLY"
|
precommand_options[$arg_raw]=$precommand_options[$arg]
|
||||||
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$alias_target"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg)
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
;;
|
;;
|
||||||
@ -714,8 +799,7 @@ _zsh_highlight_highlighter_main_paint()
|
|||||||
highlight_glob=true
|
highlight_glob=true
|
||||||
fi
|
fi
|
||||||
elif
|
elif
|
||||||
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:'* ]] ||
|
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:'* ]]; then
|
||||||
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:'* ]]; then
|
|
||||||
next_word=':start:'
|
next_word=':start:'
|
||||||
elif [[ $arg == "repeat" && $this_word == *':start:'* ]]; then
|
elif [[ $arg == "repeat" && $this_word == *':start:'* ]]; then
|
||||||
# skip the repeat-count word
|
# skip the repeat-count word
|
||||||
|
37
highlighters/main/test-data/alias-comment1.zsh
Normal file
37
highlighters/main/test-data/alias-comment1.zsh
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2016 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# see alias-comment2.zsh
|
||||||
|
setopt interactivecomments
|
||||||
|
alias x=$'# foo\npwd'
|
||||||
|
BUFFER='x'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"1 1 alias 'interactivecomments applies to aliases'" # x becomes pwd
|
||||||
|
)
|
37
highlighters/main/test-data/alias-comment2.zsh
Normal file
37
highlighters/main/test-data/alias-comment2.zsh
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2016 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# see alias-comment1.zsh
|
||||||
|
setopt NO_interactivecomments
|
||||||
|
alias x=$'# foo\npwd'
|
||||||
|
BUFFER='x'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"1 1 unknown-token" # x becomes #
|
||||||
|
)
|
@ -28,9 +28,13 @@
|
|||||||
# -------------------------------------------------------------------------------------------------
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
local x=/usr/bin/env
|
local x=/usr/bin/env
|
||||||
BUFFER='$x "argument"'
|
local y=sudo
|
||||||
|
local -a z; z=(zsh -f)
|
||||||
|
BUFFER='$x "argument"; $y; $z'
|
||||||
|
|
||||||
expected_region_highlight=(
|
expected_region_highlight=(
|
||||||
"1 2 command" # $x
|
"1 2 command" # $x
|
||||||
"4 13 double-quoted-argument" # "argument"
|
"4 13 double-quoted-argument" # "argument"
|
||||||
|
"16 17 precommand" # $y (sudo)
|
||||||
|
"20 21 command" # $z - 'zsh' being the command
|
||||||
)
|
)
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
# vim: ft=zsh sw=2 ts=2 et
|
# vim: ft=zsh sw=2 ts=2 et
|
||||||
# -------------------------------------------------------------------------------------------------
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
alias a=A
|
alias a=:
|
||||||
f() {}
|
f() {}
|
||||||
|
|
||||||
BUFFER='a;f;'
|
BUFFER='a;f;'
|
||||||
|
@ -29,9 +29,11 @@
|
|||||||
|
|
||||||
# «/usr» at this point would be highlighted as path_prefix; so should
|
# «/usr» at this point would be highlighted as path_prefix; so should
|
||||||
# a parameter that expands to an equivalent string be highlighted.
|
# a parameter that expands to an equivalent string be highlighted.
|
||||||
|
#
|
||||||
|
# More complicated parameter substitutions aren't eval'd; issue #328.
|
||||||
BUFFER='$PWD; ${PWD}'
|
BUFFER='$PWD; ${PWD}'
|
||||||
|
|
||||||
expected_region_highlight=(
|
expected_region_highlight=(
|
||||||
"1 4 unknown-token" # $PWD - not eval'd; issue #328
|
"1 4 path" # $PWD
|
||||||
"7 12 unknown-token" # ${PWD}
|
"7 12 path" # ${PWD}
|
||||||
)
|
)
|
||||||
|
@ -31,6 +31,6 @@ BUFFER='command -v ls'
|
|||||||
|
|
||||||
expected_region_highlight=(
|
expected_region_highlight=(
|
||||||
"1 7 precommand" # command
|
"1 7 precommand" # command
|
||||||
"9 10 single-hyphen-option 'issue #343'" # -v
|
"9 10 single-hyphen-option" # -v
|
||||||
"12 13 command 'issue #343'" # ls
|
"12 13 command" # ls
|
||||||
)
|
)
|
||||||
|
41
highlighters/main/test-data/precommand3.zsh
Normal file
41
highlighters/main/test-data/precommand3.zsh
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2016 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BUFFER='nice -n10 ls; nice -n 10 ls'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"1 4 precommand" # nice
|
||||||
|
"6 9 single-hyphen-option" # -n10
|
||||||
|
"11 12 command" # ls
|
||||||
|
"13 13 commandseparator" # ;
|
||||||
|
"15 18 precommand" # nice
|
||||||
|
"20 21 single-hyphen-option" # -n
|
||||||
|
"23 24 default" # 10
|
||||||
|
"26 27 command" # ls
|
||||||
|
)
|
39
highlighters/main/test-data/precommand4.zsh
Normal file
39
highlighters/main/test-data/precommand4.zsh
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
doas(){}
|
||||||
|
BUFFER=$'doas -nu phy1729 ls'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
'1 4 precommand' # doas
|
||||||
|
'6 8 single-hyphen-option' # -nu
|
||||||
|
'10 16 default' # phy1729
|
||||||
|
'18 19 command' # ls
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user