From 2819a9de56ac9693b84277e247de4e3d430d30b5 Mon Sep 17 00:00:00 2001 From: lhark Date: Sat, 7 Nov 2015 18:09:26 +0100 Subject: [PATCH] Add zsh-syntax-highlighting --- zsh-syntax-highlighting/.gitattributes | 1 + zsh-syntax-highlighting/.gitignore | 2 + zsh-syntax-highlighting/.revision-hash | 1 + zsh-syntax-highlighting/.version | 1 + zsh-syntax-highlighting/COPYING.md | 23 + zsh-syntax-highlighting/Makefile | 43 ++ zsh-syntax-highlighting/README.md | 89 ++++ zsh-syntax-highlighting/changelog.md | 212 ++++++++ .../highlighters/README.md | 50 ++ .../highlighters/brackets/README.md | 30 ++ .../brackets/brackets-highlighter.zsh | 110 ++++ .../test-data/mismatch-patentheses.zsh | 37 ++ .../brackets/test-data/nested-parentheses.zsh | 39 ++ .../brackets/test-data/quoted-patentheses.zsh | 34 ++ .../brackets/test-data/simple-parentheses.zsh | 37 ++ .../test-data/unclosed-patentheses.zsh | 36 ++ .../test-data/unclosed-patentheses2.zsh | 36 ++ .../highlighters/cursor/README.md | 24 + .../cursor/cursor-highlighter.zsh | 44 ++ .../highlighters/line/README.md | 24 + .../highlighters/line/line-highlighter.zsh | 44 ++ .../highlighters/main/README.md | 68 +++ .../highlighters/main/main-highlighter.zsh | 494 ++++++++++++++++++ .../highlighters/main/test-data/alias.zsh | 51 ++ .../main/test-data/anonymous-function.zsh | 40 ++ .../main/test-data/arithmetic-evaluation.zsh | 40 ++ .../main/test-data/assign-append.zsh | 35 ++ .../main/test-data/assign-semicolon.zsh | 36 ++ .../highlighters/main/test-data/assign.zsh | 36 ++ .../main/test-data/back-quoted-argument.zsh | 35 ++ .../main/test-data/backslash-continuation.zsh | 35 ++ .../main/test-data/commandseparator.zsh | 37 ++ .../main/test-data/comment-leading.zsh | 38 ++ .../main/test-data/comment-off.zsh | 39 ++ .../highlighters/main/test-data/comments.zsh | 39 ++ .../main/test-data/control-flow.zsh | 51 ++ .../main/test-data/dollar-quoted.zsh | 36 ++ .../main/test-data/dollar-quoted2.zsh | 41 ++ .../main/test-data/dollar-quoted3.zsh | 38 ++ .../main/test-data/double-hyphen-option.zsh | 35 ++ .../main/test-data/double-quoted.zsh | 45 ++ .../main/test-data/double-quoted2.zsh | 37 ++ .../main/test-data/double-quoted3.zsh | 39 ++ .../main/test-data/empty-command.zsh | 35 ++ .../highlighters/main/test-data/function.zsh | 47 ++ .../highlighters/main/test-data/glob.zsh | 38 ++ .../main/test-data/hashed-command.zsh | 36 ++ .../main/test-data/history-expansion.zsh | 36 ++ .../main/test-data/history-expansion2.zsh | 34 ++ .../main/test-data/multiline-string.zsh | 36 ++ .../main/test-data/multiline-string2.zsh | 35 ++ .../main/test-data/multiple-redirections.zsh | 46 ++ .../main/test-data/noglob-alias.zsh | 35 ++ .../highlighters/main/test-data/noglob1.zsh | 34 ++ .../highlighters/main/test-data/noglob2.zsh | 35 ++ .../main/test-data/path-space- .zsh | 35 ++ .../main/test-data/path-tilde-home.zsh | 36 ++ .../main/test-data/path-tilde-home2.zsh | 37 ++ .../main/test-data/path-tilde-named.zsh | 37 ++ .../highlighters/main/test-data/path.zsh | 35 ++ .../main/test-data/path_prefix.zsh | 38 ++ .../main/test-data/path_prefix2.zsh | 39 ++ .../main/test-data/precommand.zsh | 37 ++ .../main/test-data/prefix-redirection.zsh | 39 ++ .../main/test-data/redirection.zsh | 37 ++ .../main/test-data/reserved-word.zsh | 38 ++ .../main/test-data/simple-command.zsh | 34 ++ .../main/test-data/simple-redirection.zsh | 38 ++ .../highlighters/main/test-data/subshell.zsh | 41 ++ .../main/test-data/sudo-command.zsh | 47 ++ .../main/test-data/sudo-comment.zsh | 38 ++ .../main/test-data/sudo-redirection.zsh | 46 ++ .../main/test-data/sudo-redirection2.zsh | 39 ++ .../main/test-data/tilde-command-word.zsh | 37 ++ .../main/test-data/unbackslash.zsh | 35 ++ .../main/test-data/unknown-command.zsh | 34 ++ .../main/test-data/vanilla-newline.zsh | 39 ++ .../highlighters/pattern/README.md | 21 + .../pattern/pattern-highlighter.zsh | 60 +++ .../highlighters/root/README.md | 24 + .../highlighters/root/root-highlighter.zsh | 44 ++ .../images/preview-smaller.png | Bin 0 -> 5982 bytes zsh-syntax-highlighting/images/preview.png | Bin 0 -> 14650 bytes zsh-syntax-highlighting/release.md | 15 + zsh-syntax-highlighting/tests/README.md | 38 ++ .../tests/tap-colorizer.zsh | 67 +++ .../tests/test-highlighting.zsh | 118 +++++ zsh-syntax-highlighting/tests/test-perfs.zsh | 75 +++ .../zsh-syntax-highlighting.plugin.zsh | 1 + .../zsh-syntax-highlighting.zsh | 281 ++++++++++ 90 files changed, 4289 insertions(+) create mode 100644 zsh-syntax-highlighting/.gitattributes create mode 100644 zsh-syntax-highlighting/.gitignore create mode 100644 zsh-syntax-highlighting/.revision-hash create mode 100644 zsh-syntax-highlighting/.version create mode 100644 zsh-syntax-highlighting/COPYING.md create mode 100644 zsh-syntax-highlighting/Makefile create mode 100644 zsh-syntax-highlighting/README.md create mode 100644 zsh-syntax-highlighting/changelog.md create mode 100644 zsh-syntax-highlighting/highlighters/README.md create mode 100644 zsh-syntax-highlighting/highlighters/brackets/README.md create mode 100644 zsh-syntax-highlighting/highlighters/brackets/brackets-highlighter.zsh create mode 100644 zsh-syntax-highlighting/highlighters/brackets/test-data/mismatch-patentheses.zsh create mode 100644 zsh-syntax-highlighting/highlighters/brackets/test-data/nested-parentheses.zsh create mode 100644 zsh-syntax-highlighting/highlighters/brackets/test-data/quoted-patentheses.zsh create mode 100644 zsh-syntax-highlighting/highlighters/brackets/test-data/simple-parentheses.zsh create mode 100644 zsh-syntax-highlighting/highlighters/brackets/test-data/unclosed-patentheses.zsh create mode 100644 zsh-syntax-highlighting/highlighters/brackets/test-data/unclosed-patentheses2.zsh create mode 100644 zsh-syntax-highlighting/highlighters/cursor/README.md create mode 100644 zsh-syntax-highlighting/highlighters/cursor/cursor-highlighter.zsh create mode 100644 zsh-syntax-highlighting/highlighters/line/README.md create mode 100644 zsh-syntax-highlighting/highlighters/line/line-highlighter.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/README.md create mode 100644 zsh-syntax-highlighting/highlighters/main/main-highlighter.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/alias.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/anonymous-function.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/arithmetic-evaluation.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/assign-append.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/assign-semicolon.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/assign.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/back-quoted-argument.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/backslash-continuation.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/commandseparator.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/comment-leading.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/comment-off.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/comments.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/control-flow.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/dollar-quoted.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/dollar-quoted2.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/dollar-quoted3.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/double-hyphen-option.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/double-quoted.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/double-quoted2.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/double-quoted3.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/empty-command.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/function.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/glob.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/hashed-command.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/history-expansion.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/history-expansion2.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/multiline-string.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/multiline-string2.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/multiple-redirections.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/noglob-alias.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/noglob1.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/noglob2.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/path-space- .zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/path-tilde-home.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/path-tilde-home2.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/path-tilde-named.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/path.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/path_prefix.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/path_prefix2.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/precommand.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/prefix-redirection.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/redirection.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/reserved-word.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/simple-command.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/simple-redirection.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/subshell.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/sudo-command.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/sudo-comment.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/sudo-redirection.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/sudo-redirection2.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/tilde-command-word.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/unbackslash.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/unknown-command.zsh create mode 100644 zsh-syntax-highlighting/highlighters/main/test-data/vanilla-newline.zsh create mode 100644 zsh-syntax-highlighting/highlighters/pattern/README.md create mode 100644 zsh-syntax-highlighting/highlighters/pattern/pattern-highlighter.zsh create mode 100644 zsh-syntax-highlighting/highlighters/root/README.md create mode 100644 zsh-syntax-highlighting/highlighters/root/root-highlighter.zsh create mode 100644 zsh-syntax-highlighting/images/preview-smaller.png create mode 100644 zsh-syntax-highlighting/images/preview.png create mode 100644 zsh-syntax-highlighting/release.md create mode 100644 zsh-syntax-highlighting/tests/README.md create mode 100755 zsh-syntax-highlighting/tests/tap-colorizer.zsh create mode 100755 zsh-syntax-highlighting/tests/test-highlighting.zsh create mode 100755 zsh-syntax-highlighting/tests/test-perfs.zsh create mode 120000 zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh create mode 100644 zsh-syntax-highlighting/zsh-syntax-highlighting.zsh diff --git a/zsh-syntax-highlighting/.gitattributes b/zsh-syntax-highlighting/.gitattributes new file mode 100644 index 0000000..715e624 --- /dev/null +++ b/zsh-syntax-highlighting/.gitattributes @@ -0,0 +1 @@ +.revision-hash export-subst diff --git a/zsh-syntax-highlighting/.gitignore b/zsh-syntax-highlighting/.gitignore new file mode 100644 index 0000000..fb2e708 --- /dev/null +++ b/zsh-syntax-highlighting/.gitignore @@ -0,0 +1,2 @@ +*.zwc* +.pc/ diff --git a/zsh-syntax-highlighting/.revision-hash b/zsh-syntax-highlighting/.revision-hash new file mode 100644 index 0000000..6828f88 --- /dev/null +++ b/zsh-syntax-highlighting/.revision-hash @@ -0,0 +1 @@ +$Format:%H$ diff --git a/zsh-syntax-highlighting/.version b/zsh-syntax-highlighting/.version new file mode 100644 index 0000000..746bd19 --- /dev/null +++ b/zsh-syntax-highlighting/.version @@ -0,0 +1 @@ +0.3.1-dev diff --git a/zsh-syntax-highlighting/COPYING.md b/zsh-syntax-highlighting/COPYING.md new file mode 100644 index 0000000..5512a0a --- /dev/null +++ b/zsh-syntax-highlighting/COPYING.md @@ -0,0 +1,23 @@ +Copyright (c) 2010-2015 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. diff --git a/zsh-syntax-highlighting/Makefile b/zsh-syntax-highlighting/Makefile new file mode 100644 index 0000000..e4fa163 --- /dev/null +++ b/zsh-syntax-highlighting/Makefile @@ -0,0 +1,43 @@ +NAME=zsh-syntax-highlighting + +INSTALL?=install -c +PREFIX?=/usr/local +SHARE_DIR=$(DESTDIR)$(PREFIX)/share/$(NAME) +ZSH?=zsh # zsh binary to run tests with + +# Have the default target do nothing. +all: + @ : + +install: + $(INSTALL) -d $(SHARE_DIR) + cp -r .version zsh-syntax-highlighting.zsh highlighters $(SHARE_DIR) + if [ x"true" = x"`git rev-parse --is-inside-work-tree 2>/dev/null`" ]; then \ + git rev-parse HEAD; \ + else \ + cat .revision-hash; \ + fi > $(SHARE_DIR)/.revision-hash + +test: + @result=0; \ + for test in highlighters/*; do \ + if [ -d $$test/test-data ]; then \ + echo "Running test $${test##*/}"; \ + $(ZSH) -f tests/test-highlighting.zsh "$${test##*/}"; \ + : $$(( result |= $$? )); \ + fi \ + done; \ + exit $$result + +perf: + @result=0; \ + for test in highlighters/*; do \ + if [ -d $$test/test-data ]; then \ + echo "Running test $${test##*/}"; \ + $(ZSH) -f tests/test-perfs.zsh "$${test##*/}"; \ + : $$(( result |= $$? )); \ + fi \ + done; \ + exit $$result + +.PHONY: all install test diff --git a/zsh-syntax-highlighting/README.md b/zsh-syntax-highlighting/README.md new file mode 100644 index 0000000..d7fc4ad --- /dev/null +++ b/zsh-syntax-highlighting/README.md @@ -0,0 +1,89 @@ +zsh-syntax-highlighting +======================= + +**[Fish shell](http://www.fishshell.com) like syntax highlighting for [Zsh](http://www.zsh.org).** + +*Requirements: zsh 4.3.17+.* + +This package provides syntax highlighing for the shell zsh. It enables +highlighing of commands whilst they are typed at a zsh prompt into an +interactive terminal. This helps in reviewing commands before running +them, particularly in catching syntax errors. + +[![Screenshot](images/preview-smaller.png)](images/preview.png) + + +How to install +-------------- + +### Using packages + +* Arch Linux: [community/zsh-syntax-highlighting](https://www.archlinux.org/packages/zsh-syntax-highlighting) / [AUR/zsh-syntax-highlighting-git](https://aur.archlinux.org/packages/zsh-syntax-highlighting-git) +* Gentoo: [mv overlay](http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting) +* Mac OS X / Homebrew: [brew install zsh-syntax-highlighting](https://github.com/Homebrew/homebrew/blob/master/Library/Formula/zsh-syntax-highlighting.rb) + +### In your ~/.zshrc + +* Clone this repository: + + git clone git://github.com/zsh-users/zsh-syntax-highlighting.git + + (or [download a snapshot](https://github.com/zsh-users/zsh-syntax-highlighting/archive/master.tar.gz)) + +* Source the script **at the end** of `~/.zshrc`: + + source /path/to/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh + +* Source `~/.zshrc` to take changes into account: + + source ~/.zshrc + + +### With oh-my-zsh + +* Download the script or clone this repository in [oh-my-zsh](http://github.com/robbyrussell/oh-my-zsh) plugins directory: + + git clone git://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting + +* Activate the plugin in `~/.zshrc`: + + plugins=( [plugins...] zsh-syntax-highlighting) + +* Source `~/.zshrc` to take changes into account: + + source ~/.zshrc + +Note that `zsh-syntax-highlighting` must be the last plugin sourced, +so make it the last element of the `$plugins` array. + +### System-wide installation + +Either of the above methods is suitable for a single-user installation, which requires +no special privileges. If, however, you desire to install zsh-syntax-highlighting +system-wide, you may do so by running `make install` and directing your users to +add `source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh` +in their `.zshrc`s. + + +FAQ +--- + +### 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 +custom widgets have been created (i.e., after all `zle -N` calls and after +running `compinit`). Widgets created later will work, but will not update the +syntax highlighting. + +### How are new releases announced? + +There is currently no "push" announcements channel. However, the following alternatives exist: + +- GitHub's RSS feed of releases: https://github.com/zsh-users/zsh-syntax-highlighting/releases.atom +- An anitya entry: https://release-monitoring.org/project/7552/ + +How to tweak +------------ + +Syntax highlighting is done by pluggable highlighter scripts, see the [highlighters directory](highlighters) +for documentation and configuration settings. diff --git a/zsh-syntax-highlighting/changelog.md b/zsh-syntax-highlighting/changelog.md new file mode 100644 index 0000000..dbffcde --- /dev/null +++ b/zsh-syntax-highlighting/changelog.md @@ -0,0 +1,212 @@ +up to c0dafd1d850e582291b41d693369794d1ea31343 + + + + +# Changes in version 0.3.1 + + +## Added highlighting of: + +- incomplete sudo commands + (a3047a912100, 2f05620b19ae) + + sudo; + sudo -u; + +- command words following reserved words + (#207, #222, b397b12ac139 et seq, 6fbd2aa9579b et seq, 8b4adbd991b0) + + if ls; then ls; else ls; fi + repeat 10 do ls; done + + (The `ls` are now highlighted as a command.) + +- comments (when `INTERACTIVE_COMMENTS` is set) + (#163, #167, 693de99a9030) + + echo Hello # comment + +- closing brackets of arithmetic expansion, subshells, and blocks + (#226, a59f442d2d34, et seq) + + (( foo )) + ( foo ) + { foo } + + +## Fixed highlighting of: + +- precommand modifiers at non-command-word position + (#209, 2c9f8c8c95fa) + + ls command foo + +- sudo commands with infix redirections + (#221, be006aded590, 86e924970911) + + sudo -u >/tmp/foo.out user ls + +- subshells; anonymous functions + (#166, #194, 0d1bfbcbfa67, 9e178f9f3948) + + (true) + () { true } + +- parameter assignment statements with no command + (#205, 01d7eeb3c713) + + A=1; + + (The semicolon used to be highlighted as a mistake) + + +## Removed features: + +- Removed highlighting of approximate paths (`path_approx`). + (#187, 98aee7f8b9a3) + + +## Other changes: + +- main highlighter refactored to use states rather than booleans. + (2080a441ac49, et seq) + +- Fix initialization when sourcing `zsh-syntax-highlighting.zsh` via a symlink + (083c47b00707) + +- docs: Add screenshot. + (57624bb9f64b) + +- widgets wrapping: Don't add '--' when invoking widgets. + (c808d2187a73) + +- Refresh highlighting upon `accept-*` widgets (`accept-line` et al). + (59fbdda64c21) + +- Stop leaking match/mbegin/mend to global scope (thanks to upstream + `WARN_CREATE_GLOBAL` improvements). + (d3deffbf46a4) + + +## Developer-visible changes: + +- Test harness converted to [TAP](http://testanything.org/tap-specification.html) format + (d99aa58aaaef, et seq) + +- Run each test in a separate subprocess, isolating them from each other + (d99aa58aaaef, et seq) + +- Fix test failure with nonexisting $HOME + (#216, b2ac98b98150) + +- Test output is now colorized. + (4d3da30f8b72, 6fe07c096109) + +- Document `make install` + (a18a7427fd2c) + +- tests: Allow specifying the zsh binary to use. + (557bb7e0c6a0) + +- tests: Add 'make perf' target + (4513eaea71d7) + + + +# Changes in version 0.3.0 + + +## Added highlighting of: + +- suffix aliases (requires zsh 5.1.1 or newer): + + alias -s png=display + foo.png + +- prefix redirections: + + foo.txt + +- arithmetic evaluations: + + (( 42 )) + +- $'' strings, including \x/\octal/\u/\U escapes + + : $'foo\u0040bar' + +- multiline strings: + + % echo "line 1 + line 2" + +- string literals that haven't been finished: + + % echo "Hello, world + +- command words that involve tilde expansion: + + % ~/bin/foo + + +## Fixed highlighting of: + +- quoted command words: + + % \ls + +- backslash escapes in "" strings: + + % echo "\x41" + +- noglob after command separator: + + % :; noglob echo * + +- glob after command separator, when the first command starts with 'noglob': + + % noglob true; echo * + +- the region (vi visual mode / set-mark-command) (issue #165) + +- redirection and command separators that would be highlighted as `path_approx` + + % echo foo;‸ + % echo <‸ + + (where `‸` represents the cursor location) + +- escaped globbing (outside quotes) + + % echo \* + + +## Other changes: + +- implemented compatibility with zsh's paste highlighting (issue #175) + +- `$?` propagated correctly to wrapped widgets + +- don't leak $REPLY into global scope + + +## Developer-visible changes: + +- added makefile with `install` and `test` targets + +- set `warn_create_global` internally + +- document release process + + + + +# Version 0.2.1 + +(Start of changelog.) + diff --git a/zsh-syntax-highlighting/highlighters/README.md b/zsh-syntax-highlighting/highlighters/README.md new file mode 100644 index 0000000..987cc83 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/README.md @@ -0,0 +1,50 @@ +zsh-syntax-highlighting / highlighters +====================================== + +Syntax highlighting is done by pluggable highlighters: + +* [***main***](main) - the base highlighter, and the only one active by default. +* [***brackets***](brackets) - matches brackets and parenthesis. +* [***pattern***](pattern) - matches user-defined patterns. +* [***cursor***](cursor) - matches the cursor position. +* [***root***](root) - triggered if the current user is root. +* [***line***](line) - applied to the whole command line + + +How to activate highlighters +---------------------------- + +To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array in `~/.zshrc`, for example: + + ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor) + + +How to tweak highlighters +------------------------- + +Highlighters look up styles from the `ZSH_HIGHLIGHT_STYLES` array. Navigate into each highlighter directory to see what styles it defines and how to configure it. + + +How to implement a new highlighter +---------------------------------- + +To create your own ***myhighlighter*** highlighter: + +* Create your script at **highlighters/*myhighlighter*/*myhighlighter*-highlighter.zsh**. +* Implement the `_zsh_highlight_myhighlighter_highlighter_predicate` function. This function must return 0 when the highlighter needs to be called, for example: + + _zsh_highlight_myhighlighter_highlighter_predicate() { + # Call this highlighter in SVN repositories + [[ -d .svn ]] + } + +* Implement the `_zsh_highlight_myhighlighter_highlighter` function. This function does the actual syntax highlighting, by modifying `region_highlight`, for example: + + _zsh_highlight_myhighlighter_highlighter() { + # Colorize the whole buffer with blue background + region_highlight+=(0 $#BUFFER bg=blue) + } + +* Activate your highlighter in `~/.zshrc`: + + ZSH_HIGHLIGHT_HIGHLIGHTERS+=(myhighlighter) diff --git a/zsh-syntax-highlighting/highlighters/brackets/README.md b/zsh-syntax-highlighting/highlighters/brackets/README.md new file mode 100644 index 0000000..9fd4f96 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/brackets/README.md @@ -0,0 +1,30 @@ +zsh-syntax-highlighting / highlighters / brackets +================================================= + +This is the ***brackets*** highlighter, that highlights brackets, parenthesis and matches them. + + +How to activate it +------------------ +To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: + + ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] brackets) + + +How to tweak it +--------------- +This highlighter defines the following styles: + +* `bracket-error` - unmatched brackets +* `bracket-level-N` - brackets with nest level N +* `cursor-matchingbracket` - the matching bracket, if cursor is on a bracket + +To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: + + # To define styles for nested brackets up to level 4 + ZSH_HIGHLIGHT_STYLES[bracket-level-1]='fg=blue,bold' + ZSH_HIGHLIGHT_STYLES[bracket-level-2]='fg=red,bold' + ZSH_HIGHLIGHT_STYLES[bracket-level-3]='fg=yellow,bold' + ZSH_HIGHLIGHT_STYLES[bracket-level-4]='fg=magenta,bold' + +The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/zsh-syntax-highlighting/highlighters/brackets/brackets-highlighter.zsh b/zsh-syntax-highlighting/highlighters/brackets/brackets-highlighter.zsh new file mode 100644 index 0000000..2b87a3e --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/brackets/brackets-highlighter.zsh @@ -0,0 +1,110 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 +# ------------------------------------------------------------------------------------------------- + + +# Define default styles. +: ${ZSH_HIGHLIGHT_STYLES[bracket-error]:=fg=red,bold} +: ${ZSH_HIGHLIGHT_STYLES[bracket-level-1]:=fg=blue,bold} +: ${ZSH_HIGHLIGHT_STYLES[bracket-level-2]:=fg=green,bold} +: ${ZSH_HIGHLIGHT_STYLES[bracket-level-3]:=fg=magenta,bold} +: ${ZSH_HIGHLIGHT_STYLES[bracket-level-4]:=fg=yellow,bold} +: ${ZSH_HIGHLIGHT_STYLES[bracket-level-5]:=fg=cyan,bold} +: ${ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket]:=standout} + +# Whether the brackets highlighter should be called or not. +_zsh_highlight_brackets_highlighter_predicate() +{ + _zsh_highlight_cursor_moved || _zsh_highlight_buffer_modified +} + +# Brackets highlighting function. +_zsh_highlight_brackets_highlighter() +{ + local level=0 pos + local -A levelpos lastoflevel matching typepos + region_highlight=() + + # Find all brackets and remember which one is matching + for (( pos = 0; $pos < ${#BUFFER}; pos++ )) ; do + local char="$BUFFER[pos+1]" + case $char in + ["([{"]) + levelpos[$pos]=$((++level)) + lastoflevel[$level]=$pos + _zsh_highlight_brackets_highlighter_brackettype "$char" + ;; + [")]}"]) + matching[$lastoflevel[$level]]=$pos + matching[$pos]=$lastoflevel[$level] + levelpos[$pos]=$((level--)) + _zsh_highlight_brackets_highlighter_brackettype "$char" + ;; + ['"'\']) + # Skip everything inside quotes + local quotetype=$char + while (( $pos < ${#BUFFER} )) ; do + (( pos++ )) + [[ $BUFFER[$pos+1] == $quotetype ]] && break + done + ;; + esac + done + + # Now highlight all found brackets + for pos in ${(k)levelpos}; do + if [[ -n $matching[$pos] ]] && [[ $typepos[$pos] == $typepos[$matching[$pos]] ]]; then + local bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]} + local bracket_color_level=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 )) + local style=$ZSH_HIGHLIGHT_STYLES[$bracket_color_level] + region_highlight+=("$pos $((pos + 1)) $style") + else + local style=$ZSH_HIGHLIGHT_STYLES[bracket-error] + region_highlight+=("$pos $((pos + 1)) $style") + fi + done + + # If cursor is on a bracket, then highlight corresponding bracket, if any + pos=$CURSOR + if [[ -n $levelpos[$pos] ]] && [[ -n $matching[$pos] ]]; then + local otherpos=$matching[$pos] + local style=$ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket] + region_highlight+=("$otherpos $((otherpos + 1)) $style") + fi +} + +# Helper function to differentiate type +_zsh_highlight_brackets_highlighter_brackettype() +{ + case $1 in + ["()"]) typepos[$pos]=round;; + ["[]"]) typepos[$pos]=bracket;; + ["{}"]) typepos[$pos]=curly;; + *) ;; + esac +} diff --git a/zsh-syntax-highlighting/highlighters/brackets/test-data/mismatch-patentheses.zsh b/zsh-syntax-highlighting/highlighters/brackets/test-data/mismatch-patentheses.zsh new file mode 100644 index 0000000..5671079 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/brackets/test-data/mismatch-patentheses.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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='echo ({x}]' + +expected_region_highlight=( + "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ( + "7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { + "9 9 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } + "10 10 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ) +) diff --git a/zsh-syntax-highlighting/highlighters/brackets/test-data/nested-parentheses.zsh b/zsh-syntax-highlighting/highlighters/brackets/test-data/nested-parentheses.zsh new file mode 100644 index 0000000..291f8f4 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/brackets/test-data/nested-parentheses.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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='echo $(echo ${(z)array})' + +expected_region_highlight=( + "7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ( + "14 14 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { + "15 15 $ZSH_HIGHLIGHT_STYLES[bracket-level-3]" # ( + "17 17 $ZSH_HIGHLIGHT_STYLES[bracket-level-3]" # ) + "23 23 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } + "24 24 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ) +) diff --git a/zsh-syntax-highlighting/highlighters/brackets/test-data/quoted-patentheses.zsh b/zsh-syntax-highlighting/highlighters/brackets/test-data/quoted-patentheses.zsh new file mode 100644 index 0000000..a2c52c4 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/brackets/test-data/quoted-patentheses.zsh @@ -0,0 +1,34 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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='echo "foo ( bar"' + +expected_region_highlight=( +"1 16 $ZSH_HIGHLIGHT_STYLES[none]" # We expect the brackets highlighter to do nothing +) diff --git a/zsh-syntax-highlighting/highlighters/brackets/test-data/simple-parentheses.zsh b/zsh-syntax-highlighting/highlighters/brackets/test-data/simple-parentheses.zsh new file mode 100644 index 0000000..893145f --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/brackets/test-data/simple-parentheses.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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='echo ({x})' + +expected_region_highlight=( + "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ( + "7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { + "9 9 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } + "10 10 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ) +) diff --git a/zsh-syntax-highlighting/highlighters/brackets/test-data/unclosed-patentheses.zsh b/zsh-syntax-highlighting/highlighters/brackets/test-data/unclosed-patentheses.zsh new file mode 100644 index 0000000..c36ba36 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/brackets/test-data/unclosed-patentheses.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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='echo ({x}' + +expected_region_highlight=( + "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ( + "7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { + "9 9 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } +) diff --git a/zsh-syntax-highlighting/highlighters/brackets/test-data/unclosed-patentheses2.zsh b/zsh-syntax-highlighting/highlighters/brackets/test-data/unclosed-patentheses2.zsh new file mode 100644 index 0000000..04c246b --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/brackets/test-data/unclosed-patentheses2.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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='echo {x})' + +expected_region_highlight=( + "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # { + "8 8 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # } + "9 9 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ) +) diff --git a/zsh-syntax-highlighting/highlighters/cursor/README.md b/zsh-syntax-highlighting/highlighters/cursor/README.md new file mode 100644 index 0000000..d28ac19 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/cursor/README.md @@ -0,0 +1,24 @@ +zsh-syntax-highlighting / highlighters / cursor +================================================= + +This is the ***cursor*** highlighter, that highlights the cursor. + + +How to activate it +------------------ +To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: + + ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] cursor) + + +How to tweak it +--------------- +This highlighter defines the following styles: + +* `cursor` - the style for the current cursor position + +To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: + + ZSH_HIGHLIGHT_STYLES[cursor]='bg=blue' + +The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/zsh-syntax-highlighting/highlighters/cursor/cursor-highlighter.zsh b/zsh-syntax-highlighting/highlighters/cursor/cursor-highlighter.zsh new file mode 100644 index 0000000..d315c62 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/cursor/cursor-highlighter.zsh @@ -0,0 +1,44 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 +# ------------------------------------------------------------------------------------------------- + + +# Define default styles. +: ${ZSH_HIGHLIGHT_STYLES[cursor]:=standout} + +# Whether the cursor highlighter should be called or not. +_zsh_highlight_cursor_highlighter_predicate() +{ + _zsh_highlight_cursor_moved +} + +# Cursor highlighting function. +_zsh_highlight_cursor_highlighter() +{ + region_highlight+=("$CURSOR $(( $CURSOR + 1 )) $ZSH_HIGHLIGHT_STYLES[cursor]") +} diff --git a/zsh-syntax-highlighting/highlighters/line/README.md b/zsh-syntax-highlighting/highlighters/line/README.md new file mode 100644 index 0000000..2be32a2 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/line/README.md @@ -0,0 +1,24 @@ +zsh-syntax-highlighting / highlighters / line +================================================= + +This is the ***line*** highlighter, that highlights the whole line. + + +How to activate it +------------------ +To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: + + ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] line) + + +How to tweak it +--------------- +This highlighter defines the following styles: + +* `line` - the style for the whole line + +To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: + + ZSH_HIGHLIGHT_STYLES[line]='bold' + +The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/zsh-syntax-highlighting/highlighters/line/line-highlighter.zsh b/zsh-syntax-highlighting/highlighters/line/line-highlighter.zsh new file mode 100644 index 0000000..68308cc --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/line/line-highlighter.zsh @@ -0,0 +1,44 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 +# ------------------------------------------------------------------------------------------------- + + +# Define default styles. +: ${ZSH_HIGHLIGHT_STYLES[line]:=} + +# Whether the root highlighter should be called or not. +_zsh_highlight_line_highlighter_predicate() +{ + _zsh_highlight_buffer_modified +} + +# root highlighting function. +_zsh_highlight_line_highlighter() +{ + region_highlight+=("0 $#BUFFER $ZSH_HIGHLIGHT_STYLES[line]") +} diff --git a/zsh-syntax-highlighting/highlighters/main/README.md b/zsh-syntax-highlighting/highlighters/main/README.md new file mode 100644 index 0000000..c748248 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/README.md @@ -0,0 +1,68 @@ +zsh-syntax-highlighting / highlighters / main +============================================= + +This is the ***main*** highlighter, that highlights: + +* Commands +* Options +* Arguments +* Paths +* Strings + +How to activate it +------------------ +To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: + + ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] main) + +This highlighter is active by default. + + +How to tweak it +--------------- +This highlighter defines the following styles: + +* `unknown-token` - unknown tokens / errors +* `reserved-word` - shell reserved words +* `alias` - aliases +* `suffix-alias` - suffix aliases (requires zsh 5.1.1 or newer) +* `builtin` - shell builtin commands +* `function` - functions +* `command` - commands +* `precommand` - precommands (i.e. exec, builtin, ...) +* `commandseparator` - command separation tokens +* `hashed-command` - hashed commands +* `path` - paths +* `path_prefix` - path prefixes +* `globbing` - globbing expressions (`*.txt`) +* `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`) +* `single-hyphen-option` - single hyphen options (-o) +* `double-hyphen-option` - double hyphen options (--option) +* `back-quoted-argument` - backquoted expressions (`` `foo` ``) +* `single-quoted-argument` - single quoted arguments (`` 'foo' ``) +* `double-quoted-argument` - double quoted arguments (`` "foo" ``) +* `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``) +* `dollar-double-quoted-argument` - dollar double quoted arguments ($foo inside "") +* `back-double-quoted-argument` - back double quoted arguments (\x inside "") +* `back-dollar-quoted-argument` - back dollar quoted arguments (\x inside $'') +* `assign` - variable assignments +* `redirection` - redirection operators (`<`, `>`, etc) +* `comment` - interactive comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`) +* `default` - parts of the buffer that do not match anything + +To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: + + # Declare the variable + typeset -A ZSH_HIGHLIGHT_STYLES + + # To differentiate aliases from other command types + ZSH_HIGHLIGHT_STYLES[alias]='fg=magenta,bold' + + # To have paths colored instead of underlined + ZSH_HIGHLIGHT_STYLES[path]='fg=cyan' + + # To disable highlighting of globbing expressions + ZSH_HIGHLIGHT_STYLES[globbing]='none' + +The syntax for declaring styles is documented in [the `zshzle(1)` manual +page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/zsh-syntax-highlighting/highlighters/main/main-highlighter.zsh b/zsh-syntax-highlighting/highlighters/main/main-highlighter.zsh new file mode 100644 index 0000000..64a2032 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/main-highlighter.zsh @@ -0,0 +1,494 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2015 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 +# ------------------------------------------------------------------------------------------------- + + +# Define default styles. +: ${ZSH_HIGHLIGHT_STYLES[default]:=none} +: ${ZSH_HIGHLIGHT_STYLES[unknown-token]:=fg=red,bold} +: ${ZSH_HIGHLIGHT_STYLES[reserved-word]:=fg=yellow} +: ${ZSH_HIGHLIGHT_STYLES[alias]:=fg=green} +: ${ZSH_HIGHLIGHT_STYLES[suffix-alias]:=fg=green,underline} +: ${ZSH_HIGHLIGHT_STYLES[builtin]:=fg=green} +: ${ZSH_HIGHLIGHT_STYLES[function]:=fg=green} +: ${ZSH_HIGHLIGHT_STYLES[command]:=fg=green} +: ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline} +: ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none} +: ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green} +: ${ZSH_HIGHLIGHT_STYLES[path]:=underline} +: ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline} +: ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} +: ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue} +: ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none} +: ${ZSH_HIGHLIGHT_STYLES[double-hyphen-option]:=none} +: ${ZSH_HIGHLIGHT_STYLES[back-quoted-argument]:=none} +: ${ZSH_HIGHLIGHT_STYLES[single-quoted-argument]:=fg=yellow} +: ${ZSH_HIGHLIGHT_STYLES[double-quoted-argument]:=fg=yellow} +: ${ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]:=fg=yellow} +: ${ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]:=fg=cyan} +: ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan} +: ${ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan} +: ${ZSH_HIGHLIGHT_STYLES[assign]:=none} +: ${ZSH_HIGHLIGHT_STYLES[redirection]:=none} +: ${ZSH_HIGHLIGHT_STYLES[comment]:=fg=black,bold} + +# Whether the highlighter should be called or not. +_zsh_highlight_main_highlighter_predicate() +{ + # accept-* may trigger removal of path_prefix highlighting + [[ $WIDGET == accept-* ]] || + _zsh_highlight_buffer_modified +} + +# Helper to deal with tokens crossing line boundaries. +_zsh_highlight_main_add_region_highlight() { + integer start=$1 end=$2 + local style=$3 + + # The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is + # relative to $BUFFER. + (( start -= $#PREBUFFER )) + (( end -= $#PREBUFFER )) + + (( end < 0 )) && return # having end<0 would be a bug + (( start < 0 )) && start=0 # having start<0 is normal with e.g. multiline strings + region_highlight+=("$start $end $style") +} + +# Main syntax highlighting function. +_zsh_highlight_main_highlighter() +{ + if [[ -o interactive_comments ]]; then + local interactive_comments= # set to empty + fi + emulate -L zsh + setopt localoptions extendedglob bareglobqual + local start_pos=0 end_pos highlight_glob=true arg style + typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR + typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS + typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW + local buf="$PREBUFFER$BUFFER" + region_highlight=() + + ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR=( + '|' '||' ';' '&' '&&' + ) + ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=( + 'builtin' 'command' 'exec' 'nocorrect' 'noglob' + ) + + # Tokens that, at (naively-determined) "command position", are followed by + # a de jure command position. All of these are reserved words. + ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW=( + $'\x7b' # block + $'\x28' # subshell + '()' # anonymous function + 'while' + 'until' + 'if' + 'then' + 'elif' + 'else' + 'do' + 'time' + 'coproc' + '!' # reserved word; unrelated to $histchars[1] + ) + + # State machine + # + # The states are: + # - :start: Command word + # - :sudo_opt: A leading-dash option to sudo (such as "-u" or "-i") + # - :sudo_arg: The argument to a sudo leading-dash option that takes one, + # when given as a separate word; i.e., "foo" in "-u foo" (two + # words) but not in "-ufoo" (one word). + # - :regular: "Not a command word". + # Mainly used to detect premature termination of commands. + # + # When the kind of a word is not yet known, $this_word / $next_word may contain + # multiple states. For example, after "sudo -i", the next word may be either + # another --flag or a command name, hence the state would include both :start: + # and :sudo_opt:. + # + # The tokens are always added with both leading and trailing colons to serve as + # word delimiters (an improvised array); [[ $x == *:foo:* ]] and x=${x//:foo:/} + # will DTRT regardless of how many elements or repetitions $x has.. + # + # Handling of redirections: upon seeing a redirection token, we must stall + # the current state --- that is, the value of $this_word --- for two iterations + # (one for the redirection operator, one for the word following it representing + # the redirection target). Therefore, we set $in_redirection to 2 upon seeing a + # redirection operator, decrement it each iteration, and stall the current state + # when it is non-zero. Thus, upon reaching the next word (the one that follows + # the redirection operator and target), $this_word will still contain values + # appropriate for the word immediately following the word that preceded the + # redirection operator. + # + # The "the previous word was a redirection operator" state is not communicated + # to the next iteration via $next_word/$this_word as usual, but via + # $in_redirection. The value of $next_word from the iteration that processed + # the operator is discarded. + # + local this_word=':start:' next_word + integer in_redirection + for arg in ${interactive_comments-${(z)buf}} \ + ${interactive_comments+${(zZ+c+)buf}}; do + if (( in_redirection )); then + (( --in_redirection )) + fi + if (( in_redirection == 0 )); then + next_word=':regular:' + fi + # $already_added is set to 1 to disable adding an entry to region_highlight + # for this iteration. Currently, that is done for "" and $'' strings, + # which add the entry early so escape sequences within the string override + # the string's color. + integer already_added=0 + local style_override="" + if [[ $this_word == *':start:'* ]] && [[ $arg = 'noglob' ]]; then + highlight_glob=false + fi + + # advance $start_pos, skipping over whitespace in $buf. + if [[ $arg == ';' ]] ; then + # We're looking for either a semicolon or a newline, whichever comes + # first. Both of these are rendered as a ";" (SEPER) by the ${(z)..} + # flag. + # + # We can't use the (Z+n+) flag because that elides the end-of-command + # token altogether, so 'echo foo\necho bar' (two commands) becomes + # indistinguishable from 'echo foo echo bar' (one command with three + # words for arguments). + local needle=$'[;\n]' + integer offset=${${buf[start_pos+1,-1]}[(i)$needle]} + (( start_pos += offset - 1 )) + (( end_pos = start_pos + $#arg )) + else + ((start_pos+=${#buf[$start_pos+1,-1]}-${#${buf[$start_pos+1,-1]##([[:space:]]|\\[[:space:]])#}})) + ((end_pos=$start_pos+${#arg})) + fi + + if [[ -n ${interactive_comments+'set'} && $arg[1] == $histchars[3] ]]; then + if [[ $this_word == *(':regular:'|':start:')* ]]; then + style=$ZSH_HIGHLIGHT_STYLES[comment] + else + style=$ZSH_HIGHLIGHT_STYLES[unknown-token] # prematurely terminated + fi + _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style + already_added=1 + continue + fi + + # Parse the sudo command line + if (( ! in_redirection )); then + if [[ $this_word == *':sudo_opt:'* ]]; then + case "$arg" in + # Flag that requires an argument + '-'[Cgprtu]) this_word=${this_word//:start:/}; + next_word=':sudo_arg:';; + # This prevents misbehavior with sudo -u -otherargument + '-'*) this_word=${this_word//:start:/}; + next_word+=':start:'; + next_word+=':sudo_opt:';; + *) ;; + esac + elif [[ $this_word == *':sudo_arg:'* ]]; then + next_word+=':sudo_opt:' + next_word+=':start:' + fi + fi + + if [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word + if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then + style=$ZSH_HIGHLIGHT_STYLES[precommand] + elif [[ "$arg" = "sudo" ]]; then + style=$ZSH_HIGHLIGHT_STYLES[precommand] + next_word=${next_word//:regular:/} + next_word+=':sudo_opt:' + next_word+=':start:' + else + _zsh_highlight_main_highlighter_expand_path $arg + local expanded_arg="$REPLY" + local res="$(LC_ALL=C builtin type -w -- ${expanded_arg} 2>/dev/null)" + case $res in + *': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; + *': suffix alias') + style=$ZSH_HIGHLIGHT_STYLES[suffix-alias] + ;; + *': alias') style=$ZSH_HIGHLIGHT_STYLES[alias] + local aliased_command="${"$(alias -- $arg)"#*=}" + [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg) + ;; + *': builtin') style=$ZSH_HIGHLIGHT_STYLES[builtin];; + *': function') style=$ZSH_HIGHLIGHT_STYLES[function];; + *': command') style=$ZSH_HIGHLIGHT_STYLES[command];; + *': hashed') style=$ZSH_HIGHLIGHT_STYLES[hashed-command];; + *) if _zsh_highlight_main_highlighter_check_assign; then + style=$ZSH_HIGHLIGHT_STYLES[assign] + if [[ $arg[-1] != '(' ]]; then + # assignment to a scalar parameter. + # (For array assignments, the command doesn't start until the ")" token.) + next_word+=':start:' + fi + elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then + style=$ZSH_HIGHLIGHT_STYLES[history-expansion] + elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && + [[ $this_word == *':regular:'* ]]; then + # This highlights empty commands (semicolon follows nothing) as an error. + # Zsh accepts them, though. + style=$ZSH_HIGHLIGHT_STYLES[commandseparator] + elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then + style=$ZSH_HIGHLIGHT_STYLES[redirection] + (( in_redirection=2 )) + elif [[ $arg[1,2] == '((' ]]; then + # Arithmetic evaluation. + # + # Note: prior to zsh-5.1.1-52-g4bed2cf (workers/36669), the ${(z)...} + # splitter would only output the '((' token if the matching '))' had + # been typed. Therefore, under those versions of zsh, BUFFER="(( 42" + # would be highlighted as an error until the matching "))" are typed. + # + # We highlight just the opening parentheses, as a reserved word; this + # is how [[ ... ]] is highlighted, too. + style=$ZSH_HIGHLIGHT_STYLES[reserved-word] + _zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style + already_added=1 + if [[ $arg[-2,-1] == '))' ]]; then + _zsh_highlight_main_add_region_highlight $((end_pos - 2)) $end_pos $style + already_added=1 + fi + elif [[ $arg == '()' || $arg == $'\x28' ]]; then + # anonymous function + # subshell + style=$ZSH_HIGHLIGHT_STYLES[reserved-word] + else + if _zsh_highlight_main_highlighter_check_path; then + style=$ZSH_HIGHLIGHT_STYLES[path] + else + style=$ZSH_HIGHLIGHT_STYLES[unknown-token] + fi + fi + ;; + esac + fi + else # $arg is a non-command word + case $arg in + $'\x29') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; # subshell + $'\x7d') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; # block + '--'*) style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];; + '-'*) style=$ZSH_HIGHLIGHT_STYLES[single-hyphen-option];; + "'"*) style=$ZSH_HIGHLIGHT_STYLES[single-quoted-argument];; + '"'*) style=$ZSH_HIGHLIGHT_STYLES[double-quoted-argument] + _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style + _zsh_highlight_main_highlighter_highlight_string + already_added=1 + ;; + \$\'*) style=$ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument] + _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style + _zsh_highlight_main_highlighter_highlight_dollar_string + already_added=1 + ;; + '`'*) style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];; + [*?]*|*[^\\][*?]*) + $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; + *) if false; then + elif [[ $arg[0,1] = $histchars[0,1] ]]; then + style=$ZSH_HIGHLIGHT_STYLES[history-expansion] + elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then + if [[ $this_word == *':regular:'* ]]; then + style=$ZSH_HIGHLIGHT_STYLES[commandseparator] + else + style=$ZSH_HIGHLIGHT_STYLES[unknown-token] + fi + elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then + style=$ZSH_HIGHLIGHT_STYLES[redirection] + (( in_redirection=2 )) + else + if _zsh_highlight_main_highlighter_check_path; then + style=$ZSH_HIGHLIGHT_STYLES[path] + else + style=$ZSH_HIGHLIGHT_STYLES[default] + fi + fi + ;; + esac + fi + # if a style_override was set (eg in _zsh_highlight_main_highlighter_check_path), use it + [[ -n $style_override ]] && style=$ZSH_HIGHLIGHT_STYLES[$style_override] + (( already_added )) || _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style + if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then + next_word=':start:' + elif + [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:' ]] || + [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:' ]]; then + next_word=':start:' + elif [[ $arg == "repeat" && $this_word == *':start:'* ]]; then + # skip the repeat-count word + in_redirection=2 + # The redirection mechanism assumes $this_word describes the word + # following the redirection. Make it so. + # + # The repeat-count word will be handled like a redirection target. + this_word=':start:' + fi + [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && highlight_glob=true + start_pos=$end_pos + (( in_redirection == 0 )) && this_word=$next_word + done +} + +# Check if $arg is variable assignment +_zsh_highlight_main_highlighter_check_assign() +{ + setopt localoptions extended_glob + [[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])(|[+])=* ]] +} + +# Check if $arg is a path. +_zsh_highlight_main_highlighter_check_path() +{ + _zsh_highlight_main_highlighter_expand_path $arg; + local expanded_path="$REPLY" + + [[ -z $expanded_path ]] && return 1 + [[ -e $expanded_path ]] && return 0 + + # Search the path in CDPATH + local cdpath_dir + for cdpath_dir in $cdpath ; do + [[ -e "$cdpath_dir/$expanded_path" ]] && return 0 + done + + # If dirname($arg) doesn't exist, neither does $arg. + [[ ! -e ${expanded_path:h} ]] && return 1 + + # If this word ends the buffer, check if it's the prefix of a valid path. + if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]] && + [[ $WIDGET != accept-* ]]; then + local -a tmp + tmp=( ${expanded_path}*(N) ) + (( $#tmp > 0 )) && style_override=path_prefix && return 0 + fi + + # It's not a path. + return 1 +} + +# Highlight special chars inside double-quoted strings +_zsh_highlight_main_highlighter_highlight_string() +{ + setopt localoptions noksharrays + local -a match mbegin mend + local MATCH; integer MBEGIN MEND + local i j k style + # Starting quote is at 1, so start parsing at offset 2 in the string. + for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do + (( j = i + start_pos - 1 )) + (( k = j + 1 )) + case "$arg[$i]" in + '$' ) style=$ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument] + # Look for an alphanumeric parameter name. + if [[ ${arg:$i} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+) ]] ; then + (( k += $#MATCH )) # highlight the parameter name + (( i += $#MATCH )) # skip past it + else + continue + fi + ;; + "\\") style=$ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument] + if [[ \\\`\"\$ == *$arg[$i+1]* ]]; then + (( k += 1 )) # Color following char too. + (( i += 1 )) # Skip parsing the escaped char. + else + continue + fi + ;; + *) continue ;; + + esac + _zsh_highlight_main_add_region_highlight $j $k $style + done +} + +# Highlight special chars inside dollar-quoted strings +_zsh_highlight_main_highlighter_highlight_dollar_string() +{ + setopt localoptions noksharrays + local -a match mbegin mend + local MATCH; integer MBEGIN MEND + local i j k style + local AA + integer c + # Starting dollar-quote is at 1:2, so start parsing at offset 3 in the string. + for (( i = 3 ; i < end_pos - start_pos ; i += 1 )) ; do + (( j = i + start_pos - 1 )) + (( k = j + 1 )) + case "$arg[$i]" in + "\\") style=$ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument] + for (( c = i + 1 ; c <= end_pos - start_pos ; c += 1 )); do + [[ "$arg[$c]" != ([0-9xXuUa-fA-F]) ]] && break + done + AA=$arg[$i+1,$c-1] + # Matching for HEX and OCT values like \0xA6, \xA6 or \012 + if [[ "$AA" =~ "^(x|X)[0-9a-fA-F]{1,2}" + || "$AA" =~ "^[0-7]{1,3}" + || "$AA" =~ "^u[0-9a-fA-F]{1,4}" + || "$AA" =~ "^U[0-9a-fA-F]{1,8}" + ]]; then + (( k += $#MATCH )) + (( i += $#MATCH )) + else + if (( $#arg > $i+1 )) && [[ $arg[$i+1] == [xXuU] ]]; then + # \x not followed by hex digits is probably an error + style=$ZSH_HIGHLIGHT_STYLES[unknown-token] + fi + (( k += 1 )) # Color following char too. + (( i += 1 )) # Skip parsing the escaped char. + fi + ;; + *) continue ;; + + esac + _zsh_highlight_main_add_region_highlight $j $k $style + done +} + +# Called with a single positional argument. +# Perform filename expansion (tilde expansion) on the argument and set $REPLY to the expanded value. +# +# Does not perform filename generation (globbing). +_zsh_highlight_main_highlighter_expand_path() +{ + (( $# == 1 )) || echo "zsh-syntax-highlighting: BUG: _zsh_highlight_main_highlighter_expand_path: called without argument" >&2 + + # The $~1 syntax normally performs filename generation, but not when it's on the right-hand side of ${x:=y}. + setopt localoptions nonomatch + unset REPLY + : ${REPLY:=${(Q)~1}} +} diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/alias.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/alias.zsh new file mode 100644 index 0000000..aa84a58 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/alias.zsh @@ -0,0 +1,51 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 alias1="unused expansion" +alias -s alias2="echo" +alias1() {} # to check that it's highlighted as an alias, not as a function + +ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight +BUFFER='x.alias2; alias1' + +# Set expected_region_highlight as a function of zsh version. +# +# Highlight of suffix alias requires zsh-5.1.1 or newer; see issue #126, +# and commit 36403 to zsh itself. Therefore, check if the requisite zsh +# functionality is present, and skip verifying suffix-alias highlighting +# if it isn't. +expected_region_highlight=() +if [[ "$(type -w x.alias2)" == *suffix* ]]; then + expected_region_highlight+=( + "1 8 $ZSH_HIGHLIGHT_STYLES[suffix-alias]" # x.alias2 + ) +fi +expected_region_highlight+=( + "11 16 $ZSH_HIGHLIGHT_STYLES[alias]" # alias1 +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/anonymous-function.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/anonymous-function.zsh new file mode 100644 index 0000000..62714ed --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/anonymous-function.zsh @@ -0,0 +1,40 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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='() echo hello; () { echo world }' + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # () + "4 7 $ZSH_HIGHLIGHT_STYLES[command]" # echo + "9 13 $ZSH_HIGHLIGHT_STYLES[default]" # hello + "14 14 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; + "16 17 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # () + "19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # { + "21 24 $ZSH_HIGHLIGHT_STYLES[command]" # echo +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/arithmetic-evaluation.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/arithmetic-evaluation.zsh new file mode 100644 index 0000000..9287e91 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/arithmetic-evaluation.zsh @@ -0,0 +1,40 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +# Must be at command word, since the word following 'if' isn't currently considered +# a command word (issue #207). +# +# An opening '((' without matching '))' is highlighted correctly under zsh-5.1.1-52-g4bed2cf +# or newer, only (issue #188). +BUFFER='(( x == 42 ))' + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # (( + "12 13 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # )) +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/assign-append.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/assign-append.zsh new file mode 100644 index 0000000..a38cd86 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/assign-append.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight +BUFFER='a+=(lorem ipsum)' + +expected_region_highlight=( + "1 4 $ZSH_HIGHLIGHT_STYLES[assign]" # a+=( +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/assign-semicolon.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/assign-semicolon.zsh new file mode 100644 index 0000000..c3692d4 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/assign-semicolon.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[commandseparator]=$unused_highlight +BUFFER='A=1; echo hello world' + +expected_region_highlight=( + "4 4 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; + "6 9 $ZSH_HIGHLIGHT_STYLES[command]" # echo +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/assign.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/assign.zsh new file mode 100644 index 0000000..ef38668 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/assign.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight +BUFFER='A=1 b=("foo" bar)' + +expected_region_highlight=( + "1 3 $ZSH_HIGHLIGHT_STYLES[assign]" # A=1 + "8 12 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo" +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/back-quoted-argument.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/back-quoted-argument.zsh new file mode 100644 index 0000000..6dfba71 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/back-quoted-argument.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[back-quoted-argument]=$unused_highlight +BUFFER='echo `echo 42`' + +expected_region_highlight=( + "6 14 $ZSH_HIGHLIGHT_STYLES[back-quoted-argument]" +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/backslash-continuation.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/backslash-continuation.zsh new file mode 100644 index 0000000..9fbd916 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/backslash-continuation.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +PREBUFFER=$'echo \\\n' +BUFFER='noglob' + +expected_region_highlight=( + "1 6 none" # 'noglob' highlighted as a string, not as a precomand +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/commandseparator.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/commandseparator.zsh new file mode 100644 index 0000000..383bd47 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/commandseparator.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[commandseparator]=$unused_highlight + +BUFFER=':; pwd' + +expected_region_highlight=( + "2 2 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; + "4 6 $ZSH_HIGHLIGHT_STYLES[builtin]" # pwd +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/comment-leading.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/comment-leading.zsh new file mode 100644 index 0000000..a30af8b --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/comment-leading.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 interactive_comments + +BUFFER='# echo foo' + +expected_region_highlight=( + "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]}" # # + "2 10 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]}" # " echo foo" +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/comment-off.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/comment-off.zsh new file mode 100644 index 0000000..5aa16af --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/comment-off.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 +# ------------------------------------------------------------------------------------------------- + +unsetopt interactive_comments + +BUFFER='# echo foo' + +expected_region_highlight=( + "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # # + "3 6 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # " echo foo" + "8 10 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # " echo foo" +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/comments.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/comments.zsh new file mode 100644 index 0000000..4b9c974 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/comments.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 interactive_comments + +BUFFER='echo "foo #bar" #baz # quux' + +expected_region_highlight=( + "1 4 $ZSH_HIGHLIGHT_STYLES[command]" # echo + "6 15 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo #bar" + "17 27 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]}" # #baz # quux +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/control-flow.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/control-flow.zsh new file mode 100644 index 0000000..3107f50 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/control-flow.zsh @@ -0,0 +1,51 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight +BUFFER='while if echo Hello; then ls /; else ls; fi; do stat "x"; done; repeat 10 ls' + +expected_region_highlight+=( + "1 5 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # while + "7 8 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # if + "10 13 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo + "15 19 $ZSH_HIGHLIGHT_STYLES[default]" # Hello + "22 25 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # then + "27 28 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "30 30 $ZSH_HIGHLIGHT_STYLES[path]" # / + "31 31 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; + "33 36 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # else + "38 39 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "42 43 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # fi + "46 47 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # do + "49 52 $ZSH_HIGHLIGHT_STYLES[command]" # stat + "54 56 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "x" + "59 62 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # done + "65 70 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # repeat + "75 76 $ZSH_HIGHLIGHT_STYLES[command]" # ls +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/dollar-quoted.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/dollar-quoted.zsh new file mode 100644 index 0000000..ea12f9f --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/dollar-quoted.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]=$unused_highlight +BUFFER=": \$'*' 'foo'" + +expected_region_highlight=( + "3 6 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $'*' - not a glob + "8 12 $ZSH_HIGHLIGHT_STYLES[single-quoted-argument]" # 'foo' +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/dollar-quoted2.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/dollar-quoted2.zsh new file mode 100644 index 0000000..1ce9bb4 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/dollar-quoted2.zsh @@ -0,0 +1,41 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=$unused_highlight +BUFFER=": \$'foo\xbar\udeadbeef\uzzzz'" + +expected_region_highlight=( + "3 7 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $'foo + "8 11 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \xba + "12 12 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # r + "13 18 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \dead + "19 22 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # beef + "23 24 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # \u + "25 29 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # zzzz' +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/dollar-quoted3.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/dollar-quoted3.zsh new file mode 100644 index 0000000..53ee171 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/dollar-quoted3.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +# Similar to double-quoted2.zsh +ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=$unused_highlight +# This test checks that the '1' gets highlighted correctly. Do not append to the BUFFER. +BUFFER=": \$'\xa1" + +expected_region_highlight=( + "3 4 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $' + "5 8 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \xa1 +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/double-hyphen-option.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/double-hyphen-option.zsh new file mode 100644 index 0000000..b87ebe8 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/double-hyphen-option.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[double-hyphen-option]=$unused_highlight +BUFFER='hello --world' + +expected_region_highlight=( + "7 13 $ZSH_HIGHLIGHT_STYLES[double-hyphen-option]" # --world +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/double-quoted.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/double-quoted.zsh new file mode 100644 index 0000000..3f80f9e --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/double-quoted.zsh @@ -0,0 +1,45 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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$bar:\`:\":\$:' +BUFFER+=\\\\:\" + +expected_region_highlight=( + "3 6 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo + "7 10 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $bar + "11 11 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : + "12 13 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \` + "14 14 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : + "15 16 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \$ + "17 17 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : + "18 19 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \" + "20 20 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : + "21 22 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \\ + "23 24 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # :" +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/double-quoted2.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/double-quoted2.zsh new file mode 100644 index 0000000..d3facb2 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/double-quoted2.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 +# ------------------------------------------------------------------------------------------------- + +# Similar to dollar-quoted3.zsh +# This test checks that the 'r' gets highlighted correctly. Do not append to the BUFFER. +BUFFER=': "foo$bar' + +expected_region_highlight=( + "3 6 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo + "7 10 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $bar +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/double-quoted3.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/double-quoted3.zsh new file mode 100644 index 0000000..6b9001c --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/double-quoted3.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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=': "$" "$42foo"' +BUFFER+=\ \"\\\'\\x\" + +expected_region_highlight=( + "3 5 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "$" + "7 7 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # " + "8 10 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $42 + "11 14 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # foo" + "16 21 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "\'\x" - \' and \x are not escape sequences +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/empty-command.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/empty-command.zsh new file mode 100644 index 0000000..9e4b13f --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/empty-command.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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='echo; ;' + +expected_region_highlight=( + "5 5 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; + "7 7 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # ; +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/function.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/function.zsh new file mode 100644 index 0000000..3e579ab --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/function.zsh @@ -0,0 +1,47 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[function]=$unused_highlight +cd() { + builtin cd "$@" +} +ls() { + command ls "$@" +} +BUFFER='cd;ls' + +# Use $unused_highlight to see that function highlighting has precedence over command and builtin + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[function]" # cd + "4 5 $ZSH_HIGHLIGHT_STYLES[function]" # ls +) + +# don't 'unfunction cd ls', since cd() and ls() should still be a functions +# when _zsh_highlight runs. Leaving the wrapper functions is harmless. diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/glob.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/glob.zsh new file mode 100644 index 0000000..d808e2b --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/glob.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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* bar? *baz qux\?' + +expected_region_highlight=( + "1 1 $ZSH_HIGHLIGHT_STYLES[builtin]" # : + "3 6 $ZSH_HIGHLIGHT_STYLES[globbing]" # foo* + "8 11 $ZSH_HIGHLIGHT_STYLES[globbing]" # bar? + "13 16 $ZSH_HIGHLIGHT_STYLES[globbing]" # *baz + "18 22 $ZSH_HIGHLIGHT_STYLES[default]" # qux\? +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/hashed-command.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/hashed-command.zsh new file mode 100644 index 0000000..ce41b45 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/hashed-command.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +hash zsh_syntax_highlighting_hash=/doesnotexist +ZSH_HIGHLIGHT_STYLES[hashed-command]=$unused_highlight +BUFFER='zsh_syntax_highlighting_hash' + +expected_region_highlight=( + "1 28 $ZSH_HIGHLIGHT_STYLES[hashed-command]" +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/history-expansion.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/history-expansion.zsh new file mode 100644 index 0000000..c670312 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/history-expansion.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 bar !baz' + +expected_region_highlight=( + "1 4 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # !foo + "6 8 $ZSH_HIGHLIGHT_STYLES[default]" # bar + "10 13 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # !baz +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/history-expansion2.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/history-expansion2.zsh new file mode 100644 index 0000000..45af624 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/history-expansion2.zsh @@ -0,0 +1,34 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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^bar' + +expected_region_highlight=( + "1 8 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # ^foo^bar +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/multiline-string.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/multiline-string.zsh new file mode 100644 index 0000000..987dd20 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/multiline-string.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +PREBUFFER=$'echo "foo1\n' +BUFFER='foo2" ./' + +expected_region_highlight=( + "1 5 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # 'foo2"' + "7 8 $ZSH_HIGHLIGHT_STYLES[path]" # './' +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/multiline-string2.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/multiline-string2.zsh new file mode 100644 index 0000000..9753e5d --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/multiline-string2.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[double-quoted-argument]=$unused_highlight +BUFFER=$'echo "foo1\n' + +expected_region_highlight=( + "6 10 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # 'foo2"' +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/multiple-redirections.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/multiple-redirections.zsh new file mode 100644 index 0000000..374de8a --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/multiple-redirections.zsh @@ -0,0 +1,46 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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='ps aux | grep java | sort | uniq | tail | head' + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ps + "4 6 $ZSH_HIGHLIGHT_STYLES[default]" # aux + "8 8 $ZSH_HIGHLIGHT_STYLES[default]" # | + "10 13 $ZSH_HIGHLIGHT_STYLES[command]" # grep + "15 18 $ZSH_HIGHLIGHT_STYLES[default]" # java + "20 20 $ZSH_HIGHLIGHT_STYLES[default]" # | + "22 25 $ZSH_HIGHLIGHT_STYLES[command]" # sort + "27 27 $ZSH_HIGHLIGHT_STYLES[default]" # | + "29 32 $ZSH_HIGHLIGHT_STYLES[command]" # uniq + "34 34 $ZSH_HIGHLIGHT_STYLES[default]" # | + "36 39 $ZSH_HIGHLIGHT_STYLES[command]" # tail + "41 41 $ZSH_HIGHLIGHT_STYLES[default]" # | + "43 46 $ZSH_HIGHLIGHT_STYLES[command]" # head +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/noglob-alias.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/noglob-alias.zsh new file mode 100644 index 0000000..44d253a --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/noglob-alias.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 x=command +BUFFER='x ls' + +expected_region_highlight=( + "3 4 $ZSH_HIGHLIGHT_STYLES[command]" # ls +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/noglob1.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/noglob1.zsh new file mode 100644 index 0000000..d9bc69b --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/noglob1.zsh @@ -0,0 +1,34 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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=':; noglob echo *' + +expected_region_highlight=( + "16 16 $ZSH_HIGHLIGHT_STYLES[default]" # * +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/noglob2.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/noglob2.zsh new file mode 100644 index 0000000..2c19250 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/noglob2.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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='noglob echo *; echo *' + +expected_region_highlight=( + "13 13 $ZSH_HIGHLIGHT_STYLES[default]" # * + "21 21 $ZSH_HIGHLIGHT_STYLES[globbing]" # * +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/path-space- .zsh b/zsh-syntax-highlighting/highlighters/main/test-data/path-space- .zsh new file mode 100644 index 0000000..f6b889e --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/path-space- .zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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='ls highlighters/main/test-data/path-space-\ .zsh' + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "4 48 $ZSH_HIGHLIGHT_STYLES[path]" # highlighters/main/test-data/path-space-\ .zsh +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/path-tilde-home.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/path-tilde-home.zsh new file mode 100644 index 0000000..31ad1e9 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/path-tilde-home.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 +# ------------------------------------------------------------------------------------------------- + +HOME="." +BUFFER='ls ~' + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "4 4 $ZSH_HIGHLIGHT_STYLES[path]" # ~ +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/path-tilde-home2.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/path-tilde-home2.zsh new file mode 100644 index 0000000..18dd17b --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/path-tilde-home2.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +HOME="/nonexistent" +BUFFER='ls ~' + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "4 4 $ZSH_HIGHLIGHT_STYLES[default]" # ~ +) + diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/path-tilde-named.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/path-tilde-named.zsh new file mode 100644 index 0000000..be5bb5a --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/path-tilde-named.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +hash -d D=highlighters/main/test-data + +BUFFER='ls ~D/path-tilde-named.zsh' + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "4 26 $ZSH_HIGHLIGHT_STYLES[path]" # ~D/path-tilde-named.zsh +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/path.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/path.zsh new file mode 100644 index 0000000..3688b9b --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/path.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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='ls highlighters/main/test-data/path.zsh' + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "4 39 $ZSH_HIGHLIGHT_STYLES[path]" # highlighters/main/test-data/path.zsh +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/path_prefix.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/path_prefix.zsh new file mode 100644 index 0000000..17cd26c --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/path_prefix.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +# Assumes that '/bin/sh' exists and '/bin/s' does not exist. +# Related to path_prefix2.zsh + +ZSH_HIGHLIGHT_STYLES[path_prefix]=$unused_highlight +BUFFER='ls /bin/s' + +expected_region_highlight=( + "4 9 $ZSH_HIGHLIGHT_STYLES[path_prefix]" # /bin/s +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/path_prefix2.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/path_prefix2.zsh new file mode 100644 index 0000000..a1974eb --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/path_prefix2.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +# Assumes that '/bin/sh' exists and '/bin/s' does not exist. +# Related to path_prefix.zsh + +ZSH_HIGHLIGHT_STYLES[path_prefix]=$unused_highlight +BUFFER='ls /bin/s' +WIDGET=accept-line + +expected_region_highlight=( + "4 9 $ZSH_HIGHLIGHT_STYLES[default]" # /bin/s +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/precommand.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/precommand.zsh new file mode 100644 index 0000000..156b72d --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/precommand.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight +BUFFER=': command zzzzzz' + +expected_region_highlight=( + "1 1 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "3 9 $ZSH_HIGHLIGHT_STYLES[default]" # not precommand + "11 16 $ZSH_HIGHLIGHT_STYLES[default]" # not unknown-token (since 'zzzzzz' is not a command) +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/prefix-redirection.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/prefix-redirection.zsh new file mode 100644 index 0000000..0eddf0f --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/prefix-redirection.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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='>/tmp >/tmp sudo echo >/tmp foo' + +expected_region_highlight=( + "2 5 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp + "8 11 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp + "13 16 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo + "18 21 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo + "24 27 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp + "29 31 $ZSH_HIGHLIGHT_STYLES[default]" # foo +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/redirection.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/redirection.zsh new file mode 100644 index 0000000..7515352 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/redirection.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +# Redirection before and after the command word are implemented differently; test both. +ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight +BUFFER='<<>&!bar' + +expected_region_highlight=( + "1 3 $ZSH_HIGHLIGHT_STYLES[redirection]" # <<< + "13 16 $ZSH_HIGHLIGHT_STYLES[redirection]" # >>&! +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/reserved-word.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/reserved-word.zsh new file mode 100644 index 0000000..2f62103 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/reserved-word.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[reserved-word]=$unused_highlight +BUFFER='repeat "1" do done' + +expected_region_highlight=( + "1 6 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # repeat + "8 10 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "1" + "12 13 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # do + "15 18 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # done +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/simple-command.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/simple-command.zsh new file mode 100644 index 0000000..51dd9a9 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/simple-command.zsh @@ -0,0 +1,34 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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='ls' + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/simple-redirection.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/simple-redirection.zsh new file mode 100644 index 0000000..191c67e --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/simple-redirection.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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='ps aux | grep java' + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ps + "4 6 $ZSH_HIGHLIGHT_STYLES[default]" # aux + "8 8 $ZSH_HIGHLIGHT_STYLES[default]" # | + "10 13 $ZSH_HIGHLIGHT_STYLES[command]" # grep + "15 18 $ZSH_HIGHLIGHT_STYLES[default]" # java +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/subshell.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/subshell.zsh new file mode 100644 index 0000000..3e98476 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/subshell.zsh @@ -0,0 +1,41 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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='tar cf - * | (cd /target; tar xfp -) | { cat }' + +expected_region_highlight=( + "1 3 $ZSH_HIGHLIGHT_STYLES[command]" # tar + "14 14 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ( + "15 16 $ZSH_HIGHLIGHT_STYLES[command]" # cd + "27 29 $ZSH_HIGHLIGHT_STYLES[command]" # tar + "36 36 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ) + "40 40 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # { + "42 44 $ZSH_HIGHLIGHT_STYLES[command]" # cat + "46 46 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # } +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/sudo-command.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/sudo-command.zsh new file mode 100644 index 0000000..ec1ccff --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/sudo-command.zsh @@ -0,0 +1,47 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=$unused_highlight +# Tests three codepaths: +# * -i (no argument) +# * -C3 (pasted argument) +# * -u otheruser (non-pasted argument) +BUFFER='sudo -C3 -u otheruser -i ls /; sudo ; sudo -u ;' + +expected_region_highlight=( + "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo + "6 8 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -C3 + "10 11 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u + "13 21 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser + "23 24 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -i + "26 27 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "29 29 $ZSH_HIGHLIGHT_STYLES[path]" # / + "37 37 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # ;, error because empty command + "47 47 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # ;, error because incomplete command +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/sudo-comment.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/sudo-comment.zsh new file mode 100644 index 0000000..8a70ae3 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/sudo-comment.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=$unused_highlight +setopt interactive_comments +BUFFER='sudo -u # comment' + +expected_region_highlight=( + "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo + "6 7 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u + "9 17 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # "# comment" - error because argument missed +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/sudo-redirection.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/sudo-redirection.zsh new file mode 100644 index 0000000..e31ce6e --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/sudo-redirection.zsh @@ -0,0 +1,46 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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='sudo -u >/tmp otheruser ls; sudo ls; sudo -i ls' + +expected_region_highlight=( + "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo + "6 7 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u + "9 9 $ZSH_HIGHLIGHT_STYLES[redirection]" # > + "10 13 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp + "15 23 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser + "25 26 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "27 27 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; + "29 32 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo + "34 35 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "36 36 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; + "38 41 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo + "43 44 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -i + "46 47 $ZSH_HIGHLIGHT_STYLES[command]" # ls +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/sudo-redirection2.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/sudo-redirection2.zsh new file mode 100644 index 0000000..f806178 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/sudo-redirection2.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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='sudo >/tmp -u otheruser ls' + +expected_region_highlight=( + "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo + "6 6 $ZSH_HIGHLIGHT_STYLES[redirection]" # > + "7 10 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp + "12 13 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u + "15 23 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser + "25 26 $ZSH_HIGHLIGHT_STYLES[command]" # ls +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/tilde-command-word.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/tilde-command-word.zsh new file mode 100644 index 0000000..e66db8e --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/tilde-command-word.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +hash -d D=/usr/bin + +BUFFER='~D/env foo' + +expected_region_highlight=( + "1 6 $ZSH_HIGHLIGHT_STYLES[command]" # ~D/env [= /usr/bin/env] + "8 10 $ZSH_HIGHLIGHT_STYLES[default]" # foo +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/unbackslash.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/unbackslash.zsh new file mode 100644 index 0000000..b96c055 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/unbackslash.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[command]=$unused_highlight +BUFFER='\sh' + +expected_region_highlight=( + "1 3 $ZSH_HIGHLIGHT_STYLES[command]" # \sh (runs 'sh', bypassing aliases) +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/unknown-command.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/unknown-command.zsh new file mode 100644 index 0000000..9b9e8d3 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/unknown-command.zsh @@ -0,0 +1,34 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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='azertyuiop' + +expected_region_highlight=( + "1 10 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # azertyuiop +) diff --git a/zsh-syntax-highlighting/highlighters/main/test-data/vanilla-newline.zsh b/zsh-syntax-highlighting/highlighters/main/test-data/vanilla-newline.zsh new file mode 100644 index 0000000..7fa9ba2 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/main/test-data/vanilla-newline.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +PREBUFFER=$'echo foo; echo bar\n\n\n' +BUFFER=' echo baz; echo qux' + +expected_region_highlight=( + "2 5 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo + "7 9 $ZSH_HIGHLIGHT_STYLES[default]" # baz + "10 10 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # semicolon + "12 15 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo + "17 19 $ZSH_HIGHLIGHT_STYLES[default]" # qux +) diff --git a/zsh-syntax-highlighting/highlighters/pattern/README.md b/zsh-syntax-highlighting/highlighters/pattern/README.md new file mode 100644 index 0000000..82a7c65 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/pattern/README.md @@ -0,0 +1,21 @@ +zsh-syntax-highlighting / highlighters / pattern +================================================ + +This is the ***pattern*** highlighter, that highlights user defined patterns. + + +How to activate it +------------------ +To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: + + ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] pattern) + + +How to tweak it +--------------- +To use this highlighter, associate patterns with styles in the `ZSH_HIGHLIGHT_PATTERNS` array, for example in `~/.zshrc`: + + # To have commands starting with `rm -rf` in red: + ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red') + +The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/zsh-syntax-highlighting/highlighters/pattern/pattern-highlighter.zsh b/zsh-syntax-highlighting/highlighters/pattern/pattern-highlighter.zsh new file mode 100644 index 0000000..4e2eabd --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/pattern/pattern-highlighter.zsh @@ -0,0 +1,60 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 +# ------------------------------------------------------------------------------------------------- + + +# List of keyword and color pairs. +typeset -gA ZSH_HIGHLIGHT_PATTERNS + +# Whether the pattern highlighter should be called or not. +_zsh_highlight_pattern_highlighter_predicate() +{ + _zsh_highlight_buffer_modified +} + +# Pattern syntax highlighting function. +_zsh_highlight_pattern_highlighter() +{ + setopt localoptions extendedglob + local pattern + for pattern in ${(k)ZSH_HIGHLIGHT_PATTERNS}; do + _zsh_highlight_pattern_highlighter_loop "$BUFFER" "$pattern" + done +} + +_zsh_highlight_pattern_highlighter_loop() +{ + # This does *not* do its job syntactically, sorry. + local buf="$1" pat="$2" + local -a match mbegin mend + local MATCH; integer MBEGIN MEND + if [[ "$buf" == (#b)(*)(${~pat})* ]]; then + region_highlight+=("$((mbegin[2] - 1)) $mend[2] $ZSH_HIGHLIGHT_PATTERNS[$pat]") + "$0" "$match[1]" "$pat"; return $? + fi +} diff --git a/zsh-syntax-highlighting/highlighters/root/README.md b/zsh-syntax-highlighting/highlighters/root/README.md new file mode 100644 index 0000000..53c871b --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/root/README.md @@ -0,0 +1,24 @@ +zsh-syntax-highlighting / highlighters / root +================================================= + +This is the ***root*** highlighter, that highlights the whole line if the current user is root. + + +How to activate it +------------------ +To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: + + ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] root) + + +How to tweak it +--------------- +This highlighter defines the following styles: + +* `root` - the style for the whole line if the current user is root. + +To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: + + ZSH_HIGHLIGHT_STYLES[root]='bg=red' + +The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/zsh-syntax-highlighting/highlighters/root/root-highlighter.zsh b/zsh-syntax-highlighting/highlighters/root/root-highlighter.zsh new file mode 100644 index 0000000..4362379 --- /dev/null +++ b/zsh-syntax-highlighting/highlighters/root/root-highlighter.zsh @@ -0,0 +1,44 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 +# ------------------------------------------------------------------------------------------------- + + +# Define default styles. +: ${ZSH_HIGHLIGHT_STYLES[root]:=standout} + +# Whether the root highlighter should be called or not. +_zsh_highlight_root_highlighter_predicate() +{ + _zsh_highlight_buffer_modified +} + +# root highlighting function. +_zsh_highlight_root_highlighter() +{ + if [[ $(command id -u) -eq 0 ]] { region_highlight+=("0 $#BUFFER $ZSH_HIGHLIGHT_STYLES[root]") } +} diff --git a/zsh-syntax-highlighting/images/preview-smaller.png b/zsh-syntax-highlighting/images/preview-smaller.png new file mode 100644 index 0000000000000000000000000000000000000000..6fb84d18e545b56beef047eea45d7b03f9e50c05 GIT binary patch literal 5982 zcmYLN1x#F9v_%R-hd~OZK#_Kk;ySpL7I!P|?poXnrBJ*;8QhDz4DK?;rMSDp;BJ3j zet!N*&fUpP?mfxgYn`?B4pUZ?!U4VoqM)GQ$ViK;B4a9Yt74%cpF^7*1<3HyNm|EBkN~UzNnX-1KH*Z=qoBNblo9`|<~e_q?xpv8>gn&wC~2zt0GbdbREF@Azi8jCcqdo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9#20b2*bi+9UMNLj%Ax{ z_VIlgs0)2~=;@2aI6eJVFG(#KMUX4$m8v-2RHSw*7DCeM13GKi~?-)5$!e(nRvSoq$l~C@Jr^#Al73k-?M`2 zi`F7r;iso3q@UE*);uV1SZV1;I+U@qt@E?P|VxJ|1M`8*JrM!E_^DX4kE zz|!v%v0P<(a`InW5Dbhx9hU0F`+Qs-Y?OlwzBU^0i;@^Zhh8&A`rZiwFrHL-BFbwh zRaTL?HKD>%@76NG_~^%bW(Ediv#2;zVYt%ZywT!y?vOszCq5%9$3b%E<%5n*MP(5Z zf+n)L1s;q=AS9JT>#e}4V^jN=EBYP*NrWaPIg;MCK<5zoY)>;>*J%=X3HpS*7>zh)w#5PXdxw?LtzO=@4c) zidR*2&26h;2I^yClPWqqIBLB_{E@wM+H6A+O>t%hXsIS}iNh;)7nUG9h|9C3JL{}iKIYZUz-#=ILh)2$ja2Xs;KUXfv6&7mY zPWe%w1VH)yTl(f;>ng@-4l~!CGmqH7Lm+%fhG$-0co_LZKE&9!SG)+k)p4wcC2i+m zh09+FaLNP|#pMxZ%CU}nBdH5EN%xrg|Lu#u`2BlE_a64jB?4LHBWL3%G7^g7<)TJG F{{y@A$L;_C literal 0 HcmV?d00001 diff --git a/zsh-syntax-highlighting/images/preview.png b/zsh-syntax-highlighting/images/preview.png new file mode 100644 index 0000000000000000000000000000000000000000..545cc511abf0cc90fc9020cf6665f5aad2062eec GIT binary patch literal 14650 zcmbt*1yEgG*WSem9)dd|1Pd12-QDeCA-KD{dkF6C?(Q1g-GaNj_Pk%`Z@+0f?ca6= zHg_&}&OT@Dz1Jga-B5X1F=PZh1P};>EFmte2m(Q{0$@WR`NWP>wiKG&VWe^=e1LG-VUH zq8?>lRTDRv@9UG*&Gr5S_RYiF^En{_!3`oDENntT0)pSgRye)nyx-ZR)H54WLysyB z+0vo6^&-dX8~N}-uF_P8=QDzzys|R0`Fxo~>{mlW!w-HJd#Tn(*l%|$)-VF>_InYE zrs)zEG#Vn2n~QND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u5gVwkFygU%ECWT{hQ!yKYCl$%& z-vSvzl@c4d3G1huM=EZQvdqj59;bh9W5Jh>E_PW3=I@2G(_51ms(~VwPT4Z@-1O8X zfPOqY+_A`G+9a(M z&xDE*TOJ-34`HK;5Ix_ch_V5)ao+rc0*k<` za0yoP*|Li&l#~aa>G~t{e-xs3ii#*N0Z2!m!<-%&L2LrA37mH?C1zBtIB)4&zmIHo zvmmr#pj`yb2i}gZwE{5aG*dFO3{*7CnHiIl1u80HSL&GrJZ9vE=feE>_TYZeuR*8G18ZAD_WhT!Kg9U@UY@Y*{tDf6E2gYd#F4Po zhgR=$O<~&_14;T64#<}z`I(jZt+2=_GwS6!Q>7_hX22`e9?F4&L&3npaspa502TvO z#+;pn8g@jYRe6t zA`|xF#IM)7Ti)TP5^MhcfhhfM6mZac118AU`us=oJ>iOJI> zPe$s{hDvQa@xI|bJ^$TBvSIW;txps9RJ1rHTn{=L0W#ub^Qz*2w0uCa^gD==J9gl=f4pcq-FgJ# z-$;hH*$C60$a$td)~fHWAUTpFAD>*vTp1{B;`)H3=urYw6BT z+O(o^{IG2Cw~8Y1CTDAVyDPvD^|aj%3MCP`A0F%Q7v!AF_3NT9(y8K1s_}n8J3G zGm%Mw%H(vQ+`Wu*VBfeD>=dD2xpjG`3=bBkc#A6j{qz&7Y9CJ{aFM23$=7cbQubwF zfa#>gjQT1I0H#mTNUkN>sU!xiNQgg=aj=k04xCQD xYB17QfW9(>O^e56M^8;=Ff&B`e;!}>ve5sQS~R3P0bhm$Nr=b_R|x9){TGUlBl!RT literal 0 HcmV?d00001 diff --git a/zsh-syntax-highlighting/release.md b/zsh-syntax-highlighting/release.md new file mode 100644 index 0000000..a38d677 --- /dev/null +++ b/zsh-syntax-highlighting/release.md @@ -0,0 +1,15 @@ +# Release procedure (for developers): + +- Check open issues and outstanding pull requests +- Confirm `make test` passes + - check with multiple zsh versions +- Update changelog.md +- Remove `-dev` suffix from `./.version`; + Commit that; + Tag it using `git tag $(<.version)`; + Increment `./.version` and restore the `-dev` suffix; + Commit that. +- Push with `git push --tags` +- Notify downstreams (OS packages) + - anitya should autodetect the tag +- Update /topic on IRC diff --git a/zsh-syntax-highlighting/tests/README.md b/zsh-syntax-highlighting/tests/README.md new file mode 100644 index 0000000..e82a64b --- /dev/null +++ b/zsh-syntax-highlighting/tests/README.md @@ -0,0 +1,38 @@ +zsh-syntax-highlighting / tests +=============================== + +Utility scripts for testing zsh-syntax-highlighting highlighters. + +The tests expect the highlighter directory to contain a `test-data` directory with test data files. See the [main highlighter](../highlighters/main/test-data) for examples. + +Each test should define the array parameter `$expected_region_highlight`. +The value of that parameter is a list of `"$i $j $style [$todo]"` strings. +Each string specifies the highlighting that `$BUFFER[$i,$j]` should have; +that is, `$i` and `$j` specify a range, 1-indexed, inclusive of both endpoints. +If `$todo` exists, the test point is marked as TODO (the failure of that test point will not fail the test), and `$todo` is used as the explanation. + +_Note_: `$region_highlight` uses the same `"$i $j $style"` syntax but interprets the indexes differently. + + +highlighting test +----------------- +[`test-highlighting.zsh`](tests/test-highlighting.zsh) tests the correctness of the highlighting. Usage: + + zsh test-highlighting.zsh + +All tests may be run with + + make test + +which will run all highlighting tests and report results in [TAP](http://testanything.org/) format. + + +performance test +---------------- +[`test-perfs.zsh`](tests/test-perfs.zsh) measures the time spent doing the highlighting. Usage: + + zsh test-perfs.zsh + +All tests may be run with + + make perf diff --git a/zsh-syntax-highlighting/tests/tap-colorizer.zsh b/zsh-syntax-highlighting/tests/tap-colorizer.zsh new file mode 100755 index 0000000..cb645c6 --- /dev/null +++ b/zsh-syntax-highlighting/tests/tap-colorizer.zsh @@ -0,0 +1,67 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +# This is a stdin-to-stdout filter that takes TAP output (such as 'make test') +# on stdin and passes it, colorized, to stdout. + +emulate -LR zsh + +if [[ ! -t 1 ]] ; then + exec cat +fi + +while read -r line; +do + case $line in + # comment (filename header) or plan + (#* | <->..<->) + print -nP %F{blue} + ;; + # XPASS + (ok*# TODO*) + print -nP %F{red} + ;; + # XFAIL + (not ok*# TODO*) + print -nP %F{yellow} + ;; + # FAIL + (not ok*) + print -nP %F{red} + ;; + # PASS + (ok*) + print -nP %F{green} + ;; + esac + print -nr - "$line" + print -nP %f + echo "" # newline +done diff --git a/zsh-syntax-highlighting/tests/test-highlighting.zsh b/zsh-syntax-highlighting/tests/test-highlighting.zsh new file mode 100755 index 0000000..1eed974 --- /dev/null +++ b/zsh-syntax-highlighting/tests/test-highlighting.zsh @@ -0,0 +1,118 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2015 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 +# ------------------------------------------------------------------------------------------------- + + +# Check an highlighter was given as argument. +[[ -n "$1" ]] || { + echo >&2 "Bail out! You must provide the name of a valid highlighter as argument." + exit 2 +} + +# Check the highlighter is valid. +[[ -f ${0:h:h}/highlighters/$1/$1-highlighter.zsh ]] || { + echo >&2 "Bail out! Could not find highlighter '$1'." + exit 2 +} + +# Check the highlighter has test data. +[[ -d ${0:h:h}/highlighters/$1/test-data ]] || { + echo >&2 "Bail out! Highlighter '$1' has no test data." + exit 2 +} + +# Load the main script. +. ${0:h:h}/zsh-syntax-highlighting.zsh + +# Activate the highlighter. +ZSH_HIGHLIGHT_HIGHLIGHTERS=($1) + +# Runs a highlighting test +# $1: data file +run_test() { + local -a highlight_zone + local unused_highlight='bg=red,underline' # a style unused by anything else, for tests to use + + echo "# ${1:t:r}" + + # Load the data and prepare checking it. + PREBUFFER= BUFFER= ; + . "$1" + + # Check the data declares $PREBUFFER or $BUFFER. + [[ -z $PREBUFFER && -z $BUFFER ]] && { echo >&2 "Bail out! Either 'PREBUFFER' or 'BUFFER' must be declared and non-blank"; return 1; } + # Check the data declares $expected_region_highlight. + (( ${#expected_region_highlight} == 0 )) && { echo >&2 "Bail out! 'expected_region_highlight' is not declared or empty."; return 1; } + + # Process the data. + region_highlight=() + _zsh_highlight + + # Overlapping regions can be declared in region_highlight, so we first build an array of the + # observed highlighting. + local -A observed_result + for ((i=1; i<=${#region_highlight}; i++)); do + highlight_zone=${(z)region_highlight[$i]} + integer start=$highlight_zone[1] end=$highlight_zone[2] + if (( start < end )) # region_highlight ranges are half-open + then + (( --end )) # convert to closed range, like expected_region_highlight + (( ++start, ++end )) # region_highlight is 0-indexed; expected_region_highlight is 1-indexed + for j in {$start..$end}; do + observed_result[$j]=$highlight_zone[3] + done + else + # noop range; ignore. + fi + done + + # Then we compare the observed result with the expected one. + echo "1..${#expected_region_highlight}" + for ((i=1; i<=${#expected_region_highlight}; i++)); do + local todo= + highlight_zone=${(z)expected_region_highlight[$i]} + [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" + for j in {$highlight_zone[1]..$highlight_zone[2]}; do + if [[ "$observed_result[$j]" != "$highlight_zone[3]" ]]; then + echo "not ok $i '$BUFFER[$highlight_zone[1],$highlight_zone[2]]' [$highlight_zone[1],$highlight_zone[2]]: expected '$highlight_zone[3]', observed '$observed_result[$j]'.$todo" + continue 2 + fi + done + echo "ok $i$todo" + done +} + +# Process each test data file in test data directory. +integer something_failed=0 +for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do + (run_test "$data_file") | tee >(${0:A:h}/tap-colorizer.zsh) | grep -v '^not ok.*# TODO' | grep -q '^not ok\|^ok.*# TODO' && (( something_failed=1 )) + (( $pipestatus[1] )) && exit 2 +done + +exit $something_failed diff --git a/zsh-syntax-highlighting/tests/test-perfs.zsh b/zsh-syntax-highlighting/tests/test-perfs.zsh new file mode 100755 index 0000000..0d4adc3 --- /dev/null +++ b/zsh-syntax-highlighting/tests/test-perfs.zsh @@ -0,0 +1,75 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 +# ------------------------------------------------------------------------------------------------- + + +# Check an highlighter was given as argument. +[[ -n "$1" ]] || { + echo "You must provide the name of a valid highlighter as argument." >&2 + exit 1 +} + +# Check the highlighter is valid. +[[ -f ${0:h:h}/highlighters/$1/$1-highlighter.zsh ]] || { + echo "Could not find highlighter '$1'." >&2 + exit 1 +} + +# Check the highlighter has test data. +[[ -d ${0:h:h}/highlighters/$1/test-data ]] || { + echo "Highlighter '$1' has no test data." >&2 + exit 1 +} + +# Load the main script. +. ${0:h:h}/zsh-syntax-highlighting.zsh + +# Activate the highlighter. +ZSH_HIGHLIGHT_HIGHLIGHTERS=($1) + +# Process each test data file in test data directory. +for data_file in ${0:h:h}/highlighters/$1/test-data/*; do + + # Load the data and prepare checking it. + BUFFER= + echo -n "* ${data_file:t:r}: " + . $data_file + + # Check the data declares $BUFFER. + if [[ ${#BUFFER} -eq 0 ]]; then + echo "KO\n - 'BUFFER' is not declared or blank." + else + + # Measure the time taken by _zsh_highlight. + TIMEFMT="%*Es" + time ( BUFFER="$BUFFER" && _zsh_highlight) + + fi + +done diff --git a/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh b/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh new file mode 120000 index 0000000..cc95cd4 --- /dev/null +++ b/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh @@ -0,0 +1 @@ +zsh-syntax-highlighting.zsh \ No newline at end of file diff --git a/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh new file mode 100644 index 0000000..1d63dbf --- /dev/null +++ b/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh @@ -0,0 +1,281 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2015 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 +# ------------------------------------------------------------------------------------------------- + + +if [[ -o function_argzero ]]; then + # $0 is reliable + ZSH_HIGHLIGHT_VERSION=$(<"$0:A:h"/.version) + ZSH_HIGHLIGHT_REVISION=$(<"$0:A:h"/.revision-hash) + if [[ $ZSH_HIGHLIGHT_REVISION == \$Format:* ]]; then + # When running from a source tree without 'make install', $ZSH_HIGHLIGHT_REVISION + # would be set to '$Format:%H$' literally. That's an invalid value, and obtaining + # the valid value (via `git rev-parse HEAD`, as Makefile does) might be costly, so: + unset ZSH_HIGHLIGHT_REVISION + fi +else + # $0 is unreliable, so the call to _zsh_highlight_load_highlighters will fail. + # TODO: If 'zmodload zsh/parameter' is available, ${funcsourcetrace[1]%:*} might serve as a substitute? + # TODO: also check POSIX_ARGZERO, but not it's not available in older zsh + echo "zsh-syntax-highlighting: error: not compatible with FUNCTION_ARGZERO" >&2 + return 1 +fi + +# ------------------------------------------------------------------------------------------------- +# Core highlighting update system +# ------------------------------------------------------------------------------------------------- + +# Array declaring active highlighters names. +typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS + +# Update ZLE buffer syntax highlighting. +# +# Invokes each highlighter that needs updating. +# This function is supposed to be called whenever the ZLE state changes. +_zsh_highlight() +{ + # Store the previous command return code to restore it whatever happens. + local ret=$? + + setopt localoptions warncreateglobal + local REPLY # don't leak $REPLY into global scope + + # Do not highlight if there are more than 300 chars in the buffer. It's most + # likely a pasted command or a huge list of files in that case.. + [[ -n ${ZSH_HIGHLIGHT_MAXLENGTH:-} ]] && [[ $#BUFFER -gt $ZSH_HIGHLIGHT_MAXLENGTH ]] && return $ret + + # Do not highlight if there are pending inputs (copy/paste). + [[ $PENDING -gt 0 ]] && return $ret + + # Reset region highlight to build it from scratch + typeset -ga region_highlight + region_highlight=(); + + { + local cache_place + local -a region_highlight_copy + + # Select which highlighters in ZSH_HIGHLIGHT_HIGHLIGHTERS need to be invoked. + local highlighter; for highlighter in $ZSH_HIGHLIGHT_HIGHLIGHTERS; do + + # eval cache place for current highlighter and prepare it + cache_place="_zsh_highlight_${highlighter}_highlighter_cache" + typeset -ga ${cache_place} + + # If highlighter needs to be invoked + if "_zsh_highlight_${highlighter}_highlighter_predicate"; then + + # save a copy, and cleanup region_highlight + region_highlight_copy=("${region_highlight[@]}") + region_highlight=() + + # Execute highlighter and save result + { + "_zsh_highlight_${highlighter}_highlighter" + } always { + eval "${cache_place}=(\"\${region_highlight[@]}\")" + } + + # Restore saved region_highlight + region_highlight=("${region_highlight_copy[@]}") + + fi + + # Use value form cache if any cached + eval "region_highlight+=(\"\${${cache_place}[@]}\")" + + done + + # Re-apply zle_highlight settings + () { + if (( REGION_ACTIVE )) ; then + # zle_highlight[region] defaults to 'standout' if unspecified + local region="${${zle_highlight[(r)region:*]#region:}:-standout}" + integer start end + if (( MARK > CURSOR )) ; then + start=$CURSOR end=$MARK + else + start=$MARK end=$CURSOR + fi + region_highlight+=("$start $end $region") + fi + } + # YANK_ACTIVE is only available in zsh-5.1.1 and newer + (( $+YANK_ACTIVE )) && () { + if (( YANK_ACTIVE )) ; then + # zle_highlight[paste] defaults to 'standout' if unspecified + local paste="${${zle_highlight[(r)paste:*]#paste:}:-standout}" + integer start end + if (( YANK_END > YANK_START )) ; then + start=$YANK_START end=$YANK_END + else + start=$YANK_END end=$YANK_START + fi + region_highlight+=("$start $end $paste") + fi + } + + return $ret + + + } always { + typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER="$BUFFER" + typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=$CURSOR + } +} + + +# ------------------------------------------------------------------------------------------------- +# API/utility functions for highlighters +# ------------------------------------------------------------------------------------------------- + +# Array used by highlighters to declare user overridable styles. +typeset -gA ZSH_HIGHLIGHT_STYLES + +# Whether the command line buffer has been modified or not. +# +# Returns 0 if the buffer has changed since _zsh_highlight was last called. +_zsh_highlight_buffer_modified() +{ + [[ "${_ZSH_HIGHLIGHT_PRIOR_BUFFER:-}" != "$BUFFER" ]] +} + +# Whether the cursor has moved or not. +# +# Returns 0 if the cursor has moved since _zsh_highlight was last called. +_zsh_highlight_cursor_moved() +{ + [[ -n $CURSOR ]] && [[ -n ${_ZSH_HIGHLIGHT_PRIOR_CURSOR-} ]] && (($_ZSH_HIGHLIGHT_PRIOR_CURSOR != $CURSOR)) +} + + +# ------------------------------------------------------------------------------------------------- +# Setup functions +# ------------------------------------------------------------------------------------------------- + +# Helper for _zsh_highlight_bind_widgets +# $1 is name of widget to call +_zsh_highlight_call_widget() +{ + builtin zle "$@" && + _zsh_highlight +} + +# Rebind all ZLE widgets to make them invoke _zsh_highlights. +_zsh_highlight_bind_widgets() +{ + # Load ZSH module zsh/zleparameter, needed to override user defined widgets. + zmodload zsh/zleparameter 2>/dev/null || { + echo 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' >&2 + return 1 + } + + # Override ZLE widgets to make them invoke _zsh_highlight. + local cur_widget + for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|set-local-history|yank)}; do + case $widgets[$cur_widget] in + + # Already rebound event: do nothing. + user:$cur_widget|user:_zsh_highlight_widget_*);; + + # User defined widget: override and rebind old one with prefix "orig-". + user:*) eval "zle -N orig-$cur_widget ${widgets[$cur_widget]#*:}; \ + _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget \"\$@\" }; \ + zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; + + # Completion widget: override and rebind old one with prefix "orig-". + completion:*) eval "zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \ + _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget \"\$@\" }; \ + zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; + + # Builtin widget: override and make it call the builtin ".widget". + builtin) eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget .$cur_widget \"\$@\" }; \ + zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; + + # Default: unhandled case. + *) echo "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" >&2 ;; + esac + done +} + +# Load highlighters from directory. +# +# Arguments: +# 1) Path to the highlighters directory. +_zsh_highlight_load_highlighters() +{ + # Check the directory exists. + [[ -d "$1" ]] || { + echo "zsh-syntax-highlighting: highlighters directory '$1' not found." >&2 + return 1 + } + + # Load highlighters from highlighters directory and check they define required functions. + local highlighter highlighter_dir + for highlighter_dir ($1/*/); do + highlighter="${highlighter_dir:t}" + [[ -f "$highlighter_dir/${highlighter}-highlighter.zsh" ]] && { + . "$highlighter_dir/${highlighter}-highlighter.zsh" + type "_zsh_highlight_${highlighter}_highlighter" &> /dev/null && + type "_zsh_highlight_${highlighter}_highlighter_predicate" &> /dev/null || { + echo "zsh-syntax-highlighting: '${highlighter}' highlighter should define both required functions '_zsh_highlight_${highlighter}_highlighter' and '_zsh_highlight_${highlighter}_highlighter_predicate' in '${highlighter_dir}/${highlighter}-highlighter.zsh'." >&2 + } + } + done +} + + +# ------------------------------------------------------------------------------------------------- +# Setup +# ------------------------------------------------------------------------------------------------- + +# Try binding widgets. +_zsh_highlight_bind_widgets || { + echo 'zsh-syntax-highlighting: failed binding ZLE widgets, exiting.' >&2 + return 1 +} + +# Resolve highlighters directory location. +_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/highlighters}" || { + echo 'zsh-syntax-highlighting: failed loading highlighters, exiting.' >&2 + return 1 +} + +# Reset scratch variables when commandline is done. +_zsh_highlight_preexec_hook() +{ + typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER= + typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR= +} +autoload -U add-zsh-hook +add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || { + echo 'zsh-syntax-highlighting: failed loading add-zsh-hook.' >&2 + } + +# Initialize the array of active highlighters if needed. +[[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) || true