'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:
Daniel Shahaf
2020-03-17 03:59:30 +00:00
parent 1024ae8177
commit fb69f4ca81
4 changed files with 19 additions and 6 deletions

View File

@@ -59,6 +59,7 @@
: ${ZSH_HIGHLIGHT_STYLES[redirection]:=fg=yellow}
: ${ZSH_HIGHLIGHT_STYLES[comment]:=fg=black,bold}
: ${ZSH_HIGHLIGHT_STYLES[named-fd]:=none}
: ${ZSH_HIGHLIGHT_STYLES[numeric-fd]:=none}
: ${ZSH_HIGHLIGHT_STYLES[arg0]:=fg=green}
# Whether the highlighter should be called or not.
@@ -112,6 +113,10 @@ _zsh_highlight_main_calculate_fallback() {
hashed-command arg0
arg0_\* arg0
# TODO: Maybe these? —
# named-fd file-descriptor
# numeric-fd file-descriptor
path_prefix path
# The path separator fallback won't ever be used, due to the optimisation
# in _zsh_highlight_main_highlighter_highlight_path_separators().
@@ -1271,10 +1276,14 @@ _zsh_highlight_main_highlighter_highlight_argument()
esac
done
if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg[$1,-1]; then
base_style=$REPLY
_zsh_highlight_main_highlighter_highlight_path_separators $base_style
highlights+=($reply)
if (( path_eligible )); then
if (( in_redirection )) && [[ $last_arg == *['<>']['&'] && $arg[$1,-1] == <0-> ]]; then
base_style=numeric-fd
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
highlights=($(( start_pos + $1 - 1 )) $end_pos $base_style $highlights)

View File

@@ -36,5 +36,5 @@ expected_region_highlight=(
'1 4 builtin' # echo
'6 8 default' # foo
'9 10 redirection' # >&
'11 11 file-descriptor "issue #694"' # 2 (not path)
'11 11 numeric-fd' # 2 (not path)
)