Skip to content

Commit 4ec821b

Browse files
committed
Highlight redirections.
Fixes #23. * danielsh/i23-highlight-redirections: Highlight redirections.
2 parents 219184f + 040df93 commit 4ec821b

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

highlighters/main/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ This highlighter defines the following styles:
4747
* `back-double-quoted-argument` - back double quoted arguments (\x inside "")
4848
* `back-dollar-quoted-argument` - back dollar quoted arguments (\x inside $'')
4949
* `assign` - variable assignments
50+
* `redirection` - redirection operators (`<`, `>`, etc)
5051
* `default` - parts of the buffer that do not match anything
5152

5253
To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`:

highlighters/main/main-highlighter.zsh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
: ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan}
5757
: ${ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan}
5858
: ${ZSH_HIGHLIGHT_STYLES[assign]:=none}
59+
: ${ZSH_HIGHLIGHT_STYLES[redirection]:=none}
5960

6061
# Whether the highlighter should be called or not.
6162
_zsh_highlight_main_highlighter_predicate()
@@ -182,7 +183,7 @@ _zsh_highlight_main_highlighter()
182183
elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then
183184
style=$ZSH_HIGHLIGHT_STYLES[history-expansion]
184185
elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then
185-
style=$ZSH_HIGHLIGHT_STYLE[redirection]
186+
style=$ZSH_HIGHLIGHT_STYLES[redirection]
186187
redirection=true
187188
else
188189
style=$ZSH_HIGHLIGHT_STYLES[unknown-token]
@@ -217,6 +218,8 @@ _zsh_highlight_main_highlighter()
217218
style=$ZSH_HIGHLIGHT_STYLES[history-expansion]
218219
elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then
219220
style=$ZSH_HIGHLIGHT_STYLES[commandseparator]
221+
elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then
222+
style=$ZSH_HIGHLIGHT_STYLES[redirection]
220223
else
221224
style=$ZSH_HIGHLIGHT_STYLES[default]
222225
fi
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env zsh
2+
# -------------------------------------------------------------------------------------------------
3+
# Copyright (c) 2015 zsh-syntax-highlighting contributors
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without modification, are permitted
7+
# provided that the following conditions are met:
8+
#
9+
# * Redistributions of source code must retain the above copyright notice, this list of conditions
10+
# and the following disclaimer.
11+
# * Redistributions in binary form must reproduce the above copyright notice, this list of
12+
# conditions and the following disclaimer in the documentation and/or other materials provided
13+
# with the distribution.
14+
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
15+
# may be used to endorse or promote products derived from this software without specific prior
16+
# written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24+
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25+
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
# -------------------------------------------------------------------------------------------------
27+
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
28+
# vim: ft=zsh sw=2 ts=2 et
29+
# -------------------------------------------------------------------------------------------------
30+
31+
# Redirection before and after the command word are implemented differently; test both.
32+
ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight
33+
BUFFER='<<<foo echo >>&!bar'
34+
35+
expected_region_highlight=(
36+
"1 3 $ZSH_HIGHLIGHT_STYLES[redirection]" # <<<
37+
"13 16 $ZSH_HIGHLIGHT_STYLES[redirection]" # >>&!
38+
)

0 commit comments

Comments
 (0)