Compare commits

..

89 Commits

Author SHA1 Message Date
Daniel Shahaf
5eb677bb0f 'main' tests: Don't assume ps(1) is available.
Some checks failed
Tests / test (4.3.17) (push) Has been cancelled
Tests / test (5.0.0) (push) Has been cancelled
Tests / test (5.0.1) (push) Has been cancelled
Tests / test (5.0.2) (push) Has been cancelled
Tests / test (5.0.3) (push) Has been cancelled
Tests / test (5.0.4) (push) Has been cancelled
Tests / test (5.0.5) (push) Has been cancelled
Tests / test (5.0.6) (push) Has been cancelled
Tests / test (5.0.7) (push) Has been cancelled
Tests / test (5.0.8) (push) Has been cancelled
Tests / test (5.1) (push) Has been cancelled
Tests / test (5.1.1) (push) Has been cancelled
Tests / test (5.2) (push) Has been cancelled
Tests / test (5.3) (push) Has been cancelled
Tests / test (5.3.1) (push) Has been cancelled
Tests / test (5.4) (push) Has been cancelled
Tests / test (5.4.1) (push) Has been cancelled
Tests / test (5.4.2) (push) Has been cancelled
Tests / test (5.5) (push) Has been cancelled
Tests / test (5.5.1) (push) Has been cancelled
Tests / test (5.6) (push) Has been cancelled
Tests / test (5.6.1) (push) Has been cancelled
Tests / test (5.6.2) (push) Has been cancelled
Tests / test (5.7) (push) Has been cancelled
Tests / test (5.7.1) (push) Has been cancelled
Tests / test (5.8) (push) Has been cancelled
Tests / test (5.8.1) (push) Has been cancelled
Tests / test (5.9) (push) Has been cancelled
Tests / test (master) (push) Has been cancelled
Tests / notify (push) Has been cancelled
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
Matthew Martin
db085e4661 Tag version 0.8.0. 2023-12-18 16:05:43 -06:00
Matthew Martin
9bb3db7fd2 driver: Use stable zsh release in is-at-least calls 2023-12-18 16:02:40 -06:00
Matthew Martin
bb27265aee CI: Update action versions 2023-10-29 13:25:08 -05:00
Matthew Martin
71bd576af8 CI += zsh 5.9 2023-10-29 13:13:49 -05:00
Matthew Martin
d59ce0fbd0 driver: Be resilient to KSH_ARRAYS being set in the calling scope 2023-10-29 12:53:19 -05:00
Matthew Martin
e82e2d042d main: precommand_options += ktrace 2023-10-29 12:50:08 -05:00
m0viefreak
0b5b3dcc0c tests: parameter-to-global-alias: Use alias name less likely to clash 2023-10-27 22:05:00 -05:00
Matthew Martin
f8cd0b55b3 docs: Replace zplug instructions with zinit
Fixes #883.
2023-10-25 22:36:04 -05:00
Matthew Martin
1e82d8c83e changelog: Update through HEAD 2023-10-25 22:11:43 -05:00
Matthew Martin
dd0cf649d1 *: Use https in URLs 2023-10-25 21:33:29 -05:00
Mario P. Cardenas
65071902d3 docs: add instructions to source .zshrc file after package install 2023-10-24 21:15:46 -05:00
Matthew Martin
143b25eb98 docs: Fix Homebrew link
Closes #937.
2023-09-05 23:23:07 -05:00
Henry Bley-Vroman
1386f1213e docs: ZSH_HIGHLIGHT_HIGHLIGHTERS is (main) by default 2023-06-02 22:24:20 -06:00
Johan van Eck
754cefe018 docs: Markup changes only (in the brew installation instructions) 2023-02-05 08:49:34 +00:00
DiegoBoy
75ba3d87e3 Fix proxychains args
Args for proxychains should be f:q => -f file  : -q quiet.

From comments in the same function:
# $precommand_options maps precommand name to values of $flags_with_argument,
# $flags_sans_argument, and flags_solo for that precommand, joined by a
# colon.
2023-02-02 14:57:36 +00:00
Matthew Martin
b2c910a85e docs: Add Fig instructions
Closes #877
2022-11-19 14:30:47 -06:00
Matthew Martin
122dc46439 main: Add cpulimit to precommands
Closes #897
2022-09-23 19:33:44 -05:00
inventor500
b828f45da6 main precommands += torsocks 2022-09-24 00:28:28 +00:00
Daniel Shahaf
caa749d030 main: Housekeep $precommand_options. Add -v to tabbed(1). 2022-05-14 18:48:13 +00:00
Daniel Shahaf
c5ce001467 main: Deconfuse $EDITOR
Work around <https://github.com/chrisbra/vim-zsh/issues/33>.
2022-02-23 18:48:13 +00:00
Daniel Shahaf
5459ebcc4e main: precommand_options += grc 2022-02-23 18:19:58 +00:00
Daniel Shahaf
2cd73fcbde *: Update sourceforge links
* changelog.md: Update links here too.  They have not yet appeared in
    any stable release.

Command used: perl -pi -e 's#http://zsh.sourceforge.net#https://zsh.sourceforge.io#g' **/*(.)
2022-02-22 10:42:31 +00:00
Daniel Shahaf
643717ccaf changelog: Update zsh version numbers
5.8.0.3 was correct until 5.8.1 was released (see the great-grandparent of this
commit, "driver: Bump the in-development is-at-least checks so they return
false on zsh 5.8.1, released yesterday").

5.2 -> 5.3 is simply a typo fix.  zle-line-pre-redraw has been available since then.
2022-02-22 10:38:45 +00:00
Nuri Jung
caeca0bf6b docs: regexp: Document the platform dependency
Patch by Nuri Jung; extension to cover PCRE by me.  See #747.

Fixes #747.
2022-02-22 10:34:43 +00:00
Daniel Shahaf
56b4433461 CI += zsh 5.8.1 2022-02-13 21:33:05 +00:00
Daniel Shahaf
0ddb1a8d51 driver: Bump the in-development is-at-least checks so they return false on zsh 5.8.1, released yesterday.
Fixes #856
Fixes #857
2022-02-13 18:03:11 +00:00
Daniel Shahaf
c10808ad5f main: New test for issue #854 2022-01-31 09:54:57 +00:00
Daniel Shahaf
b392045e6f driver: Simplify grammar of a comment. No functional change. 2022-01-31 09:54:57 +00:00
Daniel Kuettel
c7caf57ca8 check KEYS_QUEUED_COUNT and PENDING to skip parsing when pasting 2021-11-14 02:45:00 +00:00
Leonardo Gama
1a9264bc66 docs: Add regexp to the list of built-in highlighters 2021-09-24 00:40:57 -03:00
Leonardo Gama
f6a22fa842 docs: Change highlighters' URL indexes from numbers to labels 2021-09-24 00:40:39 -03:00
a1346054
6e0e950154 *: Fix spelling
Part of PR #832.
2021-08-20 11:30:10 +00:00
Matthew Martin
dffe304567 CI: Pull image from the GitHub container registry 2021-07-03 14:33:17 -05:00
Matthew Martin
f0e6a8ef5c main: Honor shwordsplit when expanding parameters
Closes #687, #818.
2021-06-28 23:02:31 -05:00
Matthew Martin
0e1bb14452 main: precommands += proxychains 2021-05-29 23:24:58 -05:00
Matthew Martin
894127b221 docs,CI: Switch to Libera.Chat 2021-05-20 20:10:34 -05:00
Daniel Shahaf
ebef4e5569 docs: Use SSL for the link to zsh's homepage. 2021-04-14 10:39:18 +00:00
Robert
993a07fc7f docs: Fix broken link to fish shell 2021-04-14 10:39:18 +00:00
Nikola Knezevic
e8517244f7 main: Allow for "]" in shell aliases
PR #776 fixed an issue with complex aliases and expansion. However, this change
also introduced a problem with aliases which contain `]` (for example, commonly
seen on macOS: `alias ]=open`), due to using an associative array `seen_alias`,
indexed by the alias name. Due to `"$seen_alias[$arg]"`, it would fail when
`$arg` is expanded to anything containing `]`'. Thus, typing `] /` would result
in:

```
> ] /
(anon):unset:3: seen_alias[]]: invalid parameter name
```

This change fixes the issue by ensuring we properly access keys in the
associative array `seen_alias`.

Older versions of zsh have issues with map keys having special
characters, especially lacking ways to remove such keys. The
issue is described in detail in
https://unix.stackexchange.com/questions/626393/in-zsh-how-do-i-unset-an-arbitrary-associative-array-element.

This fix uses proposal from
[zsh-workers/43269](https://www.zsh.org/mla/workers/2018/msg01073.html),
discovered by Stephane Chazelas, that boils down to avoid removing keys
from the map, and reconstruct the map anew with some keys omitted.

Co-authored-by: @phy1729
2021-03-04 20:29:43 -06:00
Daniel Shahaf
205bc7ea19 'main': Disable a lint warning when env(1) was followed by a pipe.
Fixes #797.
2021-03-01 20:21:39 +00:00
Matthew Martin
5eb494852e Switch to GitHub Actions from Travis 2020-12-25 16:43:50 -06:00
Matthew Martin
75c0eb0717 main: Remember nest level an alias was seen in for seen_alias
Fixes #775.
2020-12-25 16:39:07 -06:00
Matthew Martin
046cb03a12 main: Convert in_alias to an array of shift counts
No functional change. Keeps track of how deep we are in expanding nested
aliases for the next commit.
2020-12-25 16:39:07 -06:00
Hussaina Begum Nandyala
1715f39a46 docs: Add resource link for NetBSD operating system
Signed-off-by: Hussaina Begum Nandyala <hexxdump@gmail.com>
2020-11-02 12:18:01 -06:00
Matthew Martin
2ebfa6a598 main: Forget seen aliases when starting a new command
Fixes #769
2020-10-12 19:29:53 -05:00
Matthew Martin
aac09942b8 Revert "tests: Add a test that 'rehash' isn't run."
This reverts commit 62c5575848.

The test fails when zsh/parameter is available.
2020-10-12 19:28:53 -05:00
Roman Perepelitsa
62c5575848 tests: Add a test that 'rehash' isn't run.
See comments within for the rationale.

This is a regression test for a regression that was only present in development
versions of PR #764 and was never present in master.
2020-08-26 08:47:06 +00:00
Ivo Šmerek
4cf464f843 docs: Update Gentoo link 2020-08-16 13:12:46 +00:00
Daniel Shahaf
6d5372a937 tests: parameter-to-global-alias: Fix a false positive failure when 'x' happens to be a valid external command name.
Reported on issue #757 along with other issues.
2020-08-11 09:21:21 +00:00
Daniel Shahaf
e9cad1493f changelog: Document #712 under the last tag, 0.8.0-alpha1-pre-redrawhook. 2020-08-11 08:42:59 +00:00
m0viefreak
79b6e7e05f tests: precommand-killing1: Use a dummy path that always exists
E.g., on Cygwin /etc/passwd does not necessarily exist.
2020-08-11 08:13:17 +00:00
Daniel Shahaf
3944a44ffe driver: Fix a version number check to work around a bug in the zsh version whereunder the check should return false.
The bug is as follows:

    % zsh-5.8 -fc 'autoload is-at-least; is-at-least 5.8.0.2 && echo yes || echo no'
    yes
    % zsh-5.8 -fc 'autoload is-at-least; is-at-least 5.8.0.2 $ZSH_VERSION && echo yes || echo no'
    yes

This commit deploys the following workaround:

    % zsh-5.8 -fc 'autoload is-at-least; is-at-least 5.8.0.2 $ZSH_VERSION.0.0 && echo yes || echo no'
    no

Fixes #756.
2020-08-10 07:40:01 +00:00
Matthew Martin
34674d7860 docs: Add OpenBSD port 2020-08-09 13:08:29 -05:00
Matthew Martin
e4d1db1e2c docs: Sort INSTALL.md 2020-08-09 13:08:29 -05:00
Daniel Shahaf
c14fcad3b0 empty commit: Close redrawhook bugs
The parent commit, which merged the feature/redrawhook bug and thereby
closed PR #749, also fixed the following issue:

Fixes #40.

Fixes #90, closes #470. (The latter is a PR for the former.)

Fixes #150, closes #151, closes #160. (The latter two are PR's for the first one.) The related issue #183 appears to have been fixed in master. For #150, a different fix for older versions of zsh was considered but has not been implemented.

Issue #154 was fixed in xsel(1) in 2017. The parent commit probably fixed that issue for pre-2017 xsel(1).

Is #245, #356, and #749. Fixes #245 (redrawhook umbrella issue).

Does not reintroduce #257 (comment).

Does not reintroduce #259 (comment)

Closes #281 as obsolete.

Fixes #295.

Fixes #324.

Fixes #375.

Fixes #377.

Closes #421 as obsolete.

Fixes #520.

Unblocks #536 (already milestoned).

Fixes #632.

Unblocks #635. Milestoned.

Unblocks #688. Milestoned.

Unblocks administrative issue #655 (already milestoned).

(The above is copied from
https://github.com/zsh-users/zsh-syntax-highlighting/pull/749#issuecomment-658407330,
but repeated here for the sake of github's commit-to-issue linking magic.)
2020-08-09 11:09:19 +00:00
Daniel Shahaf
239c720dec Merge branch 'feature/redrawhook'
* feature/redrawhook:
  docs: Track making the new codepath conditional upon the 'memo=' feature.
  On the feature/redrawhook branch, changelog: Add entries for issues fixed by this branch.
  On the feature/redrawhook branch, change the detection of the 'memo=' feature to avoid a catch-22.
  driver: Make the redrawhook codepath conditional upon the memo= feature.
  On the feature/redrawhook branch, move the changelog entry to the current release's section.
  driver: Fix a bug that prevented subsequent, third-party zle-line-pre-redraw hooks from running.
  driver: Do not pass widget arguments to _zsh_highlight
  driver: Clarify comment.  No functional change.
  driver: Allow for -U in autoloaded function definition
  driver: Use idiomatic module check
  driver: Make the shadowing $WIDGET read only.
  driver: Avoid a fork in the common case.
  test harness: Actually test the new code.
  driver: Rewrite without a state variable
  noop: Make a whitespace-only change to reduce noise in the next commit.
  docs: Rewrap.
  docs: Update FAQ answer per changes on this branch.
  redo _zsh_highlight__function_callable_p
  driver: Use a different way of checking whether add-zle-hook-widget is present.
  changelog: Use a more specific link.
  changelog: Note the effect of fixing #245/#90 and an alternative.
  driver: Pass zle-line-finish arguments on to _zsh_highlight.
  driver: Hook zle-line-finish.
  driver: Reimplement using 'add-zle-hook-widget zle-line-pre-redraw'
  wrappers: Reimplement using Mikachu's zle-line-pre-redraw hook (workers/36650).
2020-08-09 11:00:45 +00:00
Daniel Shahaf
7cc6226477 docs: Track making the new codepath conditional upon the 'memo=' feature.
The new codepath is used in 5.8.0.2 and newer; see zsh-syntax-highlighting.zsh:417.
2020-08-09 10:56:18 +00:00
Daniel Shahaf
cba4a1bc2e On the feature/redrawhook branch, changelog: Add entries for issues fixed by this branch.
This covers issues referenced from #245 or labelled "feature:redrawhook" or "widget-wrapping".  See #749 for details.
2020-07-14 23:20:29 +00:00
Daniel Shahaf
637e1c702e Merge remote-tracking branch 'origin/master' into feature/redrawhook
* origin/master:
  Post-release version number bump.
  Tag version 0.8.0-alpha1-pre-redrawhook.
  brackets: Optimize the character iteration
2020-07-14 22:49:17 +00:00
Daniel Shahaf
2d60a47cc4 Post-release version number bump. 2020-07-14 21:33:52 +00:00
Daniel Shahaf
cb33cc0081 On the feature/redrawhook branch, change the detection of the 'memo=' feature to avoid a catch-22. 2020-07-14 02:37:41 +00:00
Daniel Shahaf
9ce3540d74 Merge remote-tracking branch 'origin/master' into feature/redrawhook
* origin/master:
  Revert "driver: Move the initialization of $zsh_highlight__memo_feature out of the entry point function."
2020-07-14 02:31:24 +00:00
Daniel Shahaf
59cb9a560d driver: Make the redrawhook codepath conditional upon the memo= feature.
Fixes #579 (zsh-autosuggestions interoperability).
Fixes #735 (ditto).

See https://github.com/zsh-users/zsh-syntax-highlighting/issues/579#issuecomment-650126055
See https://github.com/zsh-users/zsh-autosuggestions/issues/529#issuecomment-650481227
2020-07-14 02:13:51 +00:00
Daniel Shahaf
7b863fb413 Merge remote-tracking branch 'origin/master' into feature/redrawhook
* origin/master:
  driver: Move the initialization of $zsh_highlight__memo_feature out of the entry point function.
2020-07-14 02:08:20 +00:00
Daniel Shahaf
daf0d94bae On the feature/redrawhook branch, move the changelog entry to the current release's section. 2020-07-14 02:00:45 +00:00
Daniel Shahaf
c28312b9d3 Merge remote-tracking branch 'origin/master' into feature/redrawhook
* origin/master: (297 commits)
  driver: Follow-up to grandparent: Have all test suite entry points declare the mock $region_highlight.
  Use the new, unreleased zsh 'memo=' feature to remove only our own entries from $region_highlight.
  driver: Stop re-declaring $region_highlight.  It's unneeded.
  docs: regexp highlighter: Fix a wrong associative array name in the example.
  docs: Fix obs-repository link
  tests: Fix a wrong value of $PREBUFFER in a test, and add checks to prevent this from recurring.
  test harness: Fix use of an undefined variable in an error message.
  'main': Don't progress the $in_redirection staller while $in_param.
  tests: Add an XFail test for issue #712.
  'main': Highlight the parentheses of array assignments as reserved words.
  CI += zsh-5.8
  main: Add tests for arithmetic expansion
  main: Add arithmetic substitution highlighting
  changelog.md: Restore vertical whitespace before section headers.
  'main': Fix issue #677, concerning multiline aliases.
  changelog: Update through HEAD.
  'main': Further optimize argument parsing.
  'main': Optimize a hot path.
  tests: Add a performance testing script, for measuring the performance of the 'main' highlighter on a large file.
  changelog: Update through HEAD.
  test harness: Print the expected-v.-actual on every failure, not just upon cardinality failures.
  Document ZSH_HIGHLIGHT_MAXLENGTH.
  'main': Fix the last commit's bug concerning parameter elision not happening in redirects in command position.
  'main': Add a test for parameter elision not happening in redirects in command position.
  'main': Fix regression in zsh 5.3.1 and older: all precmd hooks later than z-sy-h would be aborted.
  changelog += WARN_NESTED_VAR fixes (#727, #731)
  'main': Fix a regression caused by the great-grandparent commit's WARN_NESTED_VAR fix.
  'main': Don't run `_zsh_highlight_main__type` on every non-command word.
  'make perf': Show only a cumulative datum per highligher, rather than per test file.
  'main': Don't trip WARN_NESTED_VAR.
  'main': Follow-up to previous: Document the version number, and deduplicate some option letters.
  'main': precommands += strace
  editorconfig: Fix Makefile settings
  Fix typo
  Bump copyright years.
  driver: Fix "_zsh_highlight:3: read-only variable: ret" warnings when POSIX_BUILTINS is set.
  tests: Add a test for the infinite loop fixed by each of the last two commits.
  'main': Fix expansion of positional parameters in `_zsh_highlight_main_highlighter__try_expand_parameter`.
  'main': Fix an infinite loop.
  'main': precommands += ionice(1) (from util-linux)
  driver: Simplify initialization of $zsyh_user_options in the fallback codepath.
  driver: Make sure we don't change the return value in a called function.
  'main': Make logic more robust.  No functional change.
  'main': Break out an anonymous function into a named function.
  Fix typos in comments.
  main: Add test for issue #713
  'main': Support the 'env' precommand.
  test harness: Fix the pretty-printer's padding implementation.
  Revert "test harness: Rewrite the columnar pretty-printer without external tools." and "travis: Remove bsdmainutils since column(1) has been removed, three commits ago."
  changelog: Update through HEAD.
  'main': Correctly highlight '&&' and '||' inside '[[ … ]]' conditions.
  'main': Highlight reserved words following assignments as errors.
  tests: Add tests for issue #461.
  test harness: Output the time information to the same place the test name was printed to.
  test harness: Stringify values in a more readable manner.
  tests: Add a unit test for a path specified with mixed quoting.
  tests: Add a test for issue #498, which has already been fixed.
  tests: Test that global qualifiers and command substitutions aren't evaluated.
  'main': Don't consider path_prefix in alias expansions.
  'main': Add a test for aliases to AUTO_CD directories.
  'main': Let AUTO_CD directories be highlighted with their own style.
  'main': Add an auxiliary variable for readability.
  'main': In command position, do not highlight directories (unless AUTO_CD is set) and non-executable files.
  'main': Extend tests to capture the current behaviour.
  'main': Add an XFail test for issue #202.
  'main': Highlight errors from the EQUALS option.
  'main': Let the type determination ignore global aliases when it ignores regular ones.
  'main': Add a regression test for parameters that expand to global aliases.
  'main': Enable the zsh/parameter codepath of global aliases highlighting.
  changelog: Update through HEAD.
  travis: Remove bsdmainutils since column(1) has been removed, three commits ago.
  'main': Highlight global aliases
  tests: Record current behaviour on global aliases.
  test harness: Rewrite the columnar pretty-printer without external tools.
  test harness: Fix an issue with the pretty-printed $expected_region_highlight/$region_highlight diffing.
  'main': Support the "close file descriptor" and "coproc" redirection syntaxes
  tests: Add a test for the "close file descriptor" and "coproc" redirection syntaxes
  tests: Fix the test added in the last commit.
  tests: Add a test for issue #705, concerning continuation lines.
  test harness: Let tests fail early by exiting non-zero or by setting a flag.
  test harness: Print the test name when $skip_test is set.
  test harness: Remove a bogus check.
  test harness: Fix $skip_test support, broken yesterday.
  travis: Install bsdmainutils to provide column(1).
  test harness: When the cardinality check fails, pretty-print \$expected_region_highlight and \$region_highlight.
  test harness: Don't leak options from test files to the test harness.
  test harness: Fix test failures under zsh 5.0.8 and older.
  'main': Fix a bug manifesting under zsh 5.2 and older.
  'main': Don't highlight arithmetic expansions as command substitutions.
  tests: Add a test documenting the current state, prior to introducing #704.
  test harness: Change cardinality check semantics
  test harness: No-op change to minimize the next diff.
  'main': Document additional meanings of the 'S' $braces_stack flag.
  '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.
  'main': Add $last_arg for "lookbehind".
  noop: Clarify comment.
  'main': Honour the MULTIOS option when applying the 'globbing' style.
  'main': Document what $in_redirection is currently used for.
  'main': The optimized cmdsubst input syntax doesn't glob.
  changelog: Fix markup.
  ...
2020-07-14 01:57:55 +00:00
Daniel Shahaf
b08d508cd8 driver: Fix a bug that prevented subsequent, third-party zle-line-pre-redraw hooks from running.
Without this patch, `_zsh_highlight` was invoked by add-zle-hook-widget
with `$?` being non-zero (see add-zle-hook-widget:48-52).  Since
`_zsh_highlight` preserves `$?` from its caller's point of view,
add-zle-hook-widget saw a non-zero exit code from `_zsh_highlight` and
did not run any the remaining zle-line-pre-redraw hooks.

See https://github.com/zsh-users/zsh-syntax-highlighting/issues/579#issuecomment-623576907.
2020-05-04 16:45:21 +00:00
Matthew Martin
8d4c6355e6 driver: Do not pass widget arguments to _zsh_highlight
This avoids a bug in zsh 4.3.12 and prior which affects passing
arguments to an anonymous function.
2018-10-13 21:55:45 -05:00
Daniel Shahaf
56ba7f082d driver: Clarify comment. No functional change. 2018-10-12 12:35:34 -05:00
Matthew Martin
2cbb3fb24e driver: Allow for -U in autoloaded function definition 2018-10-12 12:35:34 -05:00
Matthew Martin
f265ef0b9a driver: Use idiomatic module check 2018-10-12 12:35:34 -05:00
Daniel Shahaf
d0fb0df4ff driver: Make the shadowing $WIDGET read only. 2018-10-12 12:35:34 -05:00
Daniel Shahaf
f665eec230 driver: Avoid a fork in the common case.
Found-by: Matthew Martin
2018-10-12 12:35:34 -05:00
Daniel Shahaf
a868b6942e test harness: Actually test the new code.
Currently, without zsh/zle loaded, the tests silently fall back to the
5.2-and-earlier codepath; see:
.
    https://github.com/zsh-users/zsh-syntax-highlighting/pull/356#issuecomment-243651251
2018-10-12 12:35:34 -05:00
Daniel Shahaf
b5249f17ab driver: Rewrite without a state variable
Suggested-by: m0viefreak
2018-10-12 12:35:32 -05:00
Daniel Shahaf
d2594c1157 noop: Make a whitespace-only change to reduce noise in the next commit. 2018-10-12 12:31:12 -05:00
Daniel Shahaf
66ae59eccc docs: Rewrap. 2018-10-12 12:31:12 -05:00
Daniel Shahaf
1651137f5c docs: Update FAQ answer per changes on this branch. 2018-10-12 12:31:12 -05:00
Daniel Shahaf
d4ab7e51d2 redo _zsh_highlight__function_callable_p 2018-10-12 12:31:12 -05:00
Daniel Shahaf
38477f2a3d driver: Use a different way of checking whether add-zle-hook-widget is present.
Based on code by Bart Schaefer (reference within).

Tested with zsh 5.0.7-5 (debian package) and with 5b4cbcc842c6 (39158,
5.3-to-be of today).
2018-10-12 12:31:12 -05:00
Daniel Shahaf
d98622dcd0 changelog: Use a more specific link. 2018-10-12 12:31:12 -05:00
Daniel Shahaf
04fd6bbf53 changelog: Note the effect of fixing #245/#90 and an alternative. 2018-10-12 12:31:12 -05:00
Daniel Shahaf
30c6e70394 driver: Pass zle-line-finish arguments on to _zsh_highlight.
(Currently a noop)
2018-10-12 12:31:12 -05:00
Daniel Shahaf
74a27de70d driver: Hook zle-line-finish.
Compare issue #288.
2018-10-12 12:31:10 -05:00
Daniel Shahaf
85e62a8171 driver: Reimplement using 'add-zle-hook-widget zle-line-pre-redraw'
This feature will be released in zsh 5.3.  Older zsh's will use the existing
codepath.
2018-10-12 12:30:23 -05:00
Daniel Shahaf
aed99f6a3e wrappers: Reimplement using Mikachu's zle-line-pre-redraw hook (workers/36650). 2018-10-11 22:04:02 -05:00
38 changed files with 1066 additions and 234 deletions

75
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,75 @@
---
name: Tests
on:
push:
paths-ignore:
- '**.md'
- '**.png'
pull_request:
paths-ignore:
- '**.md'
- '**.png'
schedule:
- cron: '29 7 * * 1'
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version:
- master
- 5.9
- 5.8.1
- 5.8
- 5.7.1
- 5.7
- 5.6.2
- 5.6.1
- 5.6
- 5.5.1
- 5.5
- 5.4.2
- 5.4.1
- 5.4
- 5.3.1
- 5.3
- 5.2
- 5.1.1
- 5.1
- 5.0.8
- 5.0.7
- 5.0.6
- 5.0.5
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.3.17
- 4.3.16
- 4.3.15
- 4.3.14
- 4.3.13
- 4.3.12
- 4.3.11
container:
image: ghcr.io/zsh-users/zsh:${{ matrix.version }}
steps:
- uses: actions/checkout@v4
- run: install_packages bsdmainutils make procps
- run: make test
notify:
runs-on: ubuntu-latest
needs: test
if: failure() && (github.repository_owner == 'zsh-users')
steps:
-
name: Notify IRC
uses: Gottox/irc-message-action@v2
with:
channel: '#zsh-syntax-highlighting'
nickname: zsyh-gh-bot
message: '${{ github.ref }} failed tests: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'

View File

@ -1,56 +0,0 @@
language: generic
sudo: required
env:
- ZSH=master
- ZSH=5.8
- ZSH=5.7.1
- ZSH=5.7
- ZSH=5.6.2
- ZSH=5.6.1
- ZSH=5.6
- ZSH=5.5.1
- ZSH=5.5
- ZSH=5.4.2
- ZSH=5.4.1
- ZSH=5.4
- ZSH=5.3.1
- ZSH=5.3
- ZSH=5.2
- ZSH=5.1.1
- ZSH=5.1
- ZSH=5.0.8
- ZSH=5.0.7
- ZSH=5.0.6
- ZSH=5.0.5
- ZSH=5.0.4
- ZSH=5.0.3
- ZSH=5.0.2
- ZSH=5.0.1
- ZSH=5.0.0
- ZSH=4.3.17
- ZSH=4.3.16
- ZSH=4.3.15
- ZSH=4.3.14
- ZSH=4.3.13
- ZSH=4.3.12
- ZSH=4.3.11
script: docker run -v $PWD:/work -w /work zshusers/zsh:${ZSH} /bin/sh -c 'install_packages make procps bsdmainutils && make test'
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/367e241cdea60cb2070b
on_success: change
on_failure: always
on_start: never
irc:
channels:
- "chat.freenode.net#zsh-syntax-highlighting"
on_success: change
on_failure: always
on_start: never
use_notice: true
template:
- "%{repository}/%{branch}#%{build_number}: %{message} Changes : %{compare_url} | Build : %{build_url}"

View File

@ -1 +1 @@
0.8.0-alpha1-pre-redrawhook 0.8.1-dev

View File

@ -95,5 +95,5 @@ zstyle ':completion:*:*:*:*:globbed-files' ignored-patterns {'*/',}zsh-syntax-hi
IRC channel IRC channel
----------- -----------
We're on #zsh-syntax-highlighting on freenode. We're on #zsh-syntax-highlighting on Libera.Chat.

View File

@ -3,31 +3,67 @@ How to install
### Using packages ### Using packages
First, install the package:
* Arch Linux: [community/zsh-syntax-highlighting][arch-package] / [AUR/zsh-syntax-highlighting-git][AUR-package] * Arch Linux: [community/zsh-syntax-highlighting][arch-package] / [AUR/zsh-syntax-highlighting-git][AUR-package]
* Debian: `zsh-syntax-highlighting` package [in `stretch`][debian-package] (or in [OBS repository][obs-repository]) * Debian: `zsh-syntax-highlighting` package [in `stretch`][debian-package] (or in [OBS repository][obs-repository])
* Fedora: [zsh-syntax-highlighting package][fedora-package-alt] in Fedora 24+ (or in [OBS repository][obs-repository]) * Fedora: [zsh-syntax-highlighting package][fedora-package-alt] in Fedora 24+ (or in [OBS repository][obs-repository])
* FreeBSD: `pkg install zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][freebsd-port]) * FreeBSD: `pkg install zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][freebsd-port])
* Gentoo: [mv overlay][gentoo-overlay] * Gentoo: [app-shells/zsh-syntax-highlighting][gentoo-repository]
* Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] * Mac OS X / Homebrew: `brew install zsh-syntax-highlighting` ([formula][brew-package])
* Ubuntu: `zsh-syntax-highlighting` package [in Xenial][ubuntu-package] (or in [OBS repository][obs-repository]) * NetBSD: `pkg_add zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][netbsd-port])
* RHEL / CentOS / Scientific Linux: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] * OpenBSD: `pkg_add zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][openbsd-port])
* openSUSE / SLE: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] * openSUSE / SLE: `zsh-syntax-highlighting` package in [OBS repository][obs-repository]
* RHEL / CentOS / Scientific Linux: `zsh-syntax-highlighting` package in [OBS repository][obs-repository]
* Ubuntu: `zsh-syntax-highlighting` package [in Xenial][ubuntu-package] (or in [OBS repository][obs-repository])
* Void Linux: `zsh-syntax-highlighting package` [in XBPS][void-package] * Void Linux: `zsh-syntax-highlighting package` [in XBPS][void-package]
[arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting [arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting
[AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git [AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git
[brew-package]: https://github.com/Homebrew/homebrew-core/blob/master/Formula/z/zsh-syntax-highlighting.rb
[debian-package]: https://packages.debian.org/zsh-syntax-highlighting [debian-package]: https://packages.debian.org/zsh-syntax-highlighting
[freebsd-port]: http://www.freshports.org/textproc/zsh-syntax-highlighting/
[gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting
[brew-package]: https://github.com/Homebrew/homebrew-core/blob/master/Formula/zsh-syntax-highlighting.rb
[ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting
[fedora-package]: https://apps.fedoraproject.org/packages/zsh-syntax-highlighting [fedora-package]: https://apps.fedoraproject.org/packages/zsh-syntax-highlighting
[fedora-package-alt]: https://bodhi.fedoraproject.org/updates/?packages=zsh-syntax-highlighting [fedora-package-alt]: https://bodhi.fedoraproject.org/updates/?packages=zsh-syntax-highlighting
[freebsd-port]: https://www.freshports.org/textproc/zsh-syntax-highlighting/
[gentoo-repository]: https://packages.gentoo.org/packages/app-shells/zsh-syntax-highlighting
[netbsd-port]: http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/shells/zsh-syntax-highlighting/
[obs-repository]: https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-syntax-highlighting&package=zsh-syntax-highlighting [obs-repository]: https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-syntax-highlighting&package=zsh-syntax-highlighting
[openbsd-port]: https://cvsweb.openbsd.org/ports/shells/zsh-syntax-highlighting/
[ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting
[void-package]: https://github.com/void-linux/void-packages/tree/master/srcpkgs/zsh-syntax-highlighting [void-package]: https://github.com/void-linux/void-packages/tree/master/srcpkgs/zsh-syntax-highlighting
See also [repology's cross-distro index](https://repology.org/metapackage/zsh-syntax-highlighting/versions) See also [repology's cross-distro index](https://repology.org/metapackage/zsh-syntax-highlighting/versions)
Second, enable zsh-syntax-highlighting by sourcing the script. Running this command on the terminal will add the source line to the end of your .zshrc:
* On most Linux distributions (except perhaps NixOS):
```zsh
echo "source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
```
* NetBSD and OpenBSD:
```zsh
echo "source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
```
* Mac OS X / Homebrew:
```zsh
echo "source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
```
Then restart zsh (such as by opening a new instance of your terminal emulator).
Alternatively, add the `source` command manually **at the end** of your `.zshrc`:
* On most Linux distributions (except perhaps NixOS):
`source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh`
* NetBSD and OpenBSD:
`source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh`
Then restart zsh.
### In your ~/.zshrc ### In your ~/.zshrc
@ -71,6 +107,12 @@ This list is incomplete as there are too many
Add `antigen bundle zsh-users/zsh-syntax-highlighting` as the last bundle in Add `antigen bundle zsh-users/zsh-syntax-highlighting` as the last bundle in
your `.zshrc`. your `.zshrc`.
#### [Fig](https://fig.io)
Click the `Install Plugin` button on the [Fig plugin page][fig-plugin].
[fig-plugin]: https://fig.io/plugins/other/zsh-syntax-highlighting
#### [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) #### [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh)
1. Clone this repository in oh-my-zsh's plugins directory: 1. Clone this repository in oh-my-zsh's plugins directory:
@ -98,15 +140,15 @@ Zsh-syntax-highlighting is included with Prezto. See the
Add `zgen load zsh-users/zsh-syntax-highlighting` to the end of your `.zshrc`. Add `zgen load zsh-users/zsh-syntax-highlighting` to the end of your `.zshrc`.
#### [zinit](https://github.com/zdharma-continuum/zinit)
Add `zinit light zsh-users/zsh-syntax-highlighting` to the end of your
`.zshrc`.
#### [zplug](https://github.com/zplug/zplug) #### [zplug](https://github.com/zplug/zplug)
Add `zplug "zsh-users/zsh-syntax-highlighting", defer:2` to your `.zshrc`. Add `zplug "zsh-users/zsh-syntax-highlighting", defer:2` to your `.zshrc`.
#### [zplugin](https://github.com/psprint/zplugin)
Add `zplugin load zsh-users/zsh-syntax-highlighting` to the end of your
`.zshrc`.
### System-wide installation ### System-wide installation

View File

@ -1,12 +1,12 @@
zsh-syntax-highlighting [![Build Status][build-status-image]][build-status-travis] zsh-syntax-highlighting [![Build Status][build-status-image]][build-status]
======================= =======================
**[Fish shell][fish]-like syntax highlighting for [Zsh][zsh].** **[Fish shell][fish]-like syntax highlighting for [Zsh][zsh].**
*Requirements: zsh 4.3.11+.* *Requirements: zsh 4.3.11+.*
[fish]: http://www.fishshell.com/ [fish]: https://fishshell.com/
[zsh]: http://www.zsh.org/ [zsh]: https://www.zsh.org/
This package provides syntax highlighting for the shell zsh. It enables This package provides syntax highlighting for the shell zsh. It enables
highlighting of commands whilst they are typed at a zsh prompt into an highlighting of commands whilst they are typed at a zsh prompt into an
@ -44,11 +44,23 @@ FAQ
### Why must `zsh-syntax-highlighting.zsh` be sourced at the end of the `.zshrc` file? ### Why must `zsh-syntax-highlighting.zsh` be sourced at the end of the `.zshrc` file?
`zsh-syntax-highlighting.zsh` wraps ZLE widgets. It must be sourced after all zsh-syntax-highlighting works by hooking into the Zsh Line Editor (ZLE) and
custom widgets have been created (i.e., after all `zle -N` calls and after computing syntax highlighting for the command-line buffer as it stands at the
running `compinit`). Widgets created later will work, but will not update the time z-sy-h's hook is invoked.
In zsh 5.2 and older,
`zsh-syntax-highlighting.zsh` hooks into ZLE by wrapping ZLE widgets. It must
be sourced after all custom widgets have been created (i.e., after all `zle -N`
calls and after running `compinit`) in order to be able to wrap all of them.
Widgets created after z-sy-h is sourced will work, but will not update the
syntax highlighting. syntax highlighting.
In zsh newer than 5.8 (not including 5.8 itself),
zsh-syntax-highlighting uses the `add-zle-hook-widget` facility to install
a `zle-line-pre-redraw` hook. Hooks are run in order of registration,
therefore, z-sy-h must be sourced (and register its hook) after anything else
that adds hooks that modify the command-line buffer.
### Does syntax highlighting work during incremental history search? ### Does syntax highlighting work during incremental history search?
Highlighting the command line during an incremental history search (by default bound to Highlighting the command line during an incremental history search (by default bound to
@ -61,7 +73,7 @@ enough information to allow computing the highlighting correctly.)
See issues [#288][i288] and [#415][i415] for details. See issues [#288][i288] and [#415][i415] for details.
[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
[i288]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/288 [i288]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/288
[i415]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/415 [i415]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/415
@ -81,5 +93,5 @@ Syntax highlighting is done by pluggable highlighter scripts. See the
[documentation on highlighters](docs/highlighters.md) for details and [documentation on highlighters](docs/highlighters.md) for details and
configuration settings. configuration settings.
[build-status-image]: https://travis-ci.org/zsh-users/zsh-syntax-highlighting.svg?branch=master [build-status]: https://github.com/zsh-users/zsh-syntax-highlighting/actions
[build-status-travis]: https://travis-ci.org/zsh-users/zsh-syntax-highlighting [build-status-image]: https://github.com/zsh-users/zsh-syntax-highlighting/workflows/Tests/badge.svg

View File

@ -1,3 +1,96 @@
# 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:
## Changes fixed as part of the switch to zle-line-pre-redraw
The changes in this section were fixed by switching to a `zle-line-pre-redraw`-based
implementation.
Note: The new implementation will only be used on future zsh releases,
numbered 5.8.1.1 and newer, due to interoperability issues with other plugins
(issues #418 and #579). The underlying zsh feature has been available since
zsh 5.3.
Whilst under development, the new implementation was known as the
"feature/redrawhook" topic branch.
- Fixed: Highlighting not triggered after popping a buffer from the buffer stack
(using the `push-line` widget, default binding: `M-q`)
[#40]
- Fixed: Invoking completion when there were no matches removed highlighting
[#90, #470]
- Fixed: Two successive deletes followed by a yank only yanked the latest
delete, rather than both of them
[#150, #151, #160; cf. #183]
- Presumed fixed: Completing `$(xsel)` results in an error message from `xsel`,
with pre-2017 versions of `xsel`. (For 2017 vintage and newer, see the issue
for details.)
[#154]
- Fixed: When the standard `bracketed-paste-magic` widget is in use, pastes were slow
[#295]
- Fixed: No way to prevent a widget from being wrapped
[#324]
- Fixed: No highlighting while cycling menu completion
[#375]
- Fixed: Does not coexist with the `IGNORE_EOF` option
[#377]
- Fixed: The `undefined-key` widget was wrapped
[#421]
- Fixed: Does not coexist with the standard `surround` family of widgets
[#520]
- Fixed: First completed filename doesn't get `path` highlighting
[#632]
## Other changes
- Add issue #712 to the previous release's changelog (hereinafter).
- Fix highlighting when using an alias twice inside another alias
[#769, #775]
- Remove lint warning for `env` followed by a pipe
[#797]
- Recognize `proxychains` as a precommand
[#814, #914]
- Honor shwordsplit when expanding parameters
[#687, #818]
- Skip highlighting when keys are still pending in more cases
[#835]
- Recognize `grc` as a precommand
- Recognize `torsocks` and `torift` as precommands
[#898]
- Recognize `cpulimit` as a precommand
[#897]
- Recognize `ktrace` as a precommand
# Changes in 0.8.0-alpha1-pre-redrawhook # Changes in 0.8.0-alpha1-pre-redrawhook
## Notice about an improbable-but-not-impossible forward incompatibility ## Notice about an improbable-but-not-impossible forward incompatibility
@ -16,6 +109,25 @@ added to zsh at z-sy-h's initiative. The new feature is used in the fix
to issue #418. to issue #418.
## Incompatible changes:
- An unsuccessful completion (a <kbd>⮀ Tab</kbd> press that doesn't change the
command line) no longer causes highlighting to be lost. Visual feedback can
alternatively be achieved by setting the `format` zstyle under the `warnings`
tag, for example,
zstyle ':completion:*:warnings' format '%F{red}No matches%f'
Refer to the [description of the `format` style in `zshcompsys(1)`]
[zshcompsys-Standard-Styles-format].
(#90, part of #245 (feature/redrawhook))
[zshcompsys-Standard-Styles]: https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Standard-Styles
[zshcompsys-Standard-Styles-format]: https://zsh.sourceforge.io/Doc/Release/Completion-System.html#index-format_002c-completion-style
## Other changes: ## Other changes:
- Document `$ZSH_HIGHLIGHT_MAXLENGTH`. - Document `$ZSH_HIGHLIGHT_MAXLENGTH`.
@ -90,6 +202,8 @@ to issue #418.
- Recognize `env` as a precommand (e.g., `env FOO=bar ls`) - Recognize `env` as a precommand (e.g., `env FOO=bar ls`)
- Recognize `ionice` as a precommand
- Recognize `strace` as a precommand - Recognize `strace` as a precommand
- Fix an error message on stderr before every prompt when the `WARN_NESTED_VAR` zsh option is set: - Fix an error message on stderr before every prompt when the `WARN_NESTED_VAR` zsh option is set:
@ -114,6 +228,9 @@ to issue #418.
- Improve performance of the `brackets` highlighter. - Improve performance of the `brackets` highlighter.
- Fix highlighting of pre-command redirections (e.g., the `$fn` in `<$fn cat`)
[#712]
# Changes in version 0.7.1 # Changes in version 0.7.1
@ -208,7 +325,7 @@ This is a stable release, featuring bugfixes and minor improvements.
- The `isearch` and `suffix` [`$zle_highlight` settings][zshzle-Character-Highlighting]. - The `isearch` and `suffix` [`$zle_highlight` settings][zshzle-Character-Highlighting].
(79e4d3d12405, 15db71abd0cc, b56ee542d619; requires zsh 5.3 for `$ISEARCHMATCH_ACTIVE` / `$SUFFIX_ACTIVE` support) (79e4d3d12405, 15db71abd0cc, b56ee542d619; requires zsh 5.3 for `$ISEARCHMATCH_ACTIVE` / `$SUFFIX_ACTIVE` support)
[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
- Possible history expansions in double-quoted strings. - Possible history expansions in double-quoted strings.
(76ea9e1df316) (76ea9e1df316)
@ -654,7 +771,7 @@ in this area.
## Developer-visible changes: ## Developer-visible changes:
- Test harness converted to [TAP](http://testanything.org/tap-specification.html) format - Test harness converted to [TAP](https://testanything.org/tap-specification.html) format
(d99aa58aaaef, et seq) (d99aa58aaaef, et seq)
- Run each test in a separate subprocess, isolating them from each other - Run each test in a separate subprocess, isolating them from each other

View File

@ -3,19 +3,21 @@ zsh-syntax-highlighting / highlighters
Syntax highlighting is done by pluggable highlighters: Syntax highlighting is done by pluggable highlighters:
* `main` - the base highlighter, and the only one [active by default][1]. * `main` - the base highlighter, and the only one [active by default][main].
* `brackets` - [matches brackets][2] and parenthesis. * `brackets` - [matches brackets][brackets] and parenthesis.
* `pattern` - matches [user-defined patterns][3]. * `pattern` - matches [user-defined patterns][pattern].
* `cursor` - matches [the cursor position][4]. * `regexp` - matches [user-defined regular expressions][regexp].
* `root` - highlights the whole command line [if the current user is root][5]. * `cursor` - matches [the cursor position][cursor].
* `line` - applied to [the whole command line][6]. * `root` - highlights the whole command line [if the current user is root][root].
* `line` - applied to [the whole command line][line].
[1]: highlighters/main.md [main]: highlighters/main.md
[2]: highlighters/brackets.md [brackets]: highlighters/brackets.md
[3]: highlighters/pattern.md [pattern]: highlighters/pattern.md
[4]: highlighters/cursor.md [regexp]: highlighters/regexp.md
[5]: highlighters/root.md [cursor]: highlighters/cursor.md
[6]: highlighters/line.md [root]: highlighters/root.md
[line]: highlighters/line.md
Highlighter-independent settings Highlighter-independent settings
@ -25,10 +27,10 @@ By default, all command lines are highlighted. However, it is possible to
prevent command lines longer than a fixed number of characters from being prevent command lines longer than a fixed number of characters from being
highlighted by setting the variable `${ZSH_HIGHLIGHT_MAXLENGTH}` to the maximum highlighted by setting the variable `${ZSH_HIGHLIGHT_MAXLENGTH}` to the maximum
length (in characters) of command lines to be highlighter. This is useful when length (in characters) of command lines to be highlighter. This is useful when
editing very long comand lines (for example, with the [`fned`][fned] utility editing very long command lines (for example, with the [`fned`][fned] utility
function). Example: function). Example:
[fned]: http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#index-zed [fned]: https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#index-zed
```zsh ```zsh
ZSH_HIGHLIGHT_MAXLENGTH=512 ZSH_HIGHLIGHT_MAXLENGTH=512
@ -38,16 +40,14 @@ ZSH_HIGHLIGHT_MAXLENGTH=512
How to activate highlighters How to activate highlighters
---------------------------- ----------------------------
To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array in To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array.
`~/.zshrc`, for example: By default `ZSH_HIGHLIGHT_HIGHLIGHTERS` is `(main)`. For example to activate
`brackets`, `pattern`, and `cursor` highlighters, in `~/.zshrc` do:
```zsh ```zsh
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor) ZSH_HIGHLIGHT_HIGHLIGHTERS+=(brackets pattern cursor)
``` ```
By default, `$ZSH_HIGHLIGHT_HIGHLIGHTERS` is unset and only the `main`
highlighter is active.
How to tweak highlighters How to tweak highlighters
------------------------- -------------------------
@ -59,7 +59,7 @@ same as the syntax of "types of highlighting" of the zsh builtin
`$zle_highlight` array, which is documented in [the `zshzle(1)` manual `$zle_highlight` array, which is documented in [the `zshzle(1)` manual
page][zshzle-Character-Highlighting]. page][zshzle-Character-Highlighting].
[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
Some highlighters support additional configuration parameters; see each Some highlighters support additional configuration parameters; see each
highlighter's documentation for details and examples. highlighter's documentation for details and examples.

View File

@ -28,4 +28,4 @@ The syntax for values is the same as the syntax of "types of highlighting" of
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
manual page][zshzle-Character-Highlighting]. manual page][zshzle-Character-Highlighting].
[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting

View File

@ -21,4 +21,4 @@ The syntax for values is the same as the syntax of "types of highlighting" of
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
manual page][zshzle-Character-Highlighting]. manual page][zshzle-Character-Highlighting].
[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting

View File

@ -21,4 +21,4 @@ The syntax for values is the same as the syntax of "types of highlighting" of
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
manual page][zshzle-Character-Highlighting]. manual page][zshzle-Character-Highlighting].
[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting

View File

@ -116,6 +116,6 @@ of that (new) kind will be highlighted by the style `arg0_$kind`,
where `$kind` is the output of `type -w` on the new kind of command word. If that where `$kind` is the output of `type -w` on the new kind of command word. If that
style is not defined, then the style `arg0` will be used instead. style is not defined, then the style `arg0` will be used instead.
[zshmisc-Simple-Commands-And-Pipelines]: http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines [zshmisc-Simple-Commands-And-Pipelines]: https://zsh.sourceforge.io/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines
[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting

View File

@ -21,4 +21,4 @@ The syntax for values is the same as the syntax of "types of highlighting" of
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
manual page][zshzle-Character-Highlighting]. manual page][zshzle-Character-Highlighting].
[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting

View File

@ -10,13 +10,46 @@ patterns.
To use this highlighter, associate regular expressions with styles in the To use this highlighter, associate regular expressions with styles in the
`ZSH_HIGHLIGHT_REGEXP` associative array, for example in `~/.zshrc`: `ZSH_HIGHLIGHT_REGEXP` associative array, for example in `~/.zshrc`:
```zsh
typeset -A ZSH_HIGHLIGHT_REGEXP
ZSH_HIGHLIGHT_REGEXP+=('^rm .*' fg=red,bold)
```
This will highlight lines that start with a call to the `rm` command.
The regular expressions flavour used is [PCRE][pcresyntax] when the
`RE_MATCH_PCRE` option is set and POSIX Extended Regular Expressions (ERE),
as implemented by the platform's C library, otherwise. For details on the
latter, see [the `zsh/regex` module's documentation][MAN_ZSH_REGEX] and the
`regcomp(3)` and `re_format(7)` manual pages on your system.
For instance, to highlight `sudo` only as a complete word, i.e., `sudo cmd`,
but not `sudoedit`, one might use:
* When the `RE_MATCH_PCRE` is set:
```zsh ```zsh
typeset -A ZSH_HIGHLIGHT_REGEXP typeset -A ZSH_HIGHLIGHT_REGEXP
ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' fg=123,bold) ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' fg=123,bold)
``` ```
This will highlight "sudo" only as a complete word, i.e., "sudo cmd", but not * When the `RE_MATCH_PCRE` is unset, on platforms with GNU `libc` (e.g., many GNU/Linux distributions):
"sudoedit"
```zsh
typeset -A ZSH_HIGHLIGHT_REGEXP
ZSH_HIGHLIGHT_REGEXP+=('\<sudo\>' fg=123,bold)
```
* When the `RE_MATCH_PCRE` is unset, on BSD-based platforms (e.g., macOS):
```zsh
typeset -A ZSH_HIGHLIGHT_REGEXP
ZSH_HIGHLIGHT_REGEXP+=('[[:<:]]sudo[[:>:]]' fg=123,bold)
```
Note, however, that PCRE and POSIX ERE have a large common subset:
for instance, the regular expressions `[abc]`, `a*`, and `(a|b)` have the same
meaning in both flavours.
The syntax for values is the same as the syntax of "types of highlighting" of The syntax for values is the same as the syntax of "types of highlighting" of
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
@ -25,6 +58,8 @@ manual page][zshzle-Character-Highlighting].
See also: [regular expressions tutorial][perlretut], zsh regexp operator `=~` See also: [regular expressions tutorial][perlretut], zsh regexp operator `=~`
in [the `zshmisc(1)` manual page][zshmisc-Conditional-Expressions] in [the `zshmisc(1)` manual page][zshmisc-Conditional-Expressions]
[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
[perlretut]: http://perldoc.perl.org/perlretut.html [perlretut]: https://perldoc.perl.org/perlretut
[zshmisc-Conditional-Expressions]: http://zsh.sourceforge.net/Doc/Release/Conditional-Expressions.html#Conditional-Expressions [zshmisc-Conditional-Expressions]: https://zsh.sourceforge.io/Doc/Release/Conditional-Expressions.html#Conditional-Expressions
[MAN_ZSH_REGEX]: https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-zsh_002fregex-Module
[pcresyntax]: https://www.pcre.org/original/doc/html/pcresyntax.html

View File

@ -22,4 +22,4 @@ The syntax for values is the same as the syntax of "types of highlighting" of
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
manual page][zshzle-Character-Highlighting]. manual page][zshzle-Character-Highlighting].
[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting

View File

@ -76,7 +76,7 @@ _zsh_highlight_main_add_region_highlight() {
integer start=$1 end=$2 integer start=$1 end=$2
shift 2 shift 2
if (( in_alias )); then if (( $#in_alias )); then
[[ $1 == unknown-token ]] && alias_style=unknown-token [[ $1 == unknown-token ]] && alias_style=unknown-token
return return
fi fi
@ -254,10 +254,9 @@ _zsh_highlight_main__is_runnable() {
_zsh_highlight_main__is_redirection() { _zsh_highlight_main__is_redirection() {
# A redirection operator token: # A redirection operator token:
# - starts with an optional single-digit number; # - starts with an optional single-digit number;
# - then, has a '<' or '>' character; # - is one of the tokens listed in zshmisc(1)
# - is not a process substitution [<(...) or >(...)]. # - however (z) normalizes ! to |
# - is not a numeric glob <-> [[ ${1#[0-9]} == (\<|\<\>|(\>|\>\>)(|\|)|\<\<(|-)|\<\<\<|\<\&|\&\<|(\>|\>\>)\&(|\|)|\&(\>|\>\>)(|\||\!)) ]]
[[ $1 == (<0-9>|)(\<|\>)* ]] && [[ $1 != (\<|\>)$'\x28'* ]] && [[ $1 != *'<'*'-'*'>'* ]]
} }
# Resolve alias. # Resolve alias.
@ -349,6 +348,7 @@ _zsh_highlight_highlighter_main_paint()
'noglob' '' 'noglob' ''
# 'time' and 'nocorrect' shouldn't be added here; they're reserved words, not precommands. # 'time' and 'nocorrect' shouldn't be added here; they're reserved words, not precommands.
# miscellaneous commands
'doas' aCu:Lns # as of OpenBSD's doas(1) dated September 4, 2016 'doas' aCu:Lns # as of OpenBSD's doas(1) dated September 4, 2016
'nice' n: # as of current POSIX spec 'nice' n: # as of current POSIX spec
'pkexec' '' # doesn't take short options; immune to #121 because it's usually not passed --option flags 'pkexec' '' # doesn't take short options; immune to #121 because it's usually not passed --option flags
@ -362,21 +362,21 @@ _zsh_highlight_highlighter_main_paint()
'env' u:i 'env' u:i
'ionice' cn:t:pPu # util-linux 2.33.1-0.1 'ionice' cn:t:pPu # util-linux 2.33.1-0.1
'strace' IbeaosXPpEuOS:ACdfhikqrtTvVxyDc # strace 4.26-0.2 'strace' IbeaosXPpEuOS:ACdfhikqrtTvVxyDc # strace 4.26-0.2
'proxychains' f:q # proxychains 4.4.0
# As of OpenSSH 8.1p1 'torsocks' idq:upaP # Torsocks 2.3.0
'ssh-agent' aEPt:csDd:k 'torify' idq:upaP # Torsocks 2.3.0
# suckless-tools v44 'ssh-agent' aEPt:csDd:k # As of OpenSSH 8.1p1
# Argumentless flags that can't be followed by a command: -v 'tabbed' gnprtTuU:cdfhs:v # suckless-tools v44
'tabbed' gnprtTuU:cdfhs 'chronic' :ev # moreutils 0.62-1
'ifne' :n # moreutils 0.62-1
# moreutils 0.62-1 'grc' :se # grc - a "generic colouriser" (that's their spelling, not mine)
'chronic' :ev 'cpulimit' elp:ivz # cpulimit 0.2
'ifne' :n 'ktrace' fgpt:aBCcdiT
) )
# Commands that would need to skip one positional argument: # Commands that would need to skip one positional argument:
# flock # flock
# ssh # ssh
# _wanted (skip two)
if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then
local right_brace_is_recognised_everywhere=false local right_brace_is_recognised_everywhere=false
@ -476,7 +476,11 @@ _zsh_highlight_main_highlighter__try_expand_parameter()
;; ;;
(*) (*)
# scalar, presumably # scalar, presumably
if [[ $zsyh_user_options[shwordsplit] == on ]]; then
words=( ${(P)=MATCH} )
else
words=( ${(P)MATCH} ) words=( ${(P)MATCH} )
fi
;; ;;
esac esac
reply=( "${words[@]}" ) reply=( "${words[@]}" )
@ -498,17 +502,18 @@ _zsh_highlight_main_highlighter__try_expand_parameter()
_zsh_highlight_main_highlighter_highlight_list() _zsh_highlight_main_highlighter_highlight_list()
{ {
integer start_pos end_pos=0 buf_offset=$1 has_end=$3 integer start_pos end_pos=0 buf_offset=$1 has_end=$3
# alias_style is the style to apply to an alias once in_alias=0 # alias_style is the style to apply to an alias once $#in_alias == 0
# Usually 'alias' but set to 'unknown-token' if any word expanded from # Usually 'alias' but set to 'unknown-token' if any word expanded from
# the alias would be highlighted as unknown-token # the alias would be highlighted as unknown-token
# param_style is analogous for parameter expansions # param_style is analogous for parameter expansions
local alias_style param_style last_arg arg buf=$4 highlight_glob=true saw_assignment=false style local alias_style param_style last_arg arg buf=$4 highlight_glob=true saw_assignment=false style
local in_array_assignment=false # true between 'a=(' and the matching ')' local in_array_assignment=false # true between 'a=(' and the matching ')'
# in_alias is equal to the number of shifts needed until arg=args[1] pops an # in_alias is an array of integers with each element equal to the number
# arg from BUFFER and not added by an alias. # of shifts needed until arg=args[1] pops an arg from the next level up
# alias or from BUFFER.
# in_param is analogous for parameter expansions # in_param is analogous for parameter expansions
integer in_alias=0 in_param=0 len=$#buf integer in_param=0 len=$#buf
local -a match mbegin mend list_highlights local -a in_alias match mbegin mend list_highlights
# seen_alias is a map of aliases already seen to avoid loops like alias a=b b=a # seen_alias is a map of aliases already seen to avoid loops like alias a=b b=a
local -A seen_alias local -A seen_alias
# Pattern for parameter names # Pattern for parameter names
@ -596,12 +601,23 @@ _zsh_highlight_main_highlighter_highlight_list()
last_arg=$arg last_arg=$arg
arg=$args[1] arg=$args[1]
shift args shift args
if (( in_alias )); then if (( $#in_alias )); then
(( in_alias-- )) (( in_alias[1]-- ))
if (( in_alias == 0 )); then # Remove leading 0 entries
in_alias=($in_alias[$in_alias[(i)<1->],-1])
if (( $#in_alias == 0 )); then
seen_alias=() seen_alias=()
# start_pos and end_pos are of the alias (previous $arg) here # start_pos and end_pos are of the alias (previous $arg) here
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
else
# We can't unset keys that contain special characters (] \ and some others).
# More details: https://www.zsh.org/workers/43269
(){
local alias_name
for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do
seen_alias=("${(@kv)seen_alias[(I)^$alias_name]}")
done
}
fi fi
fi fi
if (( in_param )); then if (( in_param )); then
@ -637,9 +653,9 @@ _zsh_highlight_main_highlighter_highlight_list()
fi fi
fi fi
if (( in_alias == 0 && in_param == 0 )); then if (( $#in_alias == 0 && in_param == 0 )); then
# Compute the new $start_pos and $end_pos, skipping over whitespace in $buf. # Compute the new $start_pos and $end_pos, skipping over whitespace in $buf.
[[ "$proc_buf" = (#b)(#s)(([ $'\t']|[\\]$'\n')#)(?|)* ]] [[ "$proc_buf" = (#b)(#s)(''([ $'\t']|[\\]$'\n')#)(?|)* ]]
# The first, outer parenthesis # The first, outer parenthesis
integer offset="${#match[1]}" integer offset="${#match[1]}"
(( start_pos = end_pos + offset )) (( start_pos = end_pos + offset ))
@ -693,11 +709,10 @@ _zsh_highlight_main_highlighter_highlight_list()
if [[ $res == "alias" ]]; then if [[ $res == "alias" ]]; then
# Mark insane aliases as unknown-token (cf. #263). # Mark insane aliases as unknown-token (cf. #263).
if [[ $arg == ?*=* ]]; then if [[ $arg == ?*=* ]]; then
(( in_alias == 0 )) && in_alias=1
_zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token
continue continue
fi fi
seen_alias[$arg]=1 seen_alias[$arg]=$#in_alias
_zsh_highlight_main__resolve_alias $arg _zsh_highlight_main__resolve_alias $arg
local -a alias_args local -a alias_args
# Elision is desired in case alias x='' # Elision is desired in case alias x=''
@ -707,15 +722,15 @@ _zsh_highlight_main_highlighter_highlight_list()
alias_args=(${(z)REPLY}) alias_args=(${(z)REPLY})
fi fi
args=( $alias_args $args ) args=( $alias_args $args )
if (( in_alias == 0 )); then if (( $#in_alias == 0 )); then
alias_style=alias alias_style=alias
# Add one because we will in_alias-- on the next loop iteration so
# this iteration should be considered in in_alias as well
(( in_alias += $#alias_args + 1 ))
else else
# This arg is already included in the count, so no need to + 1. # Transfer the count of this arg to the new element about to be appended.
(( in_alias += $#alias_args )) (( in_alias[1]-- ))
fi fi
# Add one because we will in_alias[1]-- on the next loop iteration so
# this iteration should be considered in in_alias as well
in_alias=( $(($#alias_args + 1)) $in_alias )
(( in_redirection++ )) # Stall this arg (( in_redirection++ )) # Stall this arg
continue continue
else else
@ -728,7 +743,7 @@ _zsh_highlight_main_highlighter_highlight_list()
# Analyse the current word. # Analyse the current word.
if _zsh_highlight_main__is_redirection $arg ; then if _zsh_highlight_main__is_redirection $arg ; then
if (( in_redirection == 1 )); then if (( in_redirection == 1 )); then
# Two consecuive redirection operators is an error. # Two consecutive redirection operators is an error.
_zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token
else else
in_redirection=2 in_redirection=2
@ -854,7 +869,7 @@ _zsh_highlight_main_highlighter_highlight_list()
style=commandseparator style=commandseparator
elif [[ $this_word == *':start:'* ]] && [[ $arg == $'\n' ]]; then elif [[ $this_word == *':start:'* ]] && [[ $arg == $'\n' ]]; then
style=commandseparator style=commandseparator
elif [[ $this_word == *':start:'* ]] && [[ $arg == ';' ]] && (( in_alias )); then elif [[ $this_word == *':start:'* ]] && [[ $arg == ';' ]] && (( $#in_alias )); then
style=commandseparator style=commandseparator
else else
# Empty commands (semicolon follows nothing) are valid syntax. # Empty commands (semicolon follows nothing) are valid syntax.
@ -879,6 +894,14 @@ _zsh_highlight_main_highlighter_highlight_list()
next_word=':start:' next_word=':start:'
highlight_glob=true highlight_glob=true
saw_assignment=false saw_assignment=false
(){
local alias_name
for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do
# We can't unset keys that contain special characters (] \ and some others).
# More details: https://www.zsh.org/workers/43269
seen_alias=("${(@kv)seen_alias[(I)^$alias_name]}")
done
}
if [[ $arg != '|' && $arg != '|&' ]]; then if [[ $arg != '|' && $arg != '|&' ]]; then
next_word+=':start_of_pipeline:' next_word+=':start_of_pipeline:'
fi fi
@ -902,8 +925,8 @@ _zsh_highlight_main_highlighter_highlight_list()
next_word=${next_word//:regular:/} next_word=${next_word//:regular:/}
next_word+=':sudo_opt:' next_word+=':sudo_opt:'
next_word+=':start:' next_word+=':start:'
if [[ $arg == 'exec' ]]; then if [[ $arg == 'exec' || $arg == 'env' ]]; then
# To allow "exec 2>&1;" where there's no command word # To allow "exec 2>&1;" and "env | grep" where there's no command word
next_word+=':regular:' next_word+=':regular:'
fi fi
else else
@ -1146,7 +1169,7 @@ _zsh_highlight_main_highlighter_highlight_list()
fi fi
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
done done
(( in_alias == 1 )) && in_alias=0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style (( $#in_alias )) && in_alias=() _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
(( in_param == 1 )) && in_param=0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $param_style (( in_param == 1 )) && in_param=0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $param_style
[[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\$'\n')#) ]] [[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\$'\n')#) ]]
REPLY=$(( end_pos + ${#match[1]} - 1 )) REPLY=$(( end_pos + ${#match[1]} - 1 ))
@ -1257,7 +1280,7 @@ _zsh_highlight_main_highlighter_check_path()
# If this word ends the buffer, check if it's the prefix of a valid path. # If this word ends the buffer, check if it's the prefix of a valid path.
if (( has_end && (len == end_pos) )) && if (( has_end && (len == end_pos) )) &&
(( ! in_alias )) && (( ! $#in_alias )) &&
[[ $WIDGET != zle-line-finish ]]; then [[ $WIDGET != zle-line-finish ]]; then
# TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here. # TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here.
local -a tmp local -a tmp

View File

@ -0,0 +1,41 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2021 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
# -------------------------------------------------------------------------------------------------
# Have to use cat here as it must be a command that exists.
# Otherwise, the test would fail with the first token being recognized
# as an "unknown-token".
alias ]=cat
BUFFER='] /'
expected_region_highlight=(
'1 1 alias' # ]
'3 3 path' # /
)

View File

@ -0,0 +1,39 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2020 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
# -------------------------------------------------------------------------------------------------
alias a=: b='a | a'
BUFFER='b | b'
expected_region_highlight=(
'1 1 alias' # b
'3 3 commandseparator' # |
'5 5 alias' # b
)

View File

@ -0,0 +1,39 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2020 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
# -------------------------------------------------------------------------------------------------
alias a=: b='a && a'
BUFFER='b && b'
expected_region_highlight=(
'1 1 alias' # b
'3 4 commandseparator' # &&
'6 6 alias' # b
)

View File

@ -0,0 +1,39 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2020 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
# -------------------------------------------------------------------------------------------------
alias a=: b='a; a'
BUFFER='b; b'
expected_region_highlight=(
'1 1 alias' # b
'2 2 commandseparator' # ;
'4 4 alias' # b
)

View File

@ -0,0 +1,42 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2020 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
# -------------------------------------------------------------------------------------------------
alias a=: b='a $(a)'
BUFFER='b $(b)'
expected_region_highlight=(
'1 1 alias' # b
'3 6 default' # $(b)
'3 6 command-substitution-unquoted' # $(b)
'3 4 command-substitution-delimiter-unquoted' # $(
'5 5 alias' # b
'6 6 command-substitution-delimiter-unquoted' # )
)

View File

@ -0,0 +1,43 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2020 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
# -------------------------------------------------------------------------------------------------
alias a=: b='a < <(a)'
BUFFER='b < <(b)'
expected_region_highlight=(
'1 1 alias' # b
'3 3 redirection' # <
'5 8 default' # <(b)
'5 8 process-substitution' # <(b)
'5 6 process-substitution-delimiter' # <(
'7 7 alias' # b
'8 8 process-substitution-delimiter' # )
)

View File

@ -0,0 +1,37 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2020 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
# -------------------------------------------------------------------------------------------------
alias cat='cat | cat'
BUFFER='cat'
expected_region_highlight=(
'1 3 alias' # cat
)

View File

@ -0,0 +1,38 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2022 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=$'{ a=42 }'
expected_region_highlight=(
'1 1 reserved-word' # {
'3 6 assign' # a=42
'5 6 default' # 42
'8 8 reserved word "issue #854"' # }
)

View File

@ -27,7 +27,7 @@
# vim: ft=zsh sw=2 ts=2 et # 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=( expected_region_highlight=(
"1 2 command" # ps "1 2 command" # ps

View File

@ -0,0 +1,38 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2021 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=$'env | grep $needle'
expected_region_highlight=(
'1 3 precommand' # env
'5 5 commandseparator' # |
'7 10 command' # grep
'12 18 default' # $needle
)

View File

@ -36,5 +36,5 @@ ed() { command ed "$@" }
BUFFER=$'$EDITOR' BUFFER=$'$EDITOR'
expected_region_highlight=( expected_region_highlight=(
'1 7 function "issue #687"' # $EDITOR '1 7 function' # $EDITOR
) )

View File

@ -0,0 +1,38 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2021 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
# -------------------------------------------------------------------------------------------------
setopt sh_word_split
local foo='echo foo'
BUFFER='$foo'
expected_region_highlight=(
'1 4 builtin' # $foo
)

View File

@ -28,8 +28,12 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
alias -g x=y if type global_alias >/dev/null; then
local s=x skip_test="Test is written on the assumption that 'global_alias' is not a valid command name, but that assumption does not hold"
return 0
fi
alias -g global_alias=y
local s=global_alias
BUFFER=$'$s' BUFFER=$'$s'

View File

@ -29,11 +29,12 @@
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
hash sudo=false hash sudo=false
touch foo
BUFFER='sudo -e /etc/passwd' BUFFER='sudo -e ./foo'
expected_region_highlight=( expected_region_highlight=(
'1 4 precommand' # sudo '1 4 precommand' # sudo
'6 7 single-hyphen-option' # -e '6 7 single-hyphen-option' # -e
'9 19 path' # /etc/passwd '9 13 path' # ./foo
) )

View File

@ -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
)

View File

@ -27,7 +27,7 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
BUFFER='ps aux | grep java' BUFFER='id bob | grep java'
expected_region_highlight=( expected_region_highlight=(
"1 2 command" # ps "1 2 command" # ps

View File

@ -1,11 +1,12 @@
# Release procedure (for developers): # Release procedure (for developers):
- Ensure every `is-at-least` invocation passes a stable zsh release's version number as the first argument
- For minor (A.B.0) releases: - For minor (A.B.0) releases:
- Check whether the release uses any not-yet-released zsh features - Check whether the release uses any not-yet-released zsh features
- Check open issues and outstanding pull requests - Check open issues and outstanding pull requests
- Confirm `make test` passes - Confirm `make test` passes
- check with multiple zsh versions - check with multiple zsh versions
(easiest to check travis: https://travis-ci.org/zsh-users/zsh-syntax-highlighting/) (easiest to check GitHub Actions: https://github.com/zsh-users/zsh-syntax-highlighting/actions)
- Update changelog.md - Update changelog.md
`tig --abbrev=12 --abbrev-commit 0.4.1..upstream/master` `tig --abbrev=12 --abbrev-commit 0.4.1..upstream/master`
- Make sure there are no local commits and that `git status` is clean; - Make sure there are no local commits and that `git status` is clean;

View File

@ -104,7 +104,7 @@ By default, the results of all tests will be printed; to show only "interesting"
results (tests that failed but were expected to succeed, or vice-versa), run results (tests that failed but were expected to succeed, or vice-versa), run
`make quiet-test` (or `make test QUIET=y`). `make quiet-test` (or `make test QUIET=y`).
[TAP]: http://testanything.org/ [TAP]: https://testanything.org/
Performance test Performance test

View File

@ -31,6 +31,9 @@
emulate -LR zsh emulate -LR zsh
setopt localoptions extendedglob setopt localoptions extendedglob
# Required for add-zle-hook-widget.
zmodload zsh/zle
# Argument parsing. # Argument parsing.
if (( $# * $# - 7 * $# + 12 )) || [[ $1 == -* ]]; then if (( $# * $# - 7 * $# + 12 )) || [[ $1 == -* ]]; then
print -r -- >&2 "$0: usage: $0 BUFFER HIGHLIGHTER BASENAME [PREAMBLE]" print -r -- >&2 "$0: usage: $0 BUFFER HIGHLIGHTER BASENAME [PREAMBLE]"

View File

@ -31,6 +31,9 @@
setopt NO_UNSET WARN_CREATE_GLOBAL setopt NO_UNSET WARN_CREATE_GLOBAL
# Required for add-zle-hook-widget.
zmodload zsh/zle
local -r root=${0:h:h} local -r root=${0:h:h}
local -a anon_argv; anon_argv=("$@") local -a anon_argv; anon_argv=("$@")

View File

@ -29,6 +29,9 @@
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
# Required for add-zle-hook-widget.
zmodload zsh/zle
# Check an highlighter was given as argument. # Check an highlighter was given as argument.
[[ -n "$1" ]] || { [[ -n "$1" ]] || {
echo >&2 "Bail out! You must provide the name of a valid highlighter as argument." echo >&2 "Bail out! You must provide the name of a valid highlighter as argument."

View File

@ -49,12 +49,58 @@ if true; then
fi fi
fi fi
# This function takes a single argument F and returns True iff F is an autoload stub.
_zsh_highlight__function_is_autoload_stub_p() {
if zmodload -e zsh/parameter; then
#(( ${+functions[$1]} )) &&
[[ "$functions[$1]" == *"builtin autoload -X"* ]]
else
#[[ $(type -wa -- "$1") == *'function'* ]] &&
[[ "${${(@f)"$(which -- "$1")"}[2]}" == $'\t'$histchars[3]' undefined' ]]
fi
# Do nothing here: return the exit code of the if.
}
# Return True iff the argument denotes a function name.
_zsh_highlight__is_function_p() {
if zmodload -e zsh/parameter; then
(( ${+functions[$1]} ))
else
[[ $(type -wa -- "$1") == *'function'* ]]
fi
}
# This function takes a single argument F and returns True iff F denotes the
# name of a callable function. A function is callable if it is fully defined
# or if it is marked for autoloading and autoloading it at the first call to it
# will succeed. In particular, if F has been marked for autoloading
# but is not available in $fpath, then calling this function on F will return False.
#
# See users/21671 https://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=21671
_zsh_highlight__function_callable_p() {
if _zsh_highlight__is_function_p "$1" &&
! _zsh_highlight__function_is_autoload_stub_p "$1"
then
# Already fully loaded.
return 0 # true
else
# "$1" is either an autoload stub, or not a function at all.
#
# Use a subshell to avoid affecting the calling shell.
#
# We expect 'autoload +X' to return non-zero if it fails to fully load
# the function.
( autoload -U +X -- "$1" 2>/dev/null )
return $?
fi
}
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
# Core highlighting update system # Core highlighting update system
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
# Use workaround for bug in ZSH? # Use workaround for bug in ZSH?
# zsh-users/zsh@48cadf4 http://www.zsh.org/mla/workers//2017/msg00034.html # zsh-users/zsh@48cadf4 https://www.zsh.org/mla/workers/2017/msg00034.html
autoload -Uz is-at-least autoload -Uz is-at-least
if is-at-least 5.4; then if is-at-least 5.4; then
typeset -g zsh_highlight__pat_static_bug=false typeset -g zsh_highlight__pat_static_bug=false
@ -77,7 +123,7 @@ _zsh_highlight()
typeset -r ret typeset -r ret
# $region_highlight should be predefined, either by zle or by the test suite's mock (non-special) array. # $region_highlight should be predefined, either by zle or by the test suite's mock (non-special) array.
(( ${+region_highlight} )) || { (( ${+region_highlight[@]} )) || {
echo >&2 'zsh-syntax-highlighting: error: $region_highlight is not defined' echo >&2 'zsh-syntax-highlighting: error: $region_highlight is not defined'
echo >&2 'zsh-syntax-highlighting: (Check whether zsh-syntax-highlighting was installed according to the instructions.)' echo >&2 'zsh-syntax-highlighting: (Check whether zsh-syntax-highlighting was installed according to the instructions.)'
return $ret return $ret
@ -109,15 +155,7 @@ _zsh_highlight()
# C structs, so that none of the previous case patterns will match. # C structs, so that none of the previous case patterns will match.
# #
# In either case, fall back to a version check. # In either case, fall back to a version check.
# if is-at-least 5.9; then
# The memo= feature was added to zsh in commit zsh-5.8-172-gdd6e702ee.
# The version number at the time was 5.8.0.2-dev (see Config/version.mk).
# Therefore, on 5.8.0.3 and newer the memo= feature is available.
#
# On zsh version 5.8.0.2 between the aforementioned commit and the
# first Config/version.mk bump after it (which, at the time of writing,
# is yet to come), this condition will false negative.
if is-at-least 5.8.0.3; then
integer -gr zsh_highlight__memo_feature=1 integer -gr zsh_highlight__memo_feature=1
else else
integer -gr zsh_highlight__memo_feature=0 integer -gr zsh_highlight__memo_feature=0
@ -173,7 +211,8 @@ _zsh_highlight()
[[ -n ${ZSH_HIGHLIGHT_MAXLENGTH:-} ]] && [[ $#BUFFER -gt $ZSH_HIGHLIGHT_MAXLENGTH ]] && return $ret [[ -n ${ZSH_HIGHLIGHT_MAXLENGTH:-} ]] && [[ $#BUFFER -gt $ZSH_HIGHLIGHT_MAXLENGTH ]] && return $ret
# Do not highlight if there are pending inputs (copy/paste). # Do not highlight if there are pending inputs (copy/paste).
[[ $PENDING -gt 0 ]] && return $ret (( KEYS_QUEUED_COUNT > 0 )) && return $ret
(( PENDING > 0 )) && return $ret
{ {
local cache_place local cache_place
@ -351,6 +390,46 @@ _zsh_highlight_call_widget()
_zsh_highlight _zsh_highlight
} }
# Decide whether to use the zle-line-pre-redraw codepath (colloquially known as
# "feature/redrawhook", after the topic branch's name) or the legacy "bind all
# widgets" codepath.
#
# We use the new codepath under two conditions:
#
# 1. If it's available, which we check by testing for add-zle-hook-widget's availability.
#
# 2. If zsh has the memo= feature, which is required for interoperability reasons.
# See issues #579 and #735, and the issues referenced from them.
#
# We check this with a plain version number check, since a functional check,
# as done by _zsh_highlight, can only be done from inside a widget
# function — a catch-22.
if is-at-least 5.9 && _zsh_highlight__function_callable_p add-zle-hook-widget
then
autoload -U add-zle-hook-widget
_zsh_highlight__zle-line-finish() {
# Reset $WIDGET since the 'main' highlighter depends on it.
#
# Since $WIDGET is declared by zle as read-only in this function's scope,
# a nested function is required in order to shadow its built-in value;
# see "User-defined widgets" in zshall.
() {
local -h -r WIDGET=zle-line-finish
_zsh_highlight
}
}
_zsh_highlight__zle-line-pre-redraw() {
# Set $? to 0 for _zsh_highlight. Without this, subsequent
# zle-line-pre-redraw hooks won't run, since add-zle-hook-widget happens to
# call us with $? == 1 in the common case.
true && _zsh_highlight "$@"
}
_zsh_highlight_bind_widgets(){}
if [[ -o zle ]]; then
add-zle-hook-widget zle-line-pre-redraw _zsh_highlight__zle-line-pre-redraw
add-zle-hook-widget zle-line-finish _zsh_highlight__zle-line-finish
fi
else
# Rebind all ZLE widgets to make them invoke _zsh_highlights. # Rebind all ZLE widgets to make them invoke _zsh_highlights.
_zsh_highlight_bind_widgets() _zsh_highlight_bind_widgets()
{ {
@ -417,6 +496,7 @@ _zsh_highlight_bind_widgets()
esac esac
done done
} }
fi
# Load highlighters from directory. # Load highlighters from directory.
# #