Compare commits

...
8 Commits
Author SHA1 Message Date
Daniel Shahaf e6683f20e5 'main': Prevent an infinite loop when $PWD had been deleted
Fixes #819
2026-10-09 17:16:49 +00:00
yfwmaniishandDaniel Shahaf 0bfcb582e7 docs: add correct Arch Linux install path
The Arch Linux package installs to
/usr/share/zsh/plugins/zsh-syntax-highlighting/, not
/usr/share/zsh-syntax-highlighting/ as the generic "most Linux
distributions" instructions say -- verified against the package's
current file listing on archlinux.org. Added a dedicated Arch bullet
alongside the existing NetBSD/OpenBSD and Homebrew ones, in both
places the distro-specific paths are given.

Fixes #967
2026-09-17 10:40:42 +00:00
Manish TiwariandMatthew Martin 2fc57d6306 tests: fix relative links in tests/README.md
test-highlighting.zsh and test-perfs.zsh were linked as tests/test-*.zsh,
but this file already lives in tests/, so the links resolved to
tests/tests/test-*.zsh and 404'd. Found by pointing a markdown
link-checker at the repo.
2026-08-21 21:19:05 -05:00
Colin KinlochandMatthew Martin c4d9559184 main: Add systemd run0 equivalent to sudo 2026-08-07 12:11:51 -07:00
Matthew Martin 1d85c69261 main: precommand_options += caffeinate
Closes #975
2026-02-08 10:49:40 -06:00
Daniel Shahaf 5eb677bb0f 'main' tests: Don't assume ps(1) is available.
It's actually unavailable in the minimal chroots Debian builds our
package on.  That's allowed by POSIX, which specifies ps(1) to be
optional, whereas id(1) —

- is not optional in POSIX
- should exist on every system anyone might run the testsuite on
- has the same length name, so test expectations don't have to be updated
- doesn't take a filename argument (ditto)

That does make the pipeline as a whole somewhat nonsensical
semantically, but it remains just as valid syntactically.
2024-11-21 15:09:26 +00:00
Matthew Martin e0165eaa73 main: Refactor __is_redirection
Fixes #942.
2024-01-06 12:36:52 -06:00
Matthew Martin dcc99a8649 Post-release version number bump. 2023-12-18 16:07:39 -06:00
8 changed files with 126 additions and 10 deletions
+1 -1
View File
@@ -1 +1 @@
0.8.0
0.8.1-dev
+8
View File
@@ -42,6 +42,12 @@ Second, enable zsh-syntax-highlighting by sourcing the script. Running this comm
echo "source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
```
* Arch Linux:
```zsh
echo "source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
```
* NetBSD and OpenBSD:
```zsh
@@ -60,6 +66,8 @@ Then restart zsh (such as by opening a new instance of your terminal emulator).
* On most Linux distributions (except perhaps NixOS):
`source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh`
* Arch Linux:
`source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh`
* NetBSD and OpenBSD:
`source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh`
+7
View File
@@ -1,3 +1,10 @@
# Changes in HEAD
- Highlight `&>` `>&|` `>&!` `&>|` and `&>!` as redirection.
[#942]
# Changes in 0.8.0
This is a stable bugfix and feature release. Major new features and changes include:
+11 -5
View File
@@ -254,10 +254,9 @@ _zsh_highlight_main__is_runnable() {
_zsh_highlight_main__is_redirection() {
# A redirection operator token:
# - starts with an optional single-digit number;
# - then, has a '<' or '>' character;
# - is not a process substitution [<(...) or >(...)].
# - is not a numeric glob <->
[[ $1 == (<0-9>|)(\<|\>)* ]] && [[ $1 != (\<|\>)$'\x28'* ]] && [[ $1 != *'<'*'-'*'>'* ]]
# - is one of the tokens listed in zshmisc(1)
# - however (z) normalizes ! to |
[[ ${1#[0-9]} == (\<|\<\>|(\>|\>\>)(|\|)|\<\<(|-)|\<\<\<|\<\&|\&\<|(\>|\>\>)\&(|\|)|\&(\>|\>\>)(|\||\!)) ]]
}
# Resolve alias.
@@ -355,6 +354,7 @@ _zsh_highlight_highlighter_main_paint()
'pkexec' '' # doesn't take short options; immune to #121 because it's usually not passed --option flags
# Not listed: -h, which has two different meanings.
'sudo' Cgprtu:AEHPSbilns:eKkVv # as of sudo 1.8.21p2
'run0' ugD:h # systemd 256.6
'stdbuf' ioe:
'eatmydata' ''
'catchsegv' ''
@@ -373,6 +373,7 @@ _zsh_highlight_highlighter_main_paint()
'grc' :se # grc - a "generic colouriser" (that's their spelling, not mine)
'cpulimit' elp:ivz # cpulimit 0.2
'ktrace' fgpt:aBCcdiT
'caffeinate' tw:dimsu # as of macOS's caffeinate(8) dated November 9, 2012
)
# Commands that would need to skip one positional argument:
# flock
@@ -1239,9 +1240,14 @@ _zsh_highlight_main_highlighter_check_path()
fi
tmp_path=$tmp_path:a
local candidate_new_tmp_path
while [[ $tmp_path != / ]]; do
[[ -n ${(M)ZSH_HIGHLIGHT_DIRS_BLACKLIST:#$tmp_path} ]] && return 1
tmp_path=$tmp_path:h
candidate_new_tmp_path=${tmp_path:h}
if [[ $candidate_new_tmp_path == $tmp_path ]]; then
break
fi
tmp_path=${candidate_new_tmp_path}
done
if (( in_command_position )); then
@@ -27,7 +27,7 @@
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='ps aux | grep java | sort | uniq | tail | head'
BUFFER='id bob | grep java | sort | uniq | tail | head'
expected_region_highlight=(
"1 2 command" # ps
@@ -0,0 +1,95 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2024 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=$': <foo 9<foo <>foo 9<>foo >foo 9>foo >|foo >\!foo >>foo >>|foo >>\!foo <<<foo <&9 >&9 <&- >&- <&p >&p >&foo &>foo >&|foo >&\!foo &>|foo &>\!foo >>&foo &>>foo >>&|foo >>&\!foo &>>|foo &>>\!foo'
expected_region_highlight=(
'1 1 builtin' # :
'3 3 redirection' # <
'4 6 default' # foo
'8 9 redirection' # 9<
'10 12 default' # foo
'14 15 redirection' # <>
'16 18 default' # foo
'20 22 redirection' # 9<>
'23 25 default' # foo
'27 27 redirection' # >
'28 30 default' # foo
'32 33 redirection' # 9>
'34 36 default' # foo
'38 39 redirection' # >|
'40 42 default' # foo
'44 45 redirection' # >\!
'46 48 default' # foo
'50 51 redirection' # >>
'52 54 default' # foo
'56 58 redirection' # >>|
'59 61 default' # foo
'63 65 redirection' # >>\!
'66 68 default' # foo
'70 72 redirection' # <<<
'73 75 default' # foo
'77 78 redirection' # <&
'79 79 numeric-fd' # 9
'81 82 redirection' # >&
'83 83 numeric-fd' # 9
'85 86 redirection' # <&
'87 87 redirection' # -
'89 90 redirection' # >&
'91 91 redirection' # -
'93 94 redirection' # <&
'95 95 redirection' # p
'97 98 redirection' # >&
'99 99 redirection' # p
'101 102 redirection' # >&
'103 105 default' # foo
'107 108 redirection' # &>
'109 111 default' # foo
'113 115 redirection' # >&|
'116 118 default' # foo
'120 122 redirection' # >&\!
'123 125 default' # foo
'127 129 redirection' # &>|
'130 132 default' # foo
'134 136 redirection' # &>\!
'137 139 default' # foo
'141 143 redirection' # >>&
'144 146 default' # foo
'148 150 redirection' # &>>
'151 153 default' # foo
'155 158 redirection' # >>&|
'159 161 default' # foo
'163 166 redirection' # >>&\!
'167 169 default' # foo
'171 174 redirection' # &>>|
'175 177 default' # foo
'179 182 redirection' # &>>\!
'183 185 default' # foo
)
@@ -27,7 +27,7 @@
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='ps aux | grep java'
BUFFER='id bob | grep java'
expected_region_highlight=(
"1 2 command" # ps
+2 -2
View File
@@ -86,7 +86,7 @@ grow ways to set `$PREBUFFER` to inject free-form code into the generated file.
Highlighting test
-----------------
[`test-highlighting.zsh`](tests/test-highlighting.zsh) tests the correctness of
[`test-highlighting.zsh`](test-highlighting.zsh) tests the correctness of
the highlighting. Usage:
```zsh
@@ -110,7 +110,7 @@ results (tests that failed but were expected to succeed, or vice-versa), run
Performance test
----------------
[`test-perfs.zsh`](tests/test-perfs.zsh) measures the time spent doing the
[`test-perfs.zsh`](test-perfs.zsh) measures the time spent doing the
highlighting. Usage:
```zsh