-
Notifications
You must be signed in to change notification settings - Fork 1.3k
word after "alias ssc='sudo systemctl'; ssc " displayed as error #552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Currently only the first word of the alias's expansion is used. Fixing this in full generality is probably non-trivial, because @blueyed Feel free to join IRC too. |
I understand that it uses |
z-sy-h doesn't use completion. That'd be a great thing to do (it would allow highlighting whole new classes of usage errors), but right now, z-sy-h simply parses $PREBUFFER$BUFFER by itself, using ${(z)}. What the internals do is resolve the alias, look at the first word in the alias to decide what it is, and throw away the rest. Historically, it is this way because the alias is resolve inside the 'for each word' loop, but now that I look at it, I wonder if the alias resolving code could not throw those away? diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh
index 455c21f..e30e044 100644
--- a/highlighters/main/main-highlighter.zsh
+++ b/highlighters/main/main-highlighter.zsh
@@ -69,6 +69,7 @@ _zsh_highlight_highlighter_main_predicate()
# Helper to deal with tokens crossing line boundaries.
_zsh_highlight_main_add_region_highlight() {
+ (( skip_words == 0 )) || return 0
integer start=$1 end=$2
shift 2
@@ -395,14 +396,19 @@ _zsh_highlight_main_highlighter_highlight_list()
# Processing buffer
local proc_buf="$buf"
local -a args
+ # How many words to skip (these words are the result of alias expansion and are not added to region_highlight)
+ integer skip_words=0
if [[ $zsyh_user_options[interactivecomments] == on ]]; then
args=(${(zZ+c+)buf})
else
args=(${(z)buf})
fi
- for arg in $args; do
+ while (( ${+args[1]} )); do
+ arg=$args[1]
+ args=( ${args[2,-1]} )
# Save an unmunged copy of the current word.
arg_raw="$arg"
+ (( skip_words <= 0 )) || (( --skip_words ))
# Initialize this_word and next_word.
if (( in_redirection == 0 )); then
@@ -516,6 +522,8 @@ _zsh_highlight_main_highlighter_highlight_list()
# Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar'
[[ $arg == $reply[1] ]] && break
arg=$reply[1]
+ args[1,0]=( $reply[2,-1] )
+ (( skip_words += $#reply - 1 ))
if (( $+seen_arg[$arg] )); then
res=none
break This actually passes most tests, except for these:
|
This is closer, but still wrong. diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh
index 455c21f..ec0979c 100644
--- a/highlighters/main/main-highlighter.zsh
+++ b/highlighters/main/main-highlighter.zsh
@@ -69,6 +69,7 @@ _zsh_highlight_highlighter_main_predicate()
# Helper to deal with tokens crossing line boundaries.
_zsh_highlight_main_add_region_highlight() {
+ (( skip_words == 0 )) || return 0
integer start=$1 end=$2
shift 2
@@ -395,14 +396,19 @@ _zsh_highlight_main_highlighter_highlight_list()
# Processing buffer
local proc_buf="$buf"
local -a args
+ # How many words to skip (these words are the result of alias expansion and are not added to region_highlight)
+ integer skip_words=0
if [[ $zsyh_user_options[interactivecomments] == on ]]; then
args=(${(zZ+c+)buf})
else
args=(${(z)buf})
fi
- for arg in $args; do
+ while (( ${+args[1]} )); do
+ arg=$args[1]
+ shift args
# Save an unmunged copy of the current word.
arg_raw="$arg"
+ (( skip_words <= 0 )) || (( --skip_words ))
# Initialize this_word and next_word.
if (( in_redirection == 0 )); then
@@ -428,6 +434,7 @@ _zsh_highlight_main_highlighter_highlight_list()
fi
# Compute the new $start_pos and $end_pos, skipping over whitespace in $buf.
+ if (( skip_words == 0 )); then
start_pos=$end_pos
if [[ $arg == ';' ]] ; then
# We're looking for either a semicolon or a newline, whichever comes
@@ -462,6 +469,7 @@ _zsh_highlight_main_highlighter_highlight_list()
((start_pos+=offset))
((end_pos=$start_pos+${#arg}))
fi
+ fi
# Compute the new $proc_buf. We advance it
# (chop off characters from the beginning)
@@ -516,6 +524,8 @@ _zsh_highlight_main_highlighter_highlight_list()
# Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar'
[[ $arg == $reply[1] ]] && break
arg=$reply[1]
+ args[1,0]=( "${(@)reply[2,-1]}" )
+ (( skip_words += $#reply - 1 ))
if (( $+seen_arg[$arg] )); then
res=none
break |
I have an
alias ssc='sudo systemctl'
, and zsh-syntax-highlighting will displaystop
in red withssc stop
.ssc ls
will not display an error, andalias ssc=systemctl
(withoutsudo
) is also fine.Bisected to f3410c5.
The text was updated successfully, but these errors were encountered: