'main': When the redirection operator '>&' or '<&' is followed by a positive integer, do not consider that as a filename; it's always a file descriptor.
Fixes #694.
This commit is contained in:
parent
1024ae8177
commit
fb69f4ca81
@ -35,6 +35,9 @@
|
|||||||
- Fix `cat < *` being highlighting as globbing when the `MULTIOS` option is unset.
|
- Fix `cat < *` being highlighting as globbing when the `MULTIOS` option is unset.
|
||||||
[#583]
|
[#583]
|
||||||
|
|
||||||
|
- Fix `echo >&2` highlighting the `2` as a filename if a file by that name happened to exist
|
||||||
|
[#694]
|
||||||
|
|
||||||
# Changes in version 0.7.1
|
# Changes in version 0.7.1
|
||||||
|
|
||||||
- Remove out-of-date information from the 0.7.0 changelog.
|
- Remove out-of-date information from the 0.7.0 changelog.
|
||||||
|
@ -59,7 +59,8 @@ This highlighter defines the following styles:
|
|||||||
* `redirection` - redirection operators (`<`, `>`, etc)
|
* `redirection` - redirection operators (`<`, `>`, etc)
|
||||||
* `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`)
|
* `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`)
|
||||||
* `comment` - elided parameters in command position (`$x ls` when `$x` is unset or empty)
|
* `comment` - elided parameters in command position (`$x ls` when `$x` is unset or empty)
|
||||||
* `named-fd` - named file descriptor (`echo foo {fd}>&2`)
|
* `named-fd` - named file descriptor (the `fd` in `echo foo {fd}>&2`)
|
||||||
|
* `numeric-fd` - numeric file descriptor (the `2` in `echo foo {fd}>&2`)
|
||||||
* `arg0` - a command word other than one of those enumerated above (other than a command, precommand, alias, function, or shell builtin command).
|
* `arg0` - a command word other than one of those enumerated above (other than a command, precommand, alias, function, or shell builtin command).
|
||||||
* `default` - everything else
|
* `default` - everything else
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@
|
|||||||
: ${ZSH_HIGHLIGHT_STYLES[redirection]:=fg=yellow}
|
: ${ZSH_HIGHLIGHT_STYLES[redirection]:=fg=yellow}
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[comment]:=fg=black,bold}
|
: ${ZSH_HIGHLIGHT_STYLES[comment]:=fg=black,bold}
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[named-fd]:=none}
|
: ${ZSH_HIGHLIGHT_STYLES[named-fd]:=none}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[numeric-fd]:=none}
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[arg0]:=fg=green}
|
: ${ZSH_HIGHLIGHT_STYLES[arg0]:=fg=green}
|
||||||
|
|
||||||
# Whether the highlighter should be called or not.
|
# Whether the highlighter should be called or not.
|
||||||
@ -112,6 +113,10 @@ _zsh_highlight_main_calculate_fallback() {
|
|||||||
hashed-command arg0
|
hashed-command arg0
|
||||||
arg0_\* arg0
|
arg0_\* arg0
|
||||||
|
|
||||||
|
# TODO: Maybe these? —
|
||||||
|
# named-fd file-descriptor
|
||||||
|
# numeric-fd file-descriptor
|
||||||
|
|
||||||
path_prefix path
|
path_prefix path
|
||||||
# The path separator fallback won't ever be used, due to the optimisation
|
# The path separator fallback won't ever be used, due to the optimisation
|
||||||
# in _zsh_highlight_main_highlighter_highlight_path_separators().
|
# in _zsh_highlight_main_highlighter_highlight_path_separators().
|
||||||
@ -1271,10 +1276,14 @@ _zsh_highlight_main_highlighter_highlight_argument()
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg[$1,-1]; then
|
if (( path_eligible )); then
|
||||||
base_style=$REPLY
|
if (( in_redirection )) && [[ $last_arg == *['<>']['&'] && $arg[$1,-1] == <0-> ]]; then
|
||||||
_zsh_highlight_main_highlighter_highlight_path_separators $base_style
|
base_style=numeric-fd
|
||||||
highlights+=($reply)
|
elif _zsh_highlight_main_highlighter_check_path $arg[$1,-1]; then
|
||||||
|
base_style=$REPLY
|
||||||
|
_zsh_highlight_main_highlighter_highlight_path_separators $base_style
|
||||||
|
highlights+=($reply)
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
highlights=($(( start_pos + $1 - 1 )) $end_pos $base_style $highlights)
|
highlights=($(( start_pos + $1 - 1 )) $end_pos $base_style $highlights)
|
||||||
|
@ -36,5 +36,5 @@ expected_region_highlight=(
|
|||||||
'1 4 builtin' # echo
|
'1 4 builtin' # echo
|
||||||
'6 8 default' # foo
|
'6 8 default' # foo
|
||||||
'9 10 redirection' # >&
|
'9 10 redirection' # >&
|
||||||
'11 11 file-descriptor "issue #694"' # 2 (not path)
|
'11 11 numeric-fd' # 2 (not path)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user