├── .fast-make-targets ├── .fast-read-ini-file ├── .fast-run-command ├── .fast-run-git-command ├── .fast-zts-read-all ├── .github └── workflows │ ├── linting.yml │ └── zunit.yaml ├── .gitignore ├── .zunit.yml ├── CHANGELOG.md ├── CHROMA_GUIDE.adoc ├── LICENSE ├── README.md ├── THEME_GUIDE.md ├── _fast-theme ├── fast-highlight ├── fast-string-highlight ├── fast-syntax-highlighting.plugin.zsh ├── fast-theme ├── images ├── 203654.gif ├── array-assign.png ├── assign.png ├── brackets.gif ├── cmdsubst.png ├── cplx_cond.png ├── eval_cmp.png ├── execfd.png ├── execfd_cmp.png ├── for-loop-cmp.png ├── for-loop.png ├── function.png ├── git_chroma.png ├── global-alias.png ├── heredoc.png ├── herestring.png ├── highlight-less.png ├── highlight-much.png ├── ideal-string.png ├── in_string.png ├── math.gif ├── parameter.png ├── theme.png ├── typeset.png └── zcalc.png ├── share └── free_theme.zsh ├── test ├── parse.zsh └── to-parse.zsh ├── tests ├── _output │ └── .gitkeep ├── _support │ ├── .gitkeep │ └── bootstrap ├── example.zunit └── main.zunit ├── themes ├── base16.ini ├── clean.ini ├── default.ini ├── forest.ini ├── free.ini ├── q-jmnemonic.ini ├── safari.ini ├── spa.ini ├── sv-orple.ini ├── sv-plant.ini └── zdharma.ini └── →chroma ├── -alias.ch ├── -autoload.ch ├── -autorandr.ch ├── -awk.ch ├── -docker.ch ├── -example.ch ├── -fast-theme.ch ├── -fpath_peq.ch ├── -git.ch ├── -grep.ch ├── -hub.ch ├── -ionice.ch ├── -lab.ch ├── -make.ch ├── -nice.ch ├── -nmcli.ch ├── -node.ch ├── -ogit.ch ├── -perl.ch ├── -precommand.ch ├── -printf.ch ├── -ruby.ch ├── -scp.ch ├── -sh.ch ├── -source.ch ├── -ssh.ch ├── -subcommand.ch ├── -subversion.ch ├── -vim.ch ├── -whatis.ch ├── -which.ch ├── -zinit.ch └── main-chroma.ch /.fast-make-targets: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Almost all code borrowed from Zshell's _make function 3 | # 4 | # Copyright (c) 2018 Sebastian Gniazdowski 5 | 6 | local -a TARGETS 7 | 8 | .make-expandVars() { 9 | local open close var val front='' rest=$1 10 | 11 | while [[ $rest == (#b)[^$]#($)* ]]; do 12 | front=$front${rest[1,$mbegin[1]-1]} 13 | rest=${rest[$mbegin[1],-1]} 14 | 15 | case $rest[2] in 16 | ($) # '$$'. may not appear in target and variable's value 17 | front=$front\$\$ 18 | rest=${rest[3,-1]} 19 | continue 20 | ;; 21 | (\() # Variable of the form $(foobar) 22 | open='(' 23 | close=')' 24 | ;; 25 | ({) # ${foobar} 26 | open='{' 27 | close='}' 28 | ;; 29 | ([[:alpha:]]) # $foobar. This is exactly $(f)oobar. 30 | open='' 31 | close='' 32 | var=$rest[2] 33 | ;; 34 | (*) # bad parameter name 35 | print -- $front$rest 36 | return 1 37 | ;; 38 | esac 39 | 40 | if [[ -n $open ]]; then 41 | if [[ $rest == \$$open(#b)([[:alnum:]_]##)(#B)$close* ]]; then 42 | var=$match 43 | else # unmatched () or {}, or bad parameter name 44 | print -- $front$rest 45 | return 1 46 | fi 47 | fi 48 | 49 | val='' 50 | if [[ -n ${VAR_ARGS[(i)$var]} ]]; then 51 | val=${VAR_ARGS[$var]} 52 | else 53 | if [[ -n $opt_args[(I)(-e|--environment-overrides)] ]]; then 54 | if [[ $parameters[$var] == scalar-export* ]]; then 55 | val=${(P)var} 56 | elif [[ -n ${VARIABLES[(i)$var]} ]]; then 57 | val=${VARIABLES[$var]} 58 | fi 59 | else 60 | if [[ -n ${VARIABLES[(i)$var]} ]]; then 61 | val=${VARIABLES[$var]} 62 | elif [[ $parameters[$var] == scalar-export* ]]; then 63 | val=${(P)var} 64 | fi 65 | fi 66 | fi 67 | rest=${rest//\$$open$var$close/$val} 68 | done 69 | 70 | print -- ${front}${rest} 71 | } 72 | 73 | 74 | .make-parseMakefile () { 75 | local input var val target dep TAB=$'\t' tmp IFS= 76 | 77 | while read input 78 | do 79 | case "$input " in 80 | # TARGET: dependencies 81 | # TARGET1 TARGET2 TARGET3: dependencies 82 | ([[*?[:alnum:]$][^$TAB:=%]#:[^=]*) 83 | target=$(.make-expandVars ${input%%:*}) 84 | TARGETS+=( ${(z)target} ) 85 | ;; 86 | esac 87 | done 88 | } 89 | 90 | if [[ -z "${FAST_HIGHLIGHT[chroma-make-cache]}" || $(( EPOCHSECONDS - FAST_HIGHLIGHT[chroma-make-cache-born-at] )) -gt 7 ]]; then 91 | .make-parseMakefile 92 | FAST_HIGHLIGHT[chroma-make-cache-born-at]="$EPOCHSECONDS" 93 | FAST_HIGHLIGHT[chroma-make-cache]="${(j:;:)TARGETS}" 94 | fi 95 | 96 | reply2=( "${(s:;:)FAST_HIGHLIGHT[chroma-make-cache]}" ) 97 | 98 | # vim:ft=zsh:et 99 | -------------------------------------------------------------------------------- /.fast-read-ini-file: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018 Sebastian Gniazdowski 2 | # 3 | # $1 - path to the ini file to parse 4 | # $2 - name of output hash (INI by default) 5 | # $3 - prefix for keys in the hash (can be empty) 6 | # 7 | # Writes to given hash under keys built in following way: ${3}
_field. 8 | # Values are values from ini file. 9 | 10 | local __ini_file="$1" __out_hash="${2:-INI}" __key_prefix="$3" 11 | local IFS='' __line __cur_section="void" __access_string 12 | local -a match mbegin mend 13 | 14 | [[ ! -r "$__ini_file" ]] && { builtin print -r "fast-syntax-highlighting: an ini file is unreadable ($__ini_file)"; return 1; } 15 | 16 | while read -r -t 1 __line; do 17 | if [[ "$__line" = [[:blank:]]#\;* ]]; then 18 | continue 19 | elif [[ "$__line" = (#b)[[:blank:]]#\[([^\]]##)\][[:blank:]]# ]]; then 20 | __cur_section="${match[1]}" 21 | elif [[ "$__line" = (#b)[[:blank:]]#([^[:blank:]=]##)[[:blank:]]#[=][[:blank:]]#(*) ]]; then 22 | match[2]="${match[2]%"${match[2]##*[! $'\t']}"}" # remove trailing whitespace 23 | __access_string="${__out_hash}[${__key_prefix}<$__cur_section>_${match[1]}]" 24 | : "${(P)__access_string::=${match[2]}}" 25 | fi 26 | done < "$__ini_file" 27 | 28 | return 0 29 | 30 | # vim:ft=zsh:sw=4:sts=4:et 31 | -------------------------------------------------------------------------------- /.fast-run-command: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # FAST_HIGHLIGHT hash serves as container for variables that 5 | # prevents creating them in global scope. (P) flag is not used, 6 | # output array is fixed (__lines_list). 7 | # 8 | # $1 - the command, e.g. "git remote"; 2>/dev/null redirection is 9 | # added automatically 10 | # $2 - FAST_HIGHLIGHT field name, e.g. "chroma-git-branches"; two 11 | # additional fields will be used, $2-cache, $2-cache-born-at 12 | # $3 - what to remove from beginning of the lines returned by the 13 | # command 14 | # $4 - cache validity time, default 5 (seconds) 15 | # 16 | # Output: array __lines_list, with output of the command ran 17 | 18 | # User should not forget to define this array, the below code 19 | # will only ensure that it's array (can also define a global) 20 | typeset -ga __lines_list 21 | local -a __response 22 | 23 | if [[ -z "${FAST_HIGHLIGHT[$2-cache]}" || $(( EPOCHSECONDS - FAST_HIGHLIGHT[$2-cache-born-at] )) -gt ${4:-5} ]]; then 24 | FAST_HIGHLIGHT[$2-cache-born-at]="$EPOCHSECONDS" 25 | __response=( ${${(f)"$(command ${(Qz)1#+} 2>/dev/null)"}#${~3}} ) 26 | [[ "$1" = "+"* ]] && __lines_list+=( "${__response[@]}" ) || __lines_list=( "${__response[@]}" ) 27 | FAST_HIGHLIGHT[$2-cache]="${(j:;:)__response}" 28 | else 29 | # Quoted (s:;:) flag without @ will skip empty elements. It 30 | # still produces array output, interesingly. All this is for 31 | # the trailing ";" above, to skip last, empty element. 32 | [[ "$1" = "+"* ]] && \ 33 | __lines_list+=( "${(@s:;:)FAST_HIGHLIGHT[$2-cache]}" ) || \ 34 | __lines_list=( "${(@s:;:)FAST_HIGHLIGHT[$2-cache]}" ) 35 | fi 36 | 37 | # vim:ft=zsh:et:sw=4 38 | -------------------------------------------------------------------------------- /.fast-run-git-command: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # It runs given command, which in general will be a git command, 5 | # automatically looking at cache first (a field named *-cache, 6 | # in FAST_HIGHLIGHT), which is valid for 5 seconds, and in case 7 | # of outdated or not existing cache, runs the command, splitting 8 | # on new-lines, first checking if PWD is inside git repository. 9 | # 10 | # FAST_HIGHLIGHT hash serves as container for variables that 11 | # prevents creating them in global scope. (P) flag is not used, 12 | # output array is fixed (__lines_list). 13 | # 14 | # $1 - the command, e.g. "git remote"; 2>/dev/null redirection is 15 | # added automatically 16 | # $2 - FAST_HIGHLIGHT field name, e.g. "chroma-git-branches"; two 17 | # additional fields will be used, $2-cache, $2-cache-born-at 18 | # $3 - what to remove from beginning of the lines returned by the 19 | # command 20 | # $4 - cache validity time, default 5 (seconds) 21 | # 22 | # Output: array __lines_list, with output of the (git) command ran 23 | 24 | # User should not forget to define this array, the below code 25 | # will only ensure that it's array (can also define a global) 26 | typeset -ga __lines_list 27 | local -a __response 28 | 29 | if [[ $1 == --status ]] { 30 | integer __status=1 31 | shift 32 | } 33 | 34 | if [[ -z ${FAST_HIGHLIGHT[$2-cache]} || $(( EPOCHSECONDS - FAST_HIGHLIGHT[$2-cache-born-at] )) -gt ${4:-5} ]]; then 35 | FAST_HIGHLIGHT[$2-cache-born-at]=$EPOCHSECONDS 36 | if [[ "$(command git rev-parse --is-inside-work-tree 2>/dev/null)" = true ]]; then 37 | __response=( ${${(f)"$(command ${(Qz)${1#+}} 2>/dev/null)"}#$3} ) 38 | integer retval=$? 39 | if (( __status )) { 40 | __response=( $retval ) 41 | __lines_list=( $retval ) 42 | } else { 43 | [[ "$1" = "+"* ]] && \ 44 | __lines_list+=( "${__response[@]}" ) || \ 45 | __lines_list=( "${__response[@]}" ) 46 | } 47 | else 48 | __lines_list=() 49 | fi 50 | FAST_HIGHLIGHT[$2-cache]="${(j:;:)__response}" 51 | else 52 | # Quoted (s:;:) flag without @ will skip empty elements. It 53 | # still produces array output, interesingly. All this is for 54 | # the trailing ";" above, to skip last, empty element. 55 | [[ "$1" = "+"* ]] && \ 56 | __lines_list+=( "${(@s:;:)FAST_HIGHLIGHT[$2-cache]}" ) || \ 57 | __lines_list=( "${(@s:;:)FAST_HIGHLIGHT[$2-cache]}" ) 58 | fi 59 | 60 | # vim:ft=zsh:et:sw=4 61 | -------------------------------------------------------------------------------- /.fast-zts-read-all: -------------------------------------------------------------------------------- 1 | # $1 - file-descriptor to be read from 2 | # $2 - name of output variable (default: REPLY) 3 | 4 | local __in_fd=${1:-0} __out_var=${2:-REPLY} 5 | local -a __tmp 6 | integer __ret=1 __repeat=10 __tmp_size=0 7 | 8 | while sysread -s 65535 -i "$__in_fd" '__tmp[__tmp_size + 1]'; do 9 | (( ( __ret=$? ) == 0 )) && (( ++ __tmp_size )) 10 | (( __ret == 5 )) && { __ret=0; (( --__repeat == 0 )) && break; } 11 | done 12 | 13 | : ${(P)__out_var::="${(j::)__tmp}"} 14 | 15 | return __ret 16 | 17 | # vim: ft=zsh:et:sw=4:sts=4 18 | -------------------------------------------------------------------------------- /.github/workflows/linting.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | push: 8 | branches: 9 | - main 10 | workflow_dispatch: 11 | 12 | jobs: 13 | 14 | lint: 15 | name: Lint 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@v3 19 | 20 | - name: install dependencies 21 | run: | 22 | brew install shellcheck shfmt zsh 23 | pip3 install --user linkify-it-py mdformat mdformat-config mdformat-gfm mdformat-shfmt mdformat-tables mdformat-toc 24 | 25 | - name: run mdformat 26 | run: find . -name '*.md' -type f -print0 | xargs -0 -n1 -P4 python3 -m mdformat --check --wrap 120 27 | 28 | - name: run shfmt 29 | run: find . -name '*.sh' -type f -print0 | xargs -0 -n1 -P4 shfmt -bn -ci -d -i 2 -ln bash -s -sr 30 | 31 | - name: run shellcheck 32 | run: find . -name '*.sh' -type f -print0 | xargs -0 -n1 -P4 shellcheck 33 | 34 | - name: "run zsh" 35 | run: find . -name '*.zsh' -type f -print0 | xargs -0 -n1 -P4 zsh -n 36 | 37 | - name: "run zcompile" 38 | run: find . -name '*.zsh' -type f -exec zsh -fc "zcompile {}" \; 39 | -------------------------------------------------------------------------------- /.github/workflows/zunit.yaml: -------------------------------------------------------------------------------- 1 | name: zunit 2 | on: [push, pull_request] 3 | jobs: 4 | zunit: 5 | runs-on: ubuntu-latest 6 | 7 | steps: 8 | - name: Check out repository code 9 | uses: actions/checkout@v2 10 | 11 | - name: Install dependencies 12 | run: | 13 | sudo apt install -y zsh 14 | 15 | mkdir bin 16 | curl -fsSL https://raw.githubusercontent.com/molovo/revolver/v0.2.4/revolver > bin/revolver 17 | curl -fsSL https://raw.githubusercontent.com/molovo/color/d8f91ab5fcfceb623ae45d3333ad0e543775549c/color.zsh > bin/color 18 | 19 | git clone https://github.com/zunit-zsh/zunit.git zunit.git 20 | cd zunit.git 21 | git checkout b86c006f62db138a119e9be3a4b41e28876889b2 22 | ./build.zsh 23 | cd .. 24 | mv ./zunit.git/zunit bin 25 | 26 | chmod u+x bin/{color,revolver,zunit} 27 | 28 | - name: Unit tests 29 | run: | 30 | export PATH="$PWD/bin:$PATH" 31 | zunit 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | current_theme.zsh 2 | secondary_theme.zsh 3 | theme_overlay.zsh 4 | *.txt 5 | test/out.parse 6 | test/res 7 | hold/* 8 | *.zwc 9 | 10 | ### Vim 11 | # Swap 12 | [._]*.s[a-v][a-z] 13 | [._]*.sw[a-p] 14 | [._]s[a-v][a-z] 15 | [._]sw[a-p] 16 | 17 | # Session 18 | Session.vim 19 | 20 | # Temporary 21 | .netrwhist 22 | *~ 23 | # Auto-generated tag files 24 | tags 25 | -------------------------------------------------------------------------------- /.zunit.yml: -------------------------------------------------------------------------------- 1 | tap: false 2 | directories: 3 | tests: tests 4 | output: tests/_output 5 | support: tests/_support 6 | time_limit: 0 7 | fail_fast: false 8 | allow_risky: false 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # News On Updates in F-Sy-H 2 | 3 | **2018-08-09** 4 | 5 | Added ideal string highlighting – FSH now handles any legal quoting and combination of `"`,`'` and `\` when highlighting 6 | program arguments. See the introduction for an example (item #14). 7 | 8 | **2018-08-02** 9 | 10 | Global aliases are now supported: 11 | 12 | ![image](https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/master/images/global-alias.png) 13 | 14 | **2018-08-01** 15 | 16 | Hint – how to customize styles when using Zplugin and turbo mode: 17 | 18 | ```zsh 19 | zplugin ice wait"1" atload"set_fast_theme" 20 | zplugin light zdharma/fast-syntax-highlighting 21 | 22 | set_fast_theme() { 23 | FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}paired-bracket]='bg=blue' 24 | FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}bracket-level-1]='fg=red,bold' 25 | FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}bracket-level-2]='fg=magenta,bold' 26 | FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}bracket-level-3]='fg=cyan,bold' 27 | } 28 | ``` 29 | 30 | If you have set theme before an update of styles (e.g. recent addition of bracket highlighting) then please repeat 31 | `fast-theme {theme}` call to regenerate theme files. (**2018-08-09**: FSH now has full user-theme support, refer to 32 | [appropriate section of README](#customization)). 33 | 34 | **2018-07-30** 35 | 36 | Ideal highlighting of brackets (pairing, etc.) – no quoting can disturb the result: 37 | 38 | ![image](https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/master/images/brackets.gif) 39 | 40 | `FAST_HIGHLIGHT[use_brackets]=1` to enable this feature (**2018-07-31**: not needed anymore, this highlighting is active 41 | by default). 42 | 43 | **2018-07-21** 44 | 45 | Chroma architecture now supports aliases. You can have `alias mygit="git commit"` and when `mygit` will be invoked 46 | everything will work as expected (Git chroma will be ran). 47 | 48 | **2018-07-11** 49 | 50 | There were problems with Ctrl-C not working when using FSH. After many days I've found a fix for this, it's pushed to 51 | master. 52 | 53 | Second, asynchronous path checking (useful on e.g. slow network drives, or when there are many files in directory) is 54 | now optional. Set `FAST_HIGHLIGHT[use_async]=1` to enable it. This saves some users from Zshell crashes – there's an 55 | unknown bug in Zsh. 56 | 57 | **2018-06-09** 58 | 59 | New chroma functions: `awk`, `make`, `perl`, `vim`. Checkout the [video](https://asciinema.org/a/186234), it shows 60 | functionality of `awk` – compiling of code and NOT running it. Perl can do this too: 61 | [video](https://asciinema.org/a/186098). 62 | 63 | **2018-06-06** 64 | 65 | FSH gained a new architecture – "chroma functions". They are similar to "completion functions", i.e. they are defined 66 | **per-command**, but instead of completing that command, they colorize it. Two chroma exist, for `Git` 67 | ([video](https://asciinema.org/a/185707), [video](https://asciinema.org/a/185811)) and for `grep` 68 | ([video](https://asciinema.org/a/185942)). Checkout 69 | [example chroma](https://github.com/zdharma/fast-syntax-highlighting/blob/master/chroma/-example.ch) if you would like 70 | to highlight a command. 71 | 72 | ![sshot](https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/master/images/git_chroma.png) 73 | 74 | **2018-06-01** 75 | 76 | Highlighting of command substitution (i.e. `$(...)`) with alternate theme – two themes at once! It was just white 77 | before: 78 | 79 | ![sshot](https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/master/images/cmdsubst.png) 80 | 81 | To select which theme to use for `$(...)` set the key `secondary=` in 82 | [theme ini file](https://github.com/zdharma/fast-syntax-highlighting/blob/master/themes/free.ini#L7). All shipped themes 83 | have this key set (only the `default` theme doesn't use second theme). 84 | 85 | Also added correct highlighting of descriptor-variables passed to `exec`: 86 | 87 | ![sshot](https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/master/images/execfd.png) 88 | 89 | **2018-05-30** 90 | 91 | For-loop is highlighted, it has separate settings in 92 | [theme file](https://github.com/zdharma/fast-syntax-highlighting/blob/master/themes/free.ini). 93 | 94 | ![sshot](https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/master/images/for-loop.png) 95 | 96 | **2018-05-27** 97 | 98 | Added support for 256-color themes. There are six themes shipped with FSH. The command to switch theme is 99 | `fast-theme {theme-name}`, it has a completion which lists available themes and options. Checkout 100 | [asciinema recording](https://asciinema.org/a/183814) that presents the themes. 101 | 102 | **2018-05-25** 103 | 104 | Hash holding paths that shouldn't be grepped (globbed) – blacklist for slow disks, mounts, etc.: 105 | 106 | ```zsh 107 | typeset -gA FAST_BLIST_PATTERNS 108 | FAST_BLIST_PATTERNS[/mount/nfs1/*]=1 109 | FAST_BLIST_PATTERNS[/mount/disk2/*]=1 110 | ``` 111 | 112 | **2018-05-23** 113 | 114 | Assign colorizing now spans to variables defined by `typeset`, `export`, `local`, etc.: 115 | 116 | ![sshot](https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/master/images/typeset.png) 117 | 118 | Also, `zcalc` has a separate math mode and specialized highlighting – no more light-red colors because of treating 119 | `zcalc` like a regular command-line: 120 | 121 | ![sshot](https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/master/images/zcalc.png) 122 | 123 | **2018-05-22** 124 | 125 | Array assignments were still boring, so I throwed in bracked colorizing: 126 | 127 | ![sshot](https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/master/images/array-assign.png) 128 | 129 | **2018-05-22** 130 | 131 | Assignments are no more one-colour default-white. When used in assignment, highlighted are: 132 | 133 | - variables (outside strings), 134 | - strings (double-quoted and single-quoted), 135 | - math-mode (`val=$(( ... ))`). 136 | 137 | ![sshot](https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/master/images/assign.png) 138 | 139 | **2018-01-06** 140 | 141 | Math mode is highlighted – expressions `(( ... ))` and `$(( ... ))`. Empty variables are colorized as red. There are 3 142 | style names (fields of 143 | [FAST_HIGHLIGHT_STYLES](https://github.com/zdharma/fast-syntax-highlighting/blob/master/fast-highlight#L34) hash) for 144 | math-variable, number and empty variable (error): `mathvar`, `mathnum`, `matherr`. You can set them (like the animation 145 | below shows) to change colors. 146 | 147 | ![animation](https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/master/images/math.gif) 148 | -------------------------------------------------------------------------------- /CHROMA_GUIDE.adoc: -------------------------------------------------------------------------------- 1 | # Chroma Guide for F-Sy-H 2 | 3 | ## Motivation 4 | 5 | Someone might want to create a detailed highlighting for a **specific program** 6 | and this document helps achieving this. It explains how chroma functions – the 7 | code behind such detailed highlighting – are constructed and used. 8 | 9 | ## Keywords 10 | 11 | - `chroma` - a shorthand for `chroma function` – the thing that literally colorizes selected commands, like `git`, `grep`, etc. invocations, see `chroma function` below, 12 | - `big loop` - main highlighting code, a loop over tokens and at least 2 large structular constructs (big `if` and `case`); 13 | it is advanced, e.g. parses `case` statements, here-string, it basically constitutes 90% of the F-Sy-H project, 14 | - `chroma function` - a plugin-function that is called when a specific command occurs (e.g. when user enters `git` at 15 | command line) suppressing activity of `big loop` (i.e. no standard highlighting unless requested), 16 | - `token` - result of splitting whole command line (i.e. `$BUFFER`, the Zle variable) into bits called tokens, which are 17 | words in general, separated by spaces on the command line. 18 | 19 | ## Overview Of Functioning 20 | 21 | 1. Big loop is working – token by token processes command line, changes states (e.g. enters state "inside case 22 | statement") and in the end decides on color of the token currently processed. 23 | 24 | 2. Big loop occurs a command that has a chroma, e.g. `git`. 25 | 26 | 3. Big loop enters "chroma" state, calls associated chroma function. 27 | 28 | 4. Chroma takes care of "chroma" state, ensures it will be set also for next token. 29 | 30 | 5. "chroma" state is active, so all following tokens are routed to the chroma (in general skipping big-loop, see next items), 31 | 32 | 6. When processing of a single token is complete, the associated chroma returns 0 33 | (shell-truth) to request no further processing by the big loop. 34 | 35 | 7. It can also return 1 so that single, current token will be passed into big-loop 36 | for processing (to do a standard highlighting). 37 | 38 | ## Chroma-Function Arguments 39 | 40 | - `$1` - 0 or 1, denoting if it's the first call to the chroma, or a following one, 41 | 42 | - `$2` - the current token, also accessible by `$\__arg` from the upper scope - 43 | basically a private copy of `$__arg`; the token can be eg.: "grep", 44 | 45 | - `$3` - a private copy of `$_start_pos`, i.e. the position of the token in the 46 | command line buffer, used to add region_highlight entry (see man), 47 | because Zsh colorizes by *ranges* applied onto command line buffer (e.g. 48 | `from-10 to-13 fg=red`), 49 | 50 | - `$4` - a private copy of `$_end_pos` from the upper scope; denotes where current token 51 | ends (at which index in the string being the command line). 52 | 53 | So example invocation could look like this: 54 | 55 | ---- 56 | chroma/-example.ch 1 "grep" "$_start_pos" "$_end_pos" 57 | ---- 58 | 59 | Big-loop will be doing such calls for the user, after occurring a specific chroma-enabled command (like e.g. `awk`), and then until chroma will detect end of this chroma-enabled command (end of whole invocation, with arguments, etc.; in other words, when e.g. new line or `;`-character occurs, etc.). 60 | 61 | ## Example Chroma-Function 62 | 63 | [source,zsh] 64 | ---- 65 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 66 | # Copyright (c) 2018 Sebastian Gniazdowski 67 | # 68 | # Example chroma function. It colorizes first two arguments as `builtin' style, 69 | # third and following arguments as `globbing' style. First two arguments may 70 | # be "strings", they will be passed through to normal higlighter (by returning 1). 71 | # 72 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 73 | # 74 | # $2 - like above document says 75 | # 76 | # $3 - ... 77 | # 78 | # $4 - ... 79 | # 80 | # Other tips are: 81 | # - $CURSOR holds cursor position 82 | # - $BUFFER holds whole command line buffer 83 | # - $LBUFFER holds command line buffer that is left from the cursor, i.e. it's a 84 | # BUFFER substring 1 .. $CURSOR 85 | # - $RBUFFER is the same as LBUFFER but holds part of BUFFER right to the cursor 86 | # 87 | # The function receives $BUFFER but via sequence of tokens, which are shell words, 88 | # e.g. "a b c" is a shell word, while a b c are 3 shell words. 89 | # 90 | # FAST_HIGHLIGHT is a friendly hash array which allows to store strings without 91 | # creating global parameters (variables). If you need hash, go ahead and use it, 92 | # declaring first, under some distinct name like: typeset -gA CHROMA_EXPLE_DICT. 93 | # Remember to reset the hash and others at __first_call == 1, so that you have 94 | # a fresh state for new command. 95 | 96 | # Keep chroma-takever state meaning: until ;, handle highlighting via chroma. 97 | # So the below 8192 assignment takes care that next token will be routed to chroma. 98 | (( next_word = 2 | 8192 )) 99 | 100 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 101 | local __style 102 | integer __idx1 __idx2 103 | 104 | (( __first_call )) && { 105 | # Called for the first time - new command. 106 | # FAST_HIGHLIGHT is used because it survives between calls, and 107 | # allows to use a single global hash only, instead of multiple 108 | # global string variables. 109 | FAST_HIGHLIGHT[chroma-example-counter]=0 110 | 111 | # Set style for region_highlight entry. It is used below in 112 | # '[[ -n "$__style" ]] ...' line, which adds highlight entry, 113 | # like "10 12 fg=green", through `reply' array. 114 | # 115 | # Could check if command `example' exists and set `unknown-token' 116 | # style instead of `command' 117 | __style=${FAST_THEME_NAME}command 118 | 119 | } || { 120 | # Following call, i.e. not the first one 121 | 122 | # Check if chroma should end – test if token is of type 123 | # "starts new command", if so pass-through – chroma ends 124 | [[ "$__arg_type" = 3 ]] && return 2 125 | 126 | if [[ "$__wrd" = -* ]]; then 127 | # Detected option, add style for it. 128 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 129 | __style=${FAST_THEME_NAME}single-hyphen-option 130 | else 131 | # Count non-option tokens 132 | (( FAST_HIGHLIGHT[chroma-example-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-example-counter] )) 133 | 134 | # Colorize 1..2 as builtin, 3.. as glob 135 | if (( FAST_HIGHLIGHT[chroma-example-counter] <= 2 )); then 136 | if [[ "$__wrd" = \"* ]]; then 137 | # Pass through, fsh main code will do the highlight! 138 | return 1 139 | else 140 | __style=${FAST_THEME_NAME}builtin 141 | fi 142 | else 143 | __style=${FAST_THEME_NAME}globbing 144 | fi 145 | fi 146 | } 147 | 148 | # Add region_highlight entry (via `reply' array). 149 | # If 1 will be added to __start_pos, this will highlight "oken". 150 | # If 1 will be subtracted from __end_pos, this will highlight "toke". 151 | # $PREBUFFER is for specific situations when users does command \ 152 | # i.e. when multi-line command using backslash is entered. 153 | # 154 | # This is a common place of adding such entry, but any above code can do 155 | # it itself (and it does in other chromas) and skip setting __style to 156 | # this way disable this code. 157 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 158 | 159 | # We aren't passing-through, do obligatory things ourselves. 160 | # _start_pos=$_end_pos advainces pointers in command line buffer. 161 | (( this_word = next_word )) 162 | _start_pos=$_end_pos 163 | 164 | return 0 165 | ---- 166 | 167 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2016 zsh-syntax-highlighting contributors 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted 5 | provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this list of conditions 8 | and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, this list of 10 | conditions and the following disclaimer in the documentation and/or other materials provided 11 | with the distribution. 12 | * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors 13 | may be used to endorse or promote products derived from this software without specific prior 14 | written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 17 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 19 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 22 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 23 | OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fast Syntax Highlighting (F-Sy-H) [![Gitter][gitter-image]][gitter-link] 2 | 3 | Feature rich syntax highlighting for Zsh. 4 | 5 |
6 | image could not be loaded 11 |
12 | 13 | ### Table of Contents 14 | 15 | - [News](#news) 16 | - [Installation](#installation) 17 | - [Features](#features) 18 | - [Performance](#performance) 19 | 20 | ### Other Contents 21 | 22 | - [License](https://github.com/zdharma-continuum/fast-syntax-highlighting/blob/master/LICENSE) 23 | - [Changelog](https://github.com/zdharma-continuum/fast-syntax-highlighting/blob/master/CHANGELOG.md) 24 | - [Theme Guide](https://github.com/zdharma-continuum/fast-syntax-highlighting/blob/master/THEME_GUIDE.md) 25 | - [Chroma Guide](https://github.com/zdharma-continuum/fast-syntax-highlighting/blob/master/CHROMA_GUIDE.adoc) 26 | 27 | # News 28 | 29 | - 15-06-2019 30 | - A new architecture for defining the highlighting for **specific commands**: it now uses **abstract definitions** 31 | instead of **top-down, regular code**. The first effect is the highlighting for the `git` command it is now 32 | **maximally faithful**, it follows the `git` command almost completely. [Screencast](https://asciinema.org/a/253411) 33 | 34 | # Installation 35 | 36 | ### Manual 37 | 38 | Clone the Repository. 39 | 40 | ```zsh 41 | git clone https://github.com/zdharma-continuum/fast-syntax-highlighting ~/path/to/fsh 42 | ``` 43 | 44 | And add the following to your `zshrc` file. 45 | 46 | ```zsh 47 | source ~/path/to/fsh/fast-syntax-highlighting.plugin.zsh 48 | ``` 49 | 50 | ### Zinit 51 | 52 | Add the following to your `zshrc` file. 53 | 54 | ```zsh 55 | zinit light zdharma-continuum/fast-syntax-highlighting 56 | ``` 57 | 58 | Here's an example of how to load the plugin together with a few other popular ones with the use of 59 | [Turbo](https://zdharma-continuum.org/zinit/wiki/INTRODUCTION/#turbo_mode_zsh_62_53), i.e.: speeding up the Zsh startup 60 | by loading the plugin right after the first prompt, in background: 61 | 62 | ```zsh 63 | zinit wait lucid for \ 64 | atinit"ZINIT[COMPINIT_OPTS]=-C; zicompinit; zicdreplay" \ 65 | zdharma-continuum/fast-syntax-highlighting \ 66 | blockf \ 67 | zsh-users/zsh-completions \ 68 | atload"!_zsh_autosuggest_start" \ 69 | zsh-users/zsh-autosuggestions 70 | ``` 71 | 72 | ### Antigen 73 | 74 | Add the following to your `zshrc` file. 75 | 76 | ```zsh 77 | antigen bundle zdharma-continuum/fast-syntax-highlighting 78 | ``` 79 | 80 | ### Fig 81 | 82 | [Fig](https://fig.io) adds apps, shortcuts, and autocomplete to your existing terminal. 83 | 84 | Install `fast-syntax-highlighting` in just one click. 85 | 86 | 87 | 88 | 89 | ### Zgen 90 | 91 | Add the following to your `.zshrc` file in the same place you're doing your other `zgen load` calls in. 92 | 93 | ```zsh 94 | zgen load zdharma-continuum/fast-syntax-highlighting 95 | ``` 96 | 97 | ### Oh-My-Zsh 98 | 99 | Clone the Repository. 100 | 101 | ```zsh 102 | git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git \ 103 | ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting 104 | ``` 105 | 106 | And add `fast-syntax-highlighting` to your plugin list. 107 | 108 | # Features 109 | 110 | ### Themes 111 | 112 | Switch themes via `fast-theme {theme-name}`. 113 | 114 |
115 | image could not be loaded 120 |
121 | 122 | Run `fast-theme -t {theme-name}` option to obtain the snippet above. 123 | 124 | Run `fast-theme -l` to list available themes. 125 | 126 | ### Variables 127 | 128 | Comparing to the project `zsh-users/zsh-syntax-highlighting` (the upper line): 129 | 130 |
131 | image could not be loaded 136 |
137 | 138 |
139 | image could not be loaded 144 |
145 | 146 | ### Brackets 147 | 148 |
149 | image could not be loaded 154 |
155 | 156 | ### Conditions 157 | 158 | Comparing to the project `zsh-users/zsh-syntax-highlighting` (the upper line): 159 | 160 |
161 | image could not be loaded 166 |
167 | 168 | ### Strings 169 | 170 | Exact highlighting that recognizes quotings. 171 | 172 |
173 | image could not be loaded 178 |
179 | 180 | ### here-strings 181 | 182 |
183 | image could not be loaded 188 |
189 | 190 | ### `exec` descriptor-variables 191 | 192 | Comparing to the project `zsh-users/zsh-syntax-highlighting` (the upper line): 193 | 194 |
195 | image could not be loaded 200 |
201 | 202 | ### for-loops and alternate syntax (brace `{`/`}` blocks) 203 | 204 |
205 | image could not be loaded 210 |
211 | 212 | ### Function definitions 213 | 214 | Comparing to the project `zsh-users/zsh-syntax-highlighting` (the upper 2 lines): 215 | 216 |
217 | image could not be loaded 222 |
223 | 224 | ### Recursive `eval` and `$( )` highlighting 225 | 226 | Comparing to the project `zsh-users/zsh-syntax-highlighting` (the upper line): 227 | 228 |
229 | image could not be loaded 234 |
235 | 236 | ### Chroma functions 237 | 238 | Highlighting that is specific for a given command. 239 | 240 |
241 | image could not be loaded 246 |
247 | 248 | The [chromas](https://github.com/zdharma-continuum/fast-syntax-highlighting/tree/master/%E2%86%92chroma) that are 249 | enabled by default can be found 250 | [here](https://github.com/zdharma-continuum/fast-syntax-highlighting/blob/master/fast-highlight#L166). 251 | 252 | ### Math-mode highlighting 253 | 254 |
255 | image could not be loaded 260 |
261 | 262 | ### Zcalc highlighting 263 | 264 |
265 | image could not be loaded 270 |
271 | 272 | # Performance 273 | 274 | Performance differences can be observed in this Asciinema recording, where a `10 kB` function is being edited. 275 | 276 |
277 | 278 | asciicast 279 | 280 |
281 | 282 | [gitter-image]: https://badges.gitter.im/zdharma-continuum/community.svg 283 | [gitter-link]: https://gitter.im/zdharma-continuum/community 284 | -------------------------------------------------------------------------------- /THEME_GUIDE.md: -------------------------------------------------------------------------------- 1 | # Theme Guide for F-Sy-H 2 | 3 | `fast-theme` tool is used to select a theme. There are 6 shipped themes, they can be listed with `fast-theme -l`. Themes 4 | are basic [INI files](https://github.com/zdharma/fast-syntax-highlighting/tree/master/themes) where each key is a 5 | *style*. Besides shipped themes, user can point this tool to any other theme, by simple `fast-theme ~/mytheme.ini`. To 6 | obtain template to work on when creating own theme, issue `fast-theme --copy-shipped-theme {theme-name}`. 7 | 8 | To alter just a few styles and not create a whole new theme, use **overlay**. What is overlay? It is in the same format 9 | as full theme, but can have only a few styles defined, and these styles will overwrite styles in main-theme. Example 10 | overlay file: 11 | 12 | ```ini 13 | ; overlay.ini 14 | [base] 15 | commandseparator = yellow,bold 16 | comment = 17 17 | 18 | [command-point] 19 | function = green 20 | command = 180 21 | ``` 22 | 23 | File name `overlay.ini` is treated specially. 24 | 25 | When specifing path, following short-hands can be used: 26 | 27 | ``` 28 | XDG: = ~/.config/fsh (respects $XDG_CONFIG_HOME env var) 29 | LOCAL: = /usr/local/share/fsh/ 30 | HOME: = ~/.fsh/ 31 | OPT: = /opt/local/share/fsh/ 32 | ``` 33 | 34 | So for example, issue `fast-theme XDG:overlay` to load `~/.config/fsh/overlay.ini` as overlay. The `.ini` extension is 35 | optional. 36 | 37 | ## Secondary Theme 38 | 39 | Each theme has key `secondary`, e.g. for theme `free`: 40 | 41 | ```ini 42 | ; free.ini 43 | [base] 44 | default = none 45 | unknown-token = red,bold 46 | ; ... 47 | ; ... 48 | ; ... 49 | secondary = zdharma 50 | ``` 51 | 52 | Secondary theme (`zdharma` in the example) will be used for highlighting of argument for `eval` and of `$( ... )` 53 | interior (i.e. of interior of command substitution). Basically, recursive highlighting uses alternate theme to make the 54 | highlighted code distinct: 55 | 56 | ![sshot](https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/master/images/cmdsubst.png) 57 | 58 | In the above screen-shot the interior of `$( ... )` uses different colors than the rest of the code. Example for `eval`: 59 | 60 | ![image](https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/master/images/eval_cmp.png) 61 | 62 | First line doesn't use recursive highlighting, highlights `eval` argument as regular string. Second line switches theme 63 | to `zdharma` and does full recursive highlighting of eval argument. 64 | 65 | ## Custom Working Directory 66 | 67 | Set `$FAST_WORK_DIR` before loading the plugin to have e.g. processed theme files (ready to load, in Zsh format, not 68 | INI) kept under specified location. This is handy if e.g. you install Fast-Syntax-Highlighting system-wide (e.g. from 69 | AUR on ArchLinux) and want to have per-user theme setup. 70 | 71 | You can use "~" in the path, e.g. `FAST_WORK_DIR=~/.fsh` and also the `XDG:`, `LOCAL:`, `OPT:`, etc. short-hands, so 72 | e.g. `FAST_WORK_DIR=XDG` or `FAST_WORK_DIR=XDG:` is allowed (in this case it will be changed to `$HOME/.config/fsh` by 73 | default by F-Sy-H loader). 74 | -------------------------------------------------------------------------------- /_fast-theme: -------------------------------------------------------------------------------- 1 | #compdef fast-theme 2 | 3 | # 4 | # Copyright (c) 2018 Sebastian Gniazdowski 5 | # 6 | # Completion for theme-switching function, fast-theme, 7 | # part of zdharma/fast-syntax-highlighting. 8 | # 9 | 10 | integer ret=1 11 | local -a arguments 12 | 13 | arguments=( 14 | {-h,--help}'[display help text]' 15 | {-l,--list}'[list available themes]' 16 | {-r,--reset}'[unset any theme (revert to default highlighting)]' 17 | {-R,--ov-reset}'[unset overlay, use styles only from main-theme (requires restart)]' 18 | {-q,--quiet}'[no default messages]' 19 | {-s,--show}'[get and display the theme currently being set]' 20 | {-v,--verbose}'[more messages during operation]' 21 | {-t,--test}'[test theme after setting it (show example code)]' 22 | {-p,--palette}'[just print all 256 colors and exit (useful when creating a theme)]' 23 | {-w,--workdir}'[cd into $FAST_WORK_DIR (if not set, then into the plugin directory)]' 24 | ) 25 | 26 | typeset -a themes 27 | themes=( "$FAST_WORK_DIR"/themes/*.ini(:t:r) ) 28 | 29 | if [[ -d ${XDG_CONFIG_HOME:-$HOME/.config}/fsh ]] { 30 | typeset -a themes2 31 | themes2=( "${XDG_CONFIG_HOME:-$HOME/.config}"/fsh/*.ini(:t:r) ) 32 | themes+=( XDG:${^themes2[@]} ) 33 | } 34 | 35 | _wanted themes expl "Themes" \ 36 | compadd "$@" -a - themes && ret=0 37 | _arguments -s $arguments && ret=0 38 | 39 | return $ret 40 | -------------------------------------------------------------------------------- /fast-string-highlight: -------------------------------------------------------------------------------- 1 | # vim:ft=zsh:sw=4:sts=4 2 | 3 | # 4 | # $1 - PREBUFFER 5 | # $2 - BUFFER 6 | # 7 | function -fast-highlight-string-process { 8 | emulate -LR zsh 9 | setopt extendedglob warncreateglobal typesetsilent 10 | 11 | local -A pos_to_level level_to_pos pair_map final_pairs 12 | local input=$1$2 _mybuf=$1$2 __style __quoting 13 | integer __idx=0 __pair_idx __level=0 __start __end 14 | local -a match mbegin mend 15 | 16 | pair_map=( "(" ")" "{" "}" "[" "]" ) 17 | 18 | while [[ $_mybuf = (#b)([^"{}()[]\\\"'"]#)((["({[]})\"'"])|[\\](*))(*) ]]; do 19 | if [[ -n ${match[4]} ]] { 20 | __idx+=${mbegin[2]} 21 | 22 | [[ $__quoting = \' ]] && _mybuf=${match[4]} || { _mybuf=${match[4]:1}; (( ++ __idx )); } 23 | } else { 24 | __idx+=${mbegin[2]} 25 | [[ -z $__quoting && -z ${_FAST_COMPLEX_BRACKETS[(r)$((__idx-${#PREBUFFER}-1))]} ]] && { 26 | if [[ ${match[2]} = ["({["] ]]; then 27 | pos_to_level[$__idx]=$(( ++__level )) 28 | level_to_pos[$__level]=$__idx 29 | elif [[ ${match[2]} = ["]})"] ]]; then 30 | if (( __level > 0 )); then 31 | __pair_idx=${level_to_pos[$__level]} 32 | pos_to_level[$__idx]=$(( __level -- )) 33 | [[ ${pair_map[${input[__pair_idx]}]} = ${input[__idx]} ]] && { 34 | final_pairs[$__idx]=$__pair_idx 35 | final_pairs[$__pair_idx]=$__idx 36 | } 37 | else 38 | pos_to_level[$__idx]=-1 39 | fi 40 | fi 41 | } 42 | 43 | if [[ ${match[2]} = \" && $__quoting != \' ]] { 44 | [[ $__quoting = '"' ]] && __quoting="" || __quoting='"'; 45 | } 46 | if [[ ${match[2]} = \' && $__quoting != \" ]] { 47 | if [[ $__quoting = ("'"|"$'") ]] { 48 | __quoting="" 49 | } else { 50 | if [[ $match[1] = *\$ ]] { 51 | __quoting="\$'"; 52 | } else { 53 | __quoting="'"; 54 | } 55 | } 56 | } 57 | _mybuf=${match[5]} 58 | } 59 | done 60 | 61 | for __idx in ${(k)pos_to_level}; do 62 | (( ${+final_pairs[$__idx]} )) && __style=${FAST_THEME_NAME}bracket-level-$(( ( (pos_to_level[$__idx]-1) % 3 ) + 1 )) || __style=${FAST_THEME_NAME}unknown-token 63 | (( __start=__idx-${#PREBUFFER}-1, __end=__idx-${#PREBUFFER}, __start >= 0 )) && \ 64 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 65 | done 66 | 67 | # If cursor is on a bracket, then highlight corresponding bracket, if any. 68 | if [[ $WIDGET != zle-line-finish ]]; then 69 | __idx=$(( CURSOR + 1 )) 70 | if (( ${+pos_to_level[$__idx]} )) && (( ${+final_pairs[$__idx]} )); then 71 | (( __start=final_pairs[$__idx]-${#PREBUFFER}-1, __end=final_pairs[$__idx]-${#PREBUFFER}, __start >= 0 )) && \ 72 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}paired-bracket]}") && \ 73 | reply+=("$CURSOR $__idx ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}paired-bracket]}") 74 | fi 75 | fi 76 | return 0 77 | } 78 | -------------------------------------------------------------------------------- /images/203654.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/203654.gif -------------------------------------------------------------------------------- /images/array-assign.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/array-assign.png -------------------------------------------------------------------------------- /images/assign.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/assign.png -------------------------------------------------------------------------------- /images/brackets.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/brackets.gif -------------------------------------------------------------------------------- /images/cmdsubst.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/cmdsubst.png -------------------------------------------------------------------------------- /images/cplx_cond.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/cplx_cond.png -------------------------------------------------------------------------------- /images/eval_cmp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/eval_cmp.png -------------------------------------------------------------------------------- /images/execfd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/execfd.png -------------------------------------------------------------------------------- /images/execfd_cmp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/execfd_cmp.png -------------------------------------------------------------------------------- /images/for-loop-cmp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/for-loop-cmp.png -------------------------------------------------------------------------------- /images/for-loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/for-loop.png -------------------------------------------------------------------------------- /images/function.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/function.png -------------------------------------------------------------------------------- /images/git_chroma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/git_chroma.png -------------------------------------------------------------------------------- /images/global-alias.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/global-alias.png -------------------------------------------------------------------------------- /images/heredoc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/heredoc.png -------------------------------------------------------------------------------- /images/herestring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/herestring.png -------------------------------------------------------------------------------- /images/highlight-less.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/highlight-less.png -------------------------------------------------------------------------------- /images/highlight-much.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/highlight-much.png -------------------------------------------------------------------------------- /images/ideal-string.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/ideal-string.png -------------------------------------------------------------------------------- /images/in_string.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/in_string.png -------------------------------------------------------------------------------- /images/math.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/math.gif -------------------------------------------------------------------------------- /images/parameter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/parameter.png -------------------------------------------------------------------------------- /images/theme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/theme.png -------------------------------------------------------------------------------- /images/typeset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/typeset.png -------------------------------------------------------------------------------- /images/zcalc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/images/zcalc.png -------------------------------------------------------------------------------- /share/free_theme.zsh: -------------------------------------------------------------------------------- 1 | : ${FAST_HIGHLIGHT_STYLES[freedefault]:=none} 2 | : ${FAST_HIGHLIGHT_STYLES[freeunknown-token]:=fg=red,bold} 3 | : ${FAST_HIGHLIGHT_STYLES[freereserved-word]:=fg=150} 4 | : ${FAST_HIGHLIGHT_STYLES[freealias]:=fg=180} 5 | : ${FAST_HIGHLIGHT_STYLES[freesuffix-alias]:=fg=180} 6 | : ${FAST_HIGHLIGHT_STYLES[freebuiltin]:=fg=180} 7 | : ${FAST_HIGHLIGHT_STYLES[freefunction]:=fg=180} 8 | : ${FAST_HIGHLIGHT_STYLES[freecommand]:=fg=180} 9 | : ${FAST_HIGHLIGHT_STYLES[freeprecommand]:=fg=180} 10 | : ${FAST_HIGHLIGHT_STYLES[freecommandseparator]:=none} 11 | : ${FAST_HIGHLIGHT_STYLES[freehashed-command]:=fg=180} 12 | : ${FAST_HIGHLIGHT_STYLES[freepath]:=fg=166} 13 | : ${FAST_HIGHLIGHT_STYLES[freepath_pathseparator]:=} 14 | : ${FAST_HIGHLIGHT_STYLES[freeglobbing]:=fg=112} 15 | : ${FAST_HIGHLIGHT_STYLES[freeglobbing-ext]:=fg=118} 16 | : ${FAST_HIGHLIGHT_STYLES[freehistory-expansion]:=fg=blue,bold} 17 | : ${FAST_HIGHLIGHT_STYLES[freesingle-hyphen-option]:=fg=110} 18 | : ${FAST_HIGHLIGHT_STYLES[freedouble-hyphen-option]:=fg=110} 19 | : ${FAST_HIGHLIGHT_STYLES[freeback-quoted-argument]:=none} 20 | : ${FAST_HIGHLIGHT_STYLES[freesingle-quoted-argument]:=fg=150} 21 | : ${FAST_HIGHLIGHT_STYLES[freedouble-quoted-argument]:=fg=150} 22 | : ${FAST_HIGHLIGHT_STYLES[freedollar-quoted-argument]:=fg=150} 23 | : ${FAST_HIGHLIGHT_STYLES[freeback-or-dollar-double-quoted-argument]:=fg=110} 24 | : ${FAST_HIGHLIGHT_STYLES[freeback-dollar-quoted-argument]:=fg=110} 25 | : ${FAST_HIGHLIGHT_STYLES[freeassign]:=none} 26 | : ${FAST_HIGHLIGHT_STYLES[freeredirection]:=none} 27 | : ${FAST_HIGHLIGHT_STYLES[freecomment]:=fg=black,bold} 28 | : ${FAST_HIGHLIGHT_STYLES[freevariable]:=none} 29 | : ${FAST_HIGHLIGHT_STYLES[freemathvar]:=fg=blue,bold} 30 | : ${FAST_HIGHLIGHT_STYLES[freemathnum]:=fg=166} 31 | : ${FAST_HIGHLIGHT_STYLES[freematherr]:=fg=red} 32 | : ${FAST_HIGHLIGHT_STYLES[freeassign-array-bracket]:=fg=180} 33 | : ${FAST_HIGHLIGHT_STYLES[freefor-loop-variable]:=none} 34 | : ${FAST_HIGHLIGHT_STYLES[freefor-loop-number]:=fg=150} 35 | : ${FAST_HIGHLIGHT_STYLES[freefor-loop-operator]:=fg=150} 36 | : ${FAST_HIGHLIGHT_STYLES[freefor-loop-separator]:=fg=109} 37 | : ${FAST_HIGHLIGHT_STYLES[freeexec-descriptor]:=fg=yellow,bold} 38 | : ${FAST_HIGHLIGHT_STYLES[freehere-string-tri]:=fg=yellow} 39 | : ${FAST_HIGHLIGHT_STYLES[freehere-string-text]:=bg=19} 40 | : ${FAST_HIGHLIGHT_STYLES[freehere-string-var]:=fg=110,bg=19} 41 | : ${FAST_HIGHLIGHT_STYLES[freesecondary]:=zdharma} 42 | : ${FAST_HIGHLIGHT_STYLES[freecase-input]:=fg=180} 43 | : ${FAST_HIGHLIGHT_STYLES[freecase-parentheses]:=fg=116} 44 | : ${FAST_HIGHLIGHT_STYLES[freecase-condition]:=bg=19} 45 | : ${FAST_HIGHLIGHT_STYLES[freecorrect-subtle]:=bg=55} 46 | : ${FAST_HIGHLIGHT_STYLES[freeincorrect-subtle]:=bg=52} 47 | : ${FAST_HIGHLIGHT_STYLES[freesubtle-separator]:=none} 48 | : ${FAST_HIGHLIGHT_STYLES[freesubtle-bg]:=bg=18} 49 | : ${FAST_HIGHLIGHT_STYLES[freepath-to-dir]:=fg=166,underline} 50 | : ${FAST_HIGHLIGHT_STYLES[freepaired-bracket]:=bg=blue} 51 | : ${FAST_HIGHLIGHT_STYLES[freebracket-level-1]:=fg=130} 52 | : ${FAST_HIGHLIGHT_STYLES[freebracket-level-2]:=fg=70} 53 | : ${FAST_HIGHLIGHT_STYLES[freebracket-level-3]:=fg=69} 54 | : ${FAST_HIGHLIGHT_STYLES[freeglobal-alias]:=bg=19} 55 | : ${FAST_HIGHLIGHT_STYLES[freesubcommand]:=fg=150} 56 | : ${FAST_HIGHLIGHT_STYLES[freesingle-sq-bracket]:=fg=180} 57 | : ${FAST_HIGHLIGHT_STYLES[freedouble-sq-bracket]:=fg=180} 58 | : ${FAST_HIGHLIGHT_STYLES[freedouble-paren]:=fg=150} 59 | : ${FAST_HIGHLIGHT_STYLES[freeoptarg-string]:=fg=150} 60 | : ${FAST_HIGHLIGHT_STYLES[freeoptarg-number]:=fg=166} 61 | : ${FAST_HIGHLIGHT_STYLES[freerecursive-base]:=fg=183} 62 | -------------------------------------------------------------------------------- /test/parse.zsh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # This file runs the highlighter on a specified file 5 | # i.e. parses the file with the highlighter. Outputs 6 | # running time (stderr) and resulting region_highlight 7 | # (file parse.out, or $2 if given). 8 | # 9 | # Can be also run in line-wise mode on own input (-o 10 | # option in $1), no region_highlight file then. 11 | # 12 | 13 | [[ -z "$ZSH_VERSION" ]] && exec /usr/bin/env /usr/local/bin/zsh-5.5.1 -f -c "source \"$0\" \"$1\" \"$2\" \"$3\"" 14 | 15 | ZERO="${(%):-%N}" 16 | 17 | if [[ -e "${ZERO}/../fast-highlight" ]]; then 18 | source "${ZERO}/../fast-highlight" 19 | source "${ZERO}/../fast-string-highlight" 20 | fpath+=( "${ZERO}/.." ) 21 | elif [[ -e "../fast-highlight" ]]; then 22 | source "../fast-highlight" 23 | source "../fast-string-highlight" 24 | fpath+=( "$PWD/.." ) 25 | elif [[ -e "${ZERO}/fast-highlight" ]]; then 26 | source "${ZERO}/fast-highlight" 27 | source "${ZERO}/fast-string-highlight" 28 | fpath+=( "${ZERO}" ) 29 | elif [[ -e "./fast-highlight" ]]; then 30 | source "./fast-highlight" 31 | source "./fast-string-highlight" 32 | fpath+=( "./" ) 33 | else 34 | print -u2 "Could not find fast-highlight, aborting" 35 | exit 1 36 | fi 37 | 38 | zmodload zsh/zprof 39 | autoload is-at-least chroma/-git.ch 40 | 41 | setopt interactive_comments extendedglob 42 | 43 | # Own input? 44 | if [[ "$1" = "-o" || "$1" = "-oo" || "$1" = "-ooo" || "$1" = "-git" || "$1" = "-hue" || "$1" = "-hol" ]]; then 45 | typeset -a input 46 | input=() 47 | if [[ "$1" = "-o" ]]; then 48 | input+=( "./parse.zsh ../fast-highlight parse2.out" ) 49 | input+=( "rm -f parse*.out" ) 50 | input+=( "./mh-parse.zsh ../fast-highlight > out" ) 51 | input+=( "if [[ -o multibyte ]]; then echo multibyte is set; fi" ) 52 | input+=( "[[ \"a\" = *[[:alpha:]_-][[:alpha:]]# ]] && echo yes" ) 53 | input+=( 'git tag -a v0.98 -m "Syntax highlighting of the history entries"' ) 54 | input+=( 'func() { echo "a" >! phist2.db; echo "b" >>! phist2.db; fc -Rap "phist2.db"; list=( ${history[@]} ); echo "${history[1]}"; }' ) 55 | (( ${+ZSH_EXECUTION_STRING} == 0 )) && { print -zr "${(F)input}"; return 0; } 56 | elif [[ "$1" = "-oo" ]]; then 57 | input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' ) 58 | input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' ) 59 | input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' ) 60 | input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' ) 61 | input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' ) 62 | input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' ) 63 | input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' ) 64 | (( ${+ZSH_EXECUTION_STRING} == 0 )) && { print -zr "${(F)input}"; return 0; } 65 | elif [[ "$1" = "-ooo" ]]; then 66 | local in=' 67 | # This is an example code that is diverse and allows to test a theme 68 | text="An example quite long string $with variable in it" 69 | local param1="text $variable" param2='"'"'other $variable'"'"' 70 | math=$(( 10 + HISTSIZ + HISTSIZE + $SAVEHIST )) size=$(( 0 )) 71 | 72 | for (( ii = 1; ii <= size; ++ ii )); do 73 | if [[ "${cmds[ii]} string" = "| string" ]] 74 | then 75 | sidx=${buffer[(in:ii:)\$\(?#[^\\\\]\)]} # find opening $( 76 | (( sidx <= len )) && { 77 | eidx=${buffer[(b:sidx:ii)[^\\\\]\)]} # find closing ) 78 | } 79 | fi 80 | done' 81 | (( ${+ZSH_EXECUTION_STRING} == 0 )) && { print -zr "$in"; return 0; } 82 | input+=( "$in" ) 83 | input+=( "$in" ) 84 | elif [[ "$1" = "-git" ]]; then 85 | local in="git lp 86 | git push origin master 87 | git commit 88 | git add safari.ini zdharma.ini 89 | git st . 90 | git diff --cached 91 | git commit --allow-empty 92 | git checkout themes/zdharma.ini 93 | git commit --amend 94 | git commit -m \"Example commit message\" 95 | git tag -a 'v1.18' -m 'Here-string is highlighted, descriptor-variables passed to exec are correctly highlighted' 96 | git tag -l -n9 97 | git checkout cb66b11 98 | " 99 | (( ${+ZSH_EXECUTION_STRING} == 0 )) && { print -zr "$in"; return 0; } 100 | input+=( "$in" ) 101 | input+=( "$in" ) 102 | elif [[ "$1" = "-hue" ]]; then 103 | local in="var=\$other; local var=\$other 104 | () { eval \"\$var\"; } 105 | case \$other in 106 | \$var) 107 | ( echo OK; ) 108 | ;; 109 | esac 110 | sudo -i -s ls -1 /var/log 111 | () { ( eval \"command ls -1\" ); } argument" 112 | 113 | (( ${+ZSH_EXECUTION_STRING} == 0 )) && { print -zr "$in"; return 0; } 114 | 115 | input+=( "$in" "$in" ) 116 | elif [[ "$1" = "-hol" ]]; then 117 | local in="var=\$( other ) 118 | local var2=\$(( other + 1 )) 119 | () { eval \"\$var\"; } 120 | sudo -i -s ls -1 >/tmp/ls-log.txt /var/log 121 | IFS=\$'\\n' print -rl -- \$(command ls -1 | tee -a /tmp/ls-1.txt) 122 | var3=\$(( HISTSIZE + 10 + \$var )) 123 | local var4=\$( other command ) 124 | touch \$(( HISTSIZE + \$SAVEHIST + 10 )) 125 | case \$other in 126 | \$var) 127 | ( echo OK; ) 128 | ;; 129 | \$var3) 130 | ( if { true } { noglob echo yes } ) 131 | esac 132 | ( builtin cd /var/log; ls -1; noglob cd \"/var/log\" 'log' ) 133 | noglob cat <<<\"\$PATH\" | tr : \"\\n\" 134 | if [[ \"\$var\" -gt 10 ]]; then 135 | (( var = HISTSIZE + \$SAVEHIST )) 136 | fi 137 | /var/log 138 | sidx=\${buffer[(in:ii:)\\\$\\(?#[^\\\\\\\\]\\)]} # find opening cmd-subst 139 | { 140 | exec {MYFD}<&0 {MYFD2}>&1 141 | ( read <&\$MYFD line; echo \$line >&\$MYFD2 && { builtin print \${match[1]}Written. } ) 142 | } always { 143 | (( MYFD > 0 )) && { print -rl -- -myfd:\$MYFD >&\$MYFD2 && print \"Sent.\" '(to filedescriptor)'; } 144 | } 145 | command sleep \"\$(( \$a + b + \${cde} + \${(s::)fgh[ijk]} + \\\$l + \\m + \\\" ))\" 146 | for (( i = 0; i <= 2; ++ i )) { print \$i; } 147 | " 148 | 149 | (( ${+ZSH_EXECUTION_STRING} == 0 )) && { print -zr "$in"; return 0; } 150 | 151 | input+=( "$in" ) 152 | fi 153 | 154 | typeset -a long_input 155 | integer i 156 | for (( i=1; i<= 50; i ++ )); do 157 | long_input+=( "${input[@]}" ) 158 | done 159 | 160 | typeset -F SECONDS 161 | SECONDS=0 162 | 163 | local right_brace_is_recognised_everywhere 164 | integer path_dirs_was_set multi_func_def ointeractive_comments 165 | -fast-highlight-fill-option-variables 166 | 167 | local BUFFER 168 | for BUFFER in "${long_input[@]}"; do 169 | reply=( ) 170 | () { 171 | -fast-highlight-init 172 | -fast-highlight-process "" "$BUFFER" "0" 173 | -fast-highlight-string-process "" "$BUFFER" 174 | } 175 | done 176 | 177 | print "Running time: $SECONDS" 178 | zprof | head 179 | # File input? 180 | elif [[ -r "$1" ]]; then 181 | # Load from given file 182 | local BUFFER="$(<$1)" 183 | 184 | typeset -F SECONDS 185 | SECONDS=0 186 | 187 | reply=( ) 188 | -fast-highlight-init 189 | 190 | local right_brace_is_recognised_everywhere 191 | integer path_dirs_was_set multi_func_def ointeractive_comments 192 | -fast-highlight-fill-option-variables 193 | 194 | () { 195 | -fast-highlight-process "" "$BUFFER" "0" 196 | -fast-highlight-string-process "" "$BUFFER" 197 | } 198 | 199 | print "Running time: $SECONDS" 200 | zprof | head 201 | 202 | # This output can be diffed to detect changes in operation 203 | if [[ -z "$2" ]]; then 204 | print -rl -- "${reply[@]}" >! out.parse 205 | else 206 | print -rl -- "${reply[@]}" >! "$2" 207 | fi 208 | else 209 | if [[ -z "$1" ]]; then 210 | print -u2 "Usage: ./parse.zsh {to-parse file} [region_highlight output file]" 211 | exit 2 212 | else 213 | print -u2 "Unreadable to-parse file \`$1', aborting" 214 | exit 3 215 | fi 216 | fi 217 | 218 | exit 0 219 | 220 | # vim:ft=zsh 221 | -------------------------------------------------------------------------------- /tests/_output/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/tests/_output/.gitkeep -------------------------------------------------------------------------------- /tests/_support/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zdharma-continuum/fast-syntax-highlighting/cf318e06a9b7c9f2219d78f41b46fa6e06011fd9/tests/_support/.gitkeep -------------------------------------------------------------------------------- /tests/_support/bootstrap: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zsh 2 | # Write your bootstrap code here 3 | -------------------------------------------------------------------------------- /tests/example.zunit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zunit 2 | @setup { 3 | load "../fast-highlight" 4 | } 5 | 6 | @test 'ls /usr/bin' { 7 | PREBUFFER="" 8 | BUFFER="ls /usr/bin" 9 | run -fast-highlight-process "$PREBUFFER" "$BUFFER" 0 \; print -rl -- \$reply 10 | 11 | assert "$lines[1]" same_as "0 2 fg=green" 12 | assert "$lines[2]" same_as "3 11 fg=magenta,underline" 13 | } 14 | 15 | # vim:ft=zsh:sw=4:sts=4:et 16 | -------------------------------------------------------------------------------- /tests/main.zunit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zunit 2 | @setup { 3 | load "../fast-highlight" 4 | setopt interactive_comments 5 | -fast-highlight-fill-option-variables 6 | } 7 | 8 | @test 'ls /usr/bin' { 9 | reply=() 10 | PREBUFFER="" 11 | BUFFER="ls /usr/bin" 12 | evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0 13 | 14 | assert "$reply[1]" same_as "0 2 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}command]}" 15 | assert "$reply[2]" same_as "3 11 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path-to-dir]}" 16 | assert "$reply[3]" same_as "" 17 | } 18 | 19 | @test 'ls /bin/df' { 20 | reply=() 21 | PREBUFFER="" 22 | BUFFER="ls /bin/df" 23 | evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0 24 | 25 | assert "$reply[1]" same_as "0 2 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}command]}" 26 | assert "$reply[2]" same_as "3 10 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]}" 27 | assert "$reply[3]" same_as "" 28 | } 29 | 30 | 31 | @test 'ls /bin/ls\\n # a comment\\nls /usr/bin' { 32 | reply=() 33 | PREBUFFER="" 34 | BUFFER=$'ls /bin/df\n # a comment\nls /usr/bin' 35 | evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0 36 | 37 | assert "$reply[1]" same_as "0 2 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}command]}" 38 | assert "$reply[2]" same_as "3 10 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]}" 39 | assert "$reply[3]" same_as "12 23 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}comment]}" 40 | assert "$reply[4]" same_as "24 26 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}command]}" 41 | assert "$reply[5]" same_as "27 35 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path-to-dir]}" 42 | assert "$reply[6]" same_as "" 43 | } 44 | 45 | 46 | @test 'exec {FD}< <( ls /bin )' { 47 | reply=() 48 | PREBUFFER="" 49 | BUFFER=$'exec {FD}< <( ls /bin )' 50 | evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0 51 | 52 | assert "$reply[1]" same_as "0 4 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}precommand]}" 53 | assert "$reply[2]" same_as "5 9 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}exec-descriptor]}" 54 | assert "$reply[3]" same_as "" 55 | } 56 | 57 | 58 | @test 'case x in x) a;; (y) ;; esac' { 59 | reply=() 60 | PREBUFFER="" 61 | BUFFER=$'case x in\nx) a;;\n(y)\n;;\nesac' 62 | evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0 63 | 64 | assert "$reply[1]" same_as "0 4 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}reserved-word]}" 65 | assert "$reply[2]" same_as "5 6 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-input]}" 66 | assert "$reply[3]" same_as "7 9 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-parentheses]}" 67 | assert "$reply[4]" same_as "10 11 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-condition]}" 68 | assert "$reply[5]" same_as "11 12 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-parentheses]}" 69 | assert "$reply[6]" same_as "13 14 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}unknown-token]}" 70 | assert "$reply[7]" same_as "17 18 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-parentheses]}" 71 | assert "$reply[8]" same_as "18 19 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-condition]}" 72 | assert "$reply[9]" same_as "19 20 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-parentheses]}" 73 | assert "$reply[10]" same_as "24 28 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}reserved-word]}" 74 | assert "$reply[11]" same_as "" 75 | } 76 | 77 | @test '-fast-highlight-process "$PREBUFFER" "$BUFFER" 0' { 78 | reply=() 79 | PREBUFFER="" 80 | BUFFER='-fast-highlight-process "$PREBUFFER" "$BUFFER" 0' 81 | evl -fast-highlight-process "\$PREBUFFER" "\$BUFFER" 0 82 | 83 | assert "$reply[1]" same_as "0 23 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}function]}" 84 | assert "$reply[2]" same_as "24 36 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}" 85 | assert "$reply[3]" same_as "25 35 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}back-or-dollar-double-quoted-argument]}" 86 | assert "$reply[4]" same_as "37 46 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}" 87 | assert "$reply[5]" same_as "38 45 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}back-or-dollar-double-quoted-argument]}" 88 | assert "$reply[6]" same_as "" 89 | } 90 | 91 | @test 'tr : \\\\n <<<$PATH' { 92 | reply=() 93 | PREBUFFER="" 94 | BUFFER='command tr : \\n << 59 -> CIELab: 241 23 | ; comment: 24 | ; #434749 -> 16 -> CIELab: 238 25 | ; keyword: 26 | ; #b77c4b -> 137 -> CIELab: 173 27 | ; number, string: 28 | ; #5794a2 -> 67 -> CIELab: 66 29 | ; title, section, name, selector-id: 30 | ; #778ce0 -> 104 -> CIELab: 104 31 | ; attribute, variable, type: 32 | ; #d55383 -> 168 -> CIELab: 168 33 | ; symbol, link: 34 | ; #e66493 -> 168 -> CIELab: 168 35 | ; builtin, deletion: 36 | ; #bd5ac0 -> 133 -> CIELab: 170 37 | ; formula-bg: 38 | ; #363a3b -> 16 -> CIELab: 237 39 | ; 40 | ; Token.Literal: "#dc5be0" -> CIELab: 170 (Orchid; naive: 170) 41 | ; Token.Operator: "#677dcf" -> CIELab: 68 (SteelBlue3; naive: 68) 42 | ; 43 | 44 | [base] 45 | default = none 46 | unknown-token = 196 47 | secondary = sv-orple 48 | recursive-base = 183 49 | 50 | [background] 51 | correct-subtle = bg:18 52 | incorrect-subtle = bg:238 53 | subtle-bg = bg:17 54 | global-alias = bg:20 55 | 56 | ;; 57 | ;; COLOR-GROUPS 58 | ;; 59 | 60 | [gray] 61 | comment = 243 62 | 63 | 64 | 65 | [pastel] 66 | here-string-tri = 217 67 | 68 | 69 | 70 | [no-color] 71 | assign = none 72 | back-quoted-argument = none 73 | redirection = none 74 | variable = none 75 | 76 | 77 | 78 | 79 | [magenta-3] 80 | dollar-quoted-argument = 173 81 | double-quoted-argument = 173 82 | history-expansion = 173 83 | globbing-ext = 173 84 | precommand = 173 85 | 86 | [light-salmon-3] 87 | builtin = 137 88 | subcommand = 137 89 | single-quoted-argument = 137 90 | 91 | [steel-blue-3] 92 | command = 68 93 | double-sq-bracket = 68 94 | double-paren = 68 95 | single-sq-bracket = 68 96 | 97 | [steel-blue] 98 | reserved-word = 67 99 | 100 | 101 | 102 | [medium-purple] 103 | ; backslash in $'...' 104 | back-dollar-quoted-argument = 104 105 | commandseparator = 104 106 | single-hyphen-option = 104 107 | 108 | [dark-khaki] 109 | double-hyphen-option = 143 110 | 111 | 112 | 113 | [hot-pink-3] 114 | alias = 168 115 | exec-descriptor = 168 116 | function = 168 117 | hashed-command = 168 118 | here-string-var = 168 119 | suffix-alias = 168 120 | 121 | [pale-green-3] 122 | assign-array-bracket = 114 123 | ; variable $... or backslash in "..." (i.e. variable in string) 124 | back-or-dollar-double-quoted-argument = 114 125 | globbing = 114 126 | here-string-text = 114 127 | 128 | 129 | 130 | [orchid] 131 | path = 170 132 | path-to-dir = 170,underline 133 | pathseparator = 134 | 135 | 136 | 137 | ;; 138 | ;; FUNCTIONALITY-GROUPS 139 | ;; 140 | 141 | [brackets] 142 | paired-bracket = black,bg:216 143 | bracket-level-1 = 117 144 | bracket-level-2 = 217 145 | bracket-level-3 = 220 146 | 147 | [math] 148 | mathvar = 68 149 | mathnum = 173 150 | matherr = 124 151 | 152 | [for-loop] 153 | forvar = 68 154 | fornum = 173 155 | ; operator 156 | foroper = 133 157 | ; separator 158 | forsep = 104 159 | 160 | [case] 161 | case-input = 168 162 | case-parentheses = 217 163 | case-condition = bg:25 164 | -------------------------------------------------------------------------------- /themes/safari.ini: -------------------------------------------------------------------------------- 1 | ; Light theme with colors of a Sahara oasis 2 | 3 | [base] 4 | default = none 5 | unknown-token = red,bold 6 | commandseparator = none 7 | redirection = none 8 | here-string-tri = yellow 9 | here-string-text = bg:19 10 | here-string-var = 153,bg:19 11 | exec-descriptor = yellow,bold 12 | comment = black,bold 13 | correct-subtle = bg:55 14 | incorrect-subtle = bg:52 15 | subtle-bg = bg:18 16 | secondary = zdharma 17 | recursive-base = 183 18 | 19 | [command-point] 20 | reserved-word = 150 21 | subcommand = 150 22 | alias = 185 23 | suffix-alias = 185 24 | global-alias = bg:19 25 | builtin = 185 26 | function = 185 27 | command = 185 28 | precommand = 185 29 | hashed-command = 185 30 | single-sq-bracket = 185 31 | double-sq-bracket = 185 32 | double-paren = 150 33 | 34 | [paths] 35 | path = 187 36 | pathseparator = 37 | path-to-dir = 187,underline 38 | globbing = 180 39 | globbing-ext = 184 40 | 41 | [brackets] 42 | paired-bracket = bg:blue 43 | bracket-level-1 = 178 44 | bracket-level-2 = 148 45 | bracket-level-3 = 141 46 | 47 | [arguments] 48 | single-hyphen-option = 152 49 | double-hyphen-option = 152 50 | back-quoted-argument = none 51 | single-quoted-argument = 151 52 | double-quoted-argument = 151 53 | dollar-quoted-argument = 151 54 | 55 | [in-string] 56 | ; backslash in $'...' 57 | back-dollar-quoted-argument = 153 58 | ; backslash or $... in "..." (i.e. variable inside a string) 59 | back-or-dollar-double-quoted-argument = 153 60 | 61 | [other] 62 | variable = none 63 | assign = none 64 | assign-array-bracket = 185 65 | history-expansion = blue,bold 66 | 67 | [math] 68 | mathvar = blue,bold 69 | mathnum = 187 70 | matherr = red 71 | 72 | [for-loop] 73 | forvar = none 74 | fornum = 187 75 | ; operator 76 | foroper = 151 77 | ; separator 78 | forsep = 109 79 | 80 | [case] 81 | case-input = 185 82 | case-parentheses = 116 83 | case-condition = bg:19 84 | -------------------------------------------------------------------------------- /themes/spa.ini: -------------------------------------------------------------------------------- 1 | ; 144, 187, 110, 203 2 | [base] 3 | default = none 4 | unknown-token = 196 5 | commandseparator = 150 6 | redirection = none 7 | here-string-tri = yellow 8 | here-string-text = bg:19 9 | here-string-var = 186,bg:19 10 | exec-descriptor = yellow,bold 11 | comment = black,bold 12 | correct-subtle = bg:55 13 | incorrect-subtle = bg:52 14 | subtle-bg = bg:17 15 | secondary = zdharma 16 | recursive-base = 183 17 | 18 | [command-point] 19 | reserved-word = 144 20 | subcommand = 144 21 | alias = 187 22 | suffix-alias = 187 23 | global-alias = bg:19 24 | builtin = 150 25 | function = 187 26 | command = 187 27 | precommand = 187 28 | hashed-command = 187 29 | single-sq-bracket = 150 30 | double-sq-bracket = 150 31 | double-paren = 144 32 | 33 | [paths] 34 | path = 110 35 | pathseparator = 36 | path-to-dir = 110,underline 37 | globbing = 220 38 | globbing-ext = 225 39 | 40 | [brackets] 41 | paired-bracket = bg:blue 42 | bracket-level-1 = 115 43 | bracket-level-2 = 177 44 | bracket-level-3 = 220 45 | 46 | [arguments] 47 | single-hyphen-option = 185 48 | double-hyphen-option = 185 49 | back-quoted-argument = none 50 | single-quoted-argument = 110 51 | double-quoted-argument = 110 52 | dollar-quoted-argument = 110 53 | 54 | [in-string] 55 | ; backslash in $'...' 56 | back-dollar-quoted-argument = 186 57 | ; backslash or $... in "..." (i.e. variable in string) 58 | back-or-dollar-double-quoted-argument = 186 59 | 60 | [other] 61 | variable = none 62 | assign = none 63 | assign-array-bracket = 187 64 | history-expansion = blue,bold 65 | 66 | [math] 67 | mathvar = 150 68 | mathnum = 110 69 | matherr = 196 70 | 71 | [for-loop] 72 | forvar = 71 73 | fornum = 110 74 | ; operator 75 | foroper = 203 76 | ; separator 77 | forsep = 147 78 | 79 | [case] 80 | case-input = 187 81 | case-parentheses = 116 82 | case-condition = bg:19 83 | -------------------------------------------------------------------------------- /themes/sv-orple.ini: -------------------------------------------------------------------------------- 1 | ; https://www.syntaxenvy.com/0073437 2 | ; 3 | ; comment: 4 | ; #363355 -> 61 5 | ; keyword: 6 | ; #dda69f -> 181 (138) 7 | ; number, string: 8 | ; #ca887e -> 174 (173) 9 | ; title, section, name, selector-id: 10 | ; #b3afd9 -> 146 (146) 11 | ; attribute, variable, type: 12 | ; #be85c0 -> 139 (140) 13 | ; symbol, link: 14 | ; #d6a2d8 -> 182 (182) 15 | ; builtin, deletion: 16 | ; #969c77 -> 108 (108) 17 | ; formula-bg: 18 | ; #211f37 -> 16 (17) 19 | 20 | [base] 21 | default = none 22 | unknown-token = 124 23 | commandseparator = 146 24 | redirection = none 25 | here-string-tri = 138 26 | here-string-text = bg:25 27 | here-string-var = 140,bg:25 28 | exec-descriptor = 140 29 | comment = 61 30 | correct-subtle = bg:55 31 | incorrect-subtle = bg:52 32 | subtle-bg = bg:17 33 | secondary = clean 34 | recursive-base = 186 35 | 36 | [command-point] 37 | reserved-word = 138 38 | subcommand = 182 39 | alias = 140 40 | suffix-alias = 140 41 | global-alias = bg:17 42 | builtin = 173 43 | function = 140 44 | command = 108 45 | precommand = 138 46 | hashed-command = 140 47 | single-sq-bracket = 173 48 | double-sq-bracket = 173 49 | double-paren = 138 50 | 51 | [paths] 52 | path = 182 53 | pathseparator = 54 | path-to-dir = 182,underline 55 | globbing = 138 56 | globbing-ext = 141 57 | 58 | [brackets] 59 | paired-bracket = bg:blue 60 | bracket-level-1 = 173 61 | bracket-level-2 = 177 62 | bracket-level-3 = 220 63 | 64 | [arguments] 65 | single-hyphen-option = 140 66 | double-hyphen-option = 140 67 | back-quoted-argument = none 68 | single-quoted-argument = 173 69 | double-quoted-argument = 173 70 | dollar-quoted-argument = 173 71 | 72 | [in-string] 73 | ; backslash in $'...' 74 | back-dollar-quoted-argument = 146 75 | ; backslash or $... in "..." (i.e. variable in string) 76 | back-or-dollar-double-quoted-argument = 140 77 | 78 | [other] 79 | variable = none 80 | assign = none 81 | assign-array-bracket = 182 82 | history-expansion = blue,bold 83 | 84 | [math] 85 | mathvar = 140 86 | mathnum = 173 87 | matherr = 124 88 | 89 | [for-loop] 90 | forvar = 140 91 | fornum = 173 92 | ; operator 93 | foroper = 147 94 | ; separator 95 | forsep = 182 96 | 97 | [case] 98 | case-input = 140 99 | case-parentheses = 17 100 | case-condition = bg:25 101 | -------------------------------------------------------------------------------- /themes/sv-plant.ini: -------------------------------------------------------------------------------- 1 | ; https://www.syntaxenvy.com/0854668 2 | ; 3 | ; comment: 4 | ; #5b4e3f -> 58 5 | ; keyword: 6 | ; #a1f2b2 -> 157 7 | ; number, string: 8 | ; #91cf9e -> 115 (114) 9 | ; title, section, name, selector-id: 10 | ; #dadff0 -> 189 11 | ; attribute, variable, type: 12 | ; #debb91 -> 180 13 | ; symbol, link: 14 | ; #f1dcc6 -> 224 15 | ; builtin, deletion: 16 | ; #95cbc1 -> 115 17 | ; formula: 18 | ; #3f352a -> 16 19 | 20 | [base] 21 | default = none 22 | unknown-token = 124 23 | commandseparator = 189 24 | redirection = none 25 | here-string-tri = 157 26 | here-string-text = bg:25 27 | here-string-var = 180,bg:25 28 | exec-descriptor = 180 29 | comment = 58 30 | correct-subtle = bg:55 31 | incorrect-subtle = bg:52 32 | subtle-bg = bg:17 33 | secondary = zdharma 34 | recursive-base = 183 35 | 36 | [command-point] 37 | reserved-word = 157 38 | subcommand = 224 39 | alias = 180 40 | suffix-alias = 180 41 | global-alias = bg:58 42 | builtin = 115 43 | function = 180 44 | command = 180 45 | precommand = 157 46 | hashed-command = 180 47 | single-sq-bracket = 115 48 | double-sq-bracket = 115 49 | double-paren = 157 50 | 51 | [paths] 52 | path = 224 53 | pathseparator = 54 | path-to-dir = 224,underline 55 | globbing = 157 56 | globbing-ext = 159 57 | 58 | [brackets] 59 | paired-bracket = bg:blue 60 | bracket-level-1 = 115 61 | bracket-level-2 = 177 62 | bracket-level-3 = 220 63 | 64 | [arguments] 65 | single-hyphen-option = 180 66 | double-hyphen-option = 180 67 | back-quoted-argument = none 68 | single-quoted-argument = 114 69 | double-quoted-argument = 114 70 | dollar-quoted-argument = 114 71 | 72 | [in-string] 73 | ; backslash in $'...' 74 | back-dollar-quoted-argument = 189 75 | ; backslash or $... in "..." (i.e. variable in string) 76 | back-or-dollar-double-quoted-argument = 180 77 | 78 | [other] 79 | variable = none 80 | assign = none 81 | assign-array-bracket = 224 82 | history-expansion = blue,bold 83 | 84 | [math] 85 | mathvar = 180 86 | mathnum = 114 87 | matherr = 124 88 | 89 | [for-loop] 90 | forvar = 180 91 | fornum = 114 92 | ; operator 93 | foroper = 147 94 | ; separator 95 | forsep = 224 96 | 97 | [case] 98 | case-input = 180 99 | case-parentheses = 58 100 | case-condition = bg:25 101 | -------------------------------------------------------------------------------- /themes/zdharma.ini: -------------------------------------------------------------------------------- 1 | [base] 2 | default = none 3 | unknown-token = red,bold 4 | commandseparator = none 5 | redirection = none 6 | here-string-tri = 141 7 | here-string-text = bg:19 8 | here-string-var = 177,bg:19 9 | exec-descriptor = yellow,bold 10 | comment = black,bold 11 | correct-subtle = bg:55 12 | incorrect-subtle = bg:52 13 | subtle-bg = bg:17 14 | secondary = safari 15 | recursive-base = 186 16 | 17 | [command-point] 18 | reserved-word = 146 19 | reserved-word = 146 20 | alias = 63 21 | suffix-alias = 63 22 | global-alias = bg:19 23 | builtin = 63 24 | function = 63 25 | command = 63 26 | precommand = 63 27 | hashed-command = 63 28 | single-sq-bracket = 63 29 | double-sq-bracket = 63 30 | double-paren = 146 31 | 32 | [paths] 33 | path = 154 34 | pathseparator = 35 | path-to-dir = 154,underline 36 | globbing = 114 37 | globbing-ext = 153 38 | 39 | [brackets] 40 | paired-bracket = bg:blue 41 | bracket-level-1 = 117 42 | bracket-level-2 = 141 43 | bracket-level-3 = 90 44 | 45 | [arguments] 46 | single-hyphen-option = 177 47 | double-hyphen-option = 177 48 | back-quoted-argument = none 49 | single-quoted-argument = 146 50 | double-quoted-argument = 146 51 | dollar-quoted-argument = 146 52 | 53 | [in-string] 54 | ; backslash in $'...' 55 | back-dollar-quoted-argument = 177 56 | ; backslash or $... in "..." 57 | back-or-dollar-double-quoted-argument = 177 58 | 59 | [other] 60 | variable = none 61 | assign = none 62 | assign-array-bracket = 63 63 | history-expansion = blue,bold 64 | 65 | [math] 66 | mathvar = blue,bold 67 | mathnum = 154 68 | matherr = red 69 | 70 | [for-loop] 71 | forvar = none 72 | fornum = 154 73 | ; operator 74 | foroper = 146 75 | ; separator 76 | forsep = 109 77 | 78 | [case] 79 | case-input = 63 80 | case-parentheses = 141 81 | case-condition = bg:19 82 | -------------------------------------------------------------------------------- /→chroma/-alias.ch: -------------------------------------------------------------------------------- 1 | # vim:ft=zsh:et:sw=4 2 | (( next_word = 2 | 8192 )) 3 | [[ "$__arg_type" = 3 ]] && return 2 4 | 5 | local __first_call="$1" __wrd="${2%%=*}" __start_pos="$3" __end_pos="$4" 6 | 7 | if (( __first_call )) || [[ "$2" = -* ]]; then 8 | return 1 9 | else 10 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 11 | return 1 12 | elif (( $+aliases[(e)$__wrd] )) || (( ${+galiases[(e)$__wrd]} )); then 13 | (( __start=__start_pos-${#PREBUFFER}, __end=__start_pos+${#__wrd}-${#PREBUFFER}, __start >= 0 )) \ 14 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") 15 | elif (( $+functions[(e)$__wrd] )) || (( $+builtins[(e)$__wrd] )) || (( $+commands[(e)$__wrd] )) || (( $reswords[(Ie)$__wrd] )); then 16 | (( __start=__start_pos-${#PREBUFFER}, __end=__start_pos+${#__wrd}-${#PREBUFFER}, __start >= 0 )) \ 17 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") 18 | else 19 | return 1 20 | fi 21 | if [[ "$__wrd" != "$2" ]]; then 22 | return 1 23 | fi 24 | fi 25 | 26 | (( this_word = next_word )) 27 | _start_pos=$_end_pos 28 | 29 | return 0 30 | -------------------------------------------------------------------------------- /→chroma/-autoload.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # Tracks autoload command - highlights function names if they exist somewhere 5 | # in $fpath. Also warns that the autoloaded function is already defined. 6 | # 7 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 8 | # 9 | # $2 - the current token, also accessible by $__arg from the above scope - 10 | # basically a private copy of $__arg; the token can be eg.: "grep" 11 | # 12 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 13 | # command line buffer, used to add region_highlight entry (see man), 14 | # because Zsh colorizes by *ranges* in command line buffer 15 | # 16 | # $4 - a private copy of $_end_pos from the above scope 17 | # 18 | 19 | (( next_word = 2 | 8192 )) 20 | 21 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 22 | local __style __chars 23 | integer __idx1 __idx2 24 | local -a __results __deserialized __noshsplit 25 | 26 | # First call, i.e. command starts, i.e. "grep" token etc. 27 | (( __first_call )) && { 28 | FAST_HIGHLIGHT[chroma-autoload-counter]=0 29 | FAST_HIGHLIGHT[chroma-autoload-counter-all]=1 30 | FAST_HIGHLIGHT[chroma-autoload-message]="" 31 | #FAST_HIGHLIGHT[chroma-autoload-message-shown]="" 32 | [[ -z ${FAST_HIGHLIGHT[chroma-autoload-message-shown-at]} ]] && FAST_HIGHLIGHT[chroma-autoload-message-shown-at]=0 33 | FAST_HIGHLIGHT[chroma-autoload-elements]="" 34 | __style=${FAST_THEME_NAME}command 35 | 36 | } || { 37 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 38 | return 1 39 | fi 40 | (( FAST_HIGHLIGHT[chroma-autoload-counter-all] += 1, __idx2 = FAST_HIGHLIGHT[chroma-autoload-counter-all] )) 41 | 42 | # Following call, i.e. not the first one. 43 | 44 | # Check if chroma should end – test if token is of type 45 | # "starts new command", if so pass-through – chroma ends 46 | [[ "$__arg_type" = 3 ]] && return 2 47 | 48 | if [[ "$__wrd" = [-+]* ]]; then 49 | # Detected option, add style for it. 50 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 51 | __style=${FAST_THEME_NAME}single-hyphen-option 52 | else 53 | # Count non-option tokens. 54 | (( FAST_HIGHLIGHT[chroma-autoload-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-autoload-counter] )) 55 | 56 | if [[ $__wrd != (\$|\"\$)* && $__wrd != (/|\"/|\'/)* && $__wrd != \`* ]]; then 57 | __results=( ${^fpath}/$__wrd(N) ) 58 | __deserialized=( "${(Q@)${(z@)FAST_HIGHLIGHT[chroma-fpath_peq-elements]}}" ) 59 | __results+=( ${^__deserialized}/$__wrd(N) ) 60 | [[ "${#__results}" -gt 0 ]] && { 61 | __style=${FAST_THEME_NAME}correct-subtle 62 | __deserialized=( "${(Q@)${(z@)FAST_HIGHLIGHT[chroma-autoload-elements]}}" ) 63 | [[ -z "${__deserialized[1]}" && ${#__deserialized} -eq 1 ]] && __deserialized=() 64 | # Cannot use ${abc:+"$abc"} trick with ${~...}, so handle most 65 | # cases of the possible shwordsplit through an additional array 66 | __noshsplit=( ${~__wrd} ) 67 | __deserialized+=( "${(j: :)__noshsplit}" ) 68 | FAST_HIGHLIGHT[chroma-autoload-elements]="${(j: :)${(q@)__deserialized}}" 69 | # Make the function defined for big-loop's *main-type mechanism 70 | __fast_highlight_main__command_type_cache[${(j: :)__noshsplit}]="function" 71 | } || __style=${FAST_THEME_NAME}incorrect-subtle 72 | fi 73 | 74 | if (( ${+functions[${(Q)__wrd}]} )); then 75 | FAST_HIGHLIGHT[chroma-autoload-message]+="Warning: Function ${(Q)__wrd} already defined (e.g. loaded)"$'\n' 76 | fi 77 | fi 78 | 79 | # Display only when processing last autoload argument 80 | if (( ${#${(z)BUFFER}} == FAST_HIGHLIGHT[chroma-autoload-counter-all] )); then 81 | # Display only if already shown message differs or when it timeouts 82 | if [[ ${FAST_HIGHLIGHT[chroma-autoload-message]} != ${FAST_HIGHLIGHT[chroma-autoload-message-shown]} || 83 | $(( EPOCHSECONDS - FAST_HIGHLIGHT[chroma-autoload-message-shown-at] )) -gt 7 84 | ]]; then 85 | FAST_HIGHLIGHT[chroma-autoload-message-shown]=${FAST_HIGHLIGHT[chroma-autoload-message]} 86 | FAST_HIGHLIGHT[chroma-autoload-message-shown-at]=$EPOCHSECONDS 87 | zle -M "${FAST_HIGHLIGHT[chroma-autoload-message]}" 88 | fi 89 | fi 90 | } 91 | 92 | # Add region_highlight entry (via `reply' array). 93 | # 94 | # This is a common place of adding such entry, but any above code 95 | # can do it itself and skip setting __style to disable this code. 96 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 97 | 98 | # We aren't passing-through (no return 1 occured), do obligatory things ourselves. 99 | (( this_word = next_word )) 100 | _start_pos=$_end_pos 101 | 102 | return 0 103 | 104 | # vim:ft=zsh:et:sw=4 105 | -------------------------------------------------------------------------------- /→chroma/-autorandr.ch: -------------------------------------------------------------------------------- 1 | # vim:ft=zsh:et:sw=4 2 | (( next_word = 2 | 8192 )) 3 | [[ "$__arg_type" = 3 ]] && return 2 4 | 5 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 6 | 7 | if (( __first_call )) || [[ "$__wrd" = -* ]]; then 8 | return 1 9 | else 10 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 11 | return 1 12 | fi 13 | if [[ -d "${XDG_CONFIG_HOME:-$HOME/.config}/autorandr/$__wrd" ]] then 14 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 15 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") 16 | fi 17 | fi 18 | 19 | (( this_word = next_word )) 20 | _start_pos=$_end_pos 21 | 22 | return 0 23 | -------------------------------------------------------------------------------- /→chroma/-awk.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 5 | # 6 | # $2 - the current token, also accessible by $__arg from the above scope - 7 | # basically a private copy of $__arg; the token can be eg.: "grep" 8 | # 9 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 10 | # command line buffer, used to add region_highlight entry (see man), 11 | # because Zsh colorizes by *ranges* in command line buffer 12 | # 13 | # $4 - a private copy of $_end_pos from the above scope 14 | # 15 | 16 | (( next_word = 2 | 8192 )) 17 | 18 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 19 | local __style __chars __val __style2 20 | integer __idx1 __idx2 21 | 22 | # First call, i.e. command starts, i.e. "grep" token etc. 23 | (( __first_call )) && { 24 | FAST_HIGHLIGHT[chroma-awk-counter]=0 25 | FAST_HIGHLIGHT[chroma-awk-f-seen]=0 26 | return 1 27 | } || { 28 | # Following call, i.e. not the first one. 29 | 30 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 31 | return 1 32 | fi 33 | 34 | # Check if chroma should end – test if token is of type 35 | # "starts new command", if so pass-through – chroma ends 36 | [[ "$__arg_type" = 3 ]] && return 2 37 | 38 | if [[ "$__wrd" = -* ]]; then 39 | # Detected option, add style for it. 40 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 41 | __style=${FAST_THEME_NAME}single-hyphen-option 42 | [[ "$__wrd" = "-f" ]] && FAST_HIGHLIGHT[chroma-awk-f-seen]=1 43 | else 44 | # Count non-option tokens. 45 | (( FAST_HIGHLIGHT[chroma-awk-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-awk-counter] )) 46 | 47 | # First non-option token is the pattern (regex), we will 48 | # highlight it. 49 | if (( FAST_HIGHLIGHT[chroma-awk-counter] == 1 && FAST_HIGHLIGHT[chroma-awk-f-seen] == 0 )); then 50 | if print -r -- "${(Q)__wrd}" | gawk --source 'BEGIN { exit } END { exit 0 }' -f - >/dev/null 2>&1; then 51 | __style2="${FAST_THEME_NAME}subtle-bg" 52 | else 53 | __style2="${FAST_THEME_NAME}incorrect-subtle" 54 | fi 55 | 56 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \ 57 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style2]}") 58 | 59 | # Highlight keywords 60 | FSH_LIST=() 61 | : "${__wrd//(#m)(BEGIN|END|FIELDWIDTHS|RS|ARGC|ARGV|ENVIRON|NF|NR|IGNORECASE|FILENAME|if|then|else|while|toupper|tolower|function|print|sub)/$(( fsh_sy_h_append($MBEGIN, $MEND) ))}"; 62 | for __val in "${FSH_LIST[@]}" ; do 63 | [[ ${__wrd[${__val%%;;*}]} = [a-zA-Z0-9_] || ${__wrd[${__val##*;;}+1]} = [a-zA-Z0-9_] ]] && continue 64 | __idx1=$(( __start_pos + ${__val%%;;*} )) 65 | __idx2=__idx1+${__val##*;;}-${__val%%;;*}+1 66 | (( __start=__idx1-${#PREBUFFER}, __end=__idx2-${#PREBUFFER}-1, __start >= 0 )) && \ 67 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}reserved-word]},${FAST_HIGHLIGHT_STYLES[$__style2]}") 68 | done 69 | 70 | # Highlight regex characters 71 | __chars="*+\\)(\{\}[]^" 72 | __idx1=__start_pos 73 | __idx2=__start_pos 74 | while [[ "$__wrd" = (#b)[^$__chars]#([\\][\\])#((+|\*|\[|\]|\)|\(|\^|\}|\{)|[\\](+|\*|\[|\]|\)|\(|\^|\{|\}))(*) ]]; do 75 | if [[ -n "${match[3]}" ]]; then 76 | __idx1+=${mbegin[3]}-1 77 | __idx2=__idx1+${mend[3]}-${mbegin[3]}+1 78 | (( __start=__idx1-${#PREBUFFER}, __end=__idx2-${#PREBUFFER}, __start >= 0 )) && \ 79 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}mathnum]},${FAST_HIGHLIGHT_STYLES[$__style2]}") 80 | __idx1=__idx2 81 | else 82 | __idx1+=${mbegin[5]}-1 83 | fi 84 | __wrd="${match[5]}" 85 | done 86 | elif (( FAST_HIGHLIGHT[chroma-awk-counter] >= 2 || FAST_HIGHLIGHT[chroma-awk-f-seen] == 1 )); then 87 | FAST_HIGHLIGHT[chroma-awk-f-seen]=0 88 | # Handle paths, etc. normally - just pass-through to the big 89 | # highlighter (the main FSH highlighter, used before chromas). 90 | return 1 91 | fi 92 | fi 93 | } 94 | 95 | # Add region_highlight entry (via `reply' array). 96 | # 97 | # This is a common place of adding such entry, but any above 98 | # code can do it itself (and it does) and skip setting __style 99 | # to disable this code. 100 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 101 | 102 | # We aren't passing-through (no return 1 occured), do obligatory things ourselves. 103 | (( this_word = next_word )) 104 | _start_pos=$_end_pos 105 | 106 | return 0 107 | 108 | # vim:ft=zsh:et:sw=4 109 | -------------------------------------------------------------------------------- /→chroma/-docker.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # Chroma function for command `docker'. It verifies command line, by denoting 5 | # wrong and good arguments by color. Currently implemented: verification of 6 | # image IDs passed to: docker image rm . 7 | # 8 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 9 | # $2 - the current token, also accessible by $__arg from the above scope - 10 | # basically a private copy of $__arg 11 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 12 | # command line buffer, used to add region_highlight entry (see man), 13 | # because Zsh colorizes by *ranges* in command line buffer 14 | # $4 - a private copy of $_end_pos from the above scope 15 | # 16 | 17 | (( next_word = 2 | 8192 )) 18 | 19 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 20 | local __style 21 | integer __idx1 __idx2 22 | local -a __lines_list 23 | 24 | (( __first_call )) && { 25 | # Called for the first time - new command 26 | # FAST_HIGHLIGHT is used because it survives between calls, and 27 | # allows to use a single global hash only, instead of multiple 28 | # global variables 29 | FAST_HIGHLIGHT[chroma-docker-counter]=0 30 | FAST_HIGHLIGHT[chroma-docker-got-subcommand]=0 31 | FAST_HIGHLIGHT[chroma-docker-subcommand]="" 32 | FAST_HIGHLIGHT[chrome-docker-got-msg1]=0 33 | return 1 34 | } || { 35 | # Following call, i.e. not the first one 36 | 37 | # Check if chroma should end – test if token is of type 38 | # "starts new command", if so pass-through – chroma ends 39 | [[ "$__arg_type" = 3 ]] && return 2 40 | 41 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 42 | return 1 43 | fi 44 | 45 | if [[ "$__wrd" = -* && ${FAST_HIGHLIGHT[chroma-docker-got-subcommand]} -eq 0 ]]; then 46 | __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option} 47 | else 48 | if (( FAST_HIGHLIGHT[chroma-docker-got-subcommand] == 0 )); then 49 | FAST_HIGHLIGHT[chroma-docker-got-subcommand]=1 50 | FAST_HIGHLIGHT[chroma-docker-subcommand]="$__wrd" 51 | __style=${FAST_THEME_NAME}subcommand 52 | (( FAST_HIGHLIGHT[chroma-docker-counter] += 1 )) 53 | else 54 | __wrd="${__wrd//\`/x}" 55 | __arg="${__arg//\`/x}" 56 | __wrd="${(Q)__wrd}" 57 | if [[ "${FAST_HIGHLIGHT[chroma-docker-subcommand]}" = "image" ]]; then 58 | [[ "$__wrd" != -* ]] && { 59 | (( FAST_HIGHLIGHT[chroma-docker-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-docker-counter] )) 60 | 61 | if (( __idx1 == 2 )); then 62 | __style=${FAST_THEME_NAME}subcommand 63 | elif (( __idx1 == 3 )); then 64 | .fast-run-command "docker images -q" chroma-docker-list "" 65 | [[ -n "${__lines_list[(r)$__wrd]}" ]] && { 66 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \ 67 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") 68 | } || { 69 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \ 70 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") 71 | } 72 | fi 73 | } || __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option} 74 | else 75 | return 1 76 | fi 77 | fi 78 | fi 79 | } 80 | 81 | # Add region_highlight entry (via `reply' array) 82 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 83 | 84 | # We aren't passing-through, do obligatory things ourselves 85 | (( this_word = next_word )) 86 | _start_pos=$_end_pos 87 | 88 | return 0 89 | 90 | # vim:ft=zsh:et:sw=4 91 | -------------------------------------------------------------------------------- /→chroma/-example.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # Example chroma function. It colorizes first two arguments as `builtin' style, 5 | # third and following arguments as `globbing' style. First two arguments may 6 | # be "strings", they will be passed through to normal higlighter (by returning 1). 7 | # 8 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 9 | # 10 | # $2 - the current token, also accessible by $__arg from the above scope - 11 | # basically a private copy of $__arg; the token can be eg.: "grep" 12 | # 13 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 14 | # command line buffer, used to add region_highlight entry (see man), 15 | # because Zsh colorizes by *ranges* in command line buffer 16 | # 17 | # $4 - a private copy of $_end_pos from the above scope 18 | # 19 | # 20 | # Overall functioning is: when command "example" is occured, this function 21 | # is called with $1 == 1, it ("example") is the first token ($2), then for any 22 | # following token, this function is called with $1 == 0, until end of command 23 | # is occured (i.e. till enter is pressed or ";" is put into source, or the 24 | # command line simply ends). 25 | # 26 | # Other tips are: 27 | # - $CURSOR holds cursor position 28 | # - $BUFFER holds whole command line buffer 29 | # - $LBUFFER holds command line buffer that is left from the cursor, i.e. it's a 30 | # BUFFER substring 1 .. $CURSOR 31 | # - $RBUFFER is the same as LBUFFER but holds part of BUFFER right to the cursor 32 | # 33 | # The function receives $BUFFER but via sequence of tokens, which are shell words, 34 | # e.g. "a b c" is a shell word, while a b c are 3 shell words. 35 | # 36 | # FAST_HIGHLIGHT is a friendly hash array which allows to store strings without 37 | # creating global parameters (variables). If you need hash, just use it first 38 | # declaring, under some distinct name like: typeset -gA CHROMA_EXPLE_DICT. 39 | # Remember to reset the hash and others at __first_call == 1, so that you have 40 | # a fresh state for new command. 41 | 42 | # Keep chroma-takever state meaning: until ;, handle highlighting via chroma. 43 | # So the below 8192 assignment takes care that next token will be routed to chroma. 44 | (( next_word = 2 | 8192 )) 45 | 46 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 47 | local __style 48 | integer __idx1 __idx2 49 | 50 | (( __first_call )) && { 51 | # Called for the first time - new command. 52 | # FAST_HIGHLIGHT is used because it survives between calls, and 53 | # allows to use a single global hash only, instead of multiple 54 | # global string variables. 55 | FAST_HIGHLIGHT[chroma-example-counter]=0 56 | 57 | # Set style for region_highlight entry. It is used below in 58 | # '[[ -n "$__style" ]] ...' line, which adds highlight entry, 59 | # like "10 12 fg=green", through `reply' array. 60 | # 61 | # Could check if command `example' exists and set `unknown-token' 62 | # style instead of `command' 63 | __style=${FAST_THEME_NAME}command 64 | 65 | } || { 66 | # Following call, i.e. not the first one 67 | 68 | # Check if chroma should end – test if token is of type 69 | # "starts new command", if so pass-through – chroma ends 70 | [[ "$__arg_type" = 3 ]] && return 2 71 | 72 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 73 | return 1 74 | fi 75 | 76 | if [[ "$__wrd" = -* ]]; then 77 | # Detected option, add style for it. 78 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 79 | __style=${FAST_THEME_NAME}single-hyphen-option 80 | else 81 | # Count non-option tokens 82 | (( FAST_HIGHLIGHT[chroma-example-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-example-counter] )) 83 | 84 | # Colorize 1..2 as builtin, 3.. as glob 85 | if (( FAST_HIGHLIGHT[chroma-example-counter] <= 2 )); then 86 | if [[ "$__wrd" = \"* ]]; then 87 | # Pass through, fsh main code will do the highlight! 88 | return 1 89 | else 90 | __style=${FAST_THEME_NAME}builtin 91 | fi 92 | else 93 | __style=${FAST_THEME_NAME}globbing 94 | fi 95 | fi 96 | } 97 | 98 | # Add region_highlight entry (via `reply' array). 99 | # If 1 will be added to __start_pos, this will highlight "oken". 100 | # If 1 will be subtracted from __end_pos, this will highlight "toke". 101 | # $PREBUFFER is for specific situations when users does command \ 102 | # i.e. when multi-line command using backslash is entered. 103 | # 104 | # This is a common place of adding such entry, but any above code can do 105 | # it itself (and it does in other chromas) and skip setting __style to 106 | # this way disable this code. 107 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 108 | 109 | # We aren't passing-through, do obligatory things ourselves. 110 | # _start_pos=$_end_pos advainces pointers in command line buffer. 111 | # 112 | # To pass through means to `return 1'. The highlighting of 113 | # this single token is then done by fast-syntax-highlighting's 114 | # main code and chroma doesn't have to do anything. 115 | (( this_word = next_word )) 116 | _start_pos=$_end_pos 117 | 118 | return 0 119 | 120 | # vim:ft=zsh:et:sw=4 121 | -------------------------------------------------------------------------------- /→chroma/-fast-theme.ch: -------------------------------------------------------------------------------- 1 | # vim:ft=zsh:et:sw=4 2 | (( next_word = 2 | 8192 )) 3 | [[ "$__arg_type" = 3 ]] && return 2 4 | 5 | local __first_call="$1" __wrd="${(Q)2}" __start_pos="$3" __end_pos="$4" 6 | local __style 7 | 8 | if (( __first_call )); then 9 | FAST_HIGHLIGHT[chroma-fast-theme-first]=0 10 | return 1 11 | elif (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 12 | return 1 13 | elif (( ${FAST_HIGHLIGHT[chroma-fast-theme-first]} )) || [[ $__wrd = -* ]]; then 14 | return 1 15 | else 16 | FAST_HIGHLIGHT[chroma-fast-theme-first]=1 17 | fi 18 | 19 | if [[ "$__wrd" = */* || "$__wrd" = (XDG|LOCAL|HOME|OPT):* ]]; then 20 | __wrd="${${__wrd/(#s)XDG:/${${XDG_CONFIG_HOME:-$HOME/.config}%/}/fsh/}%.ini}.ini" 21 | __wrd="${${__wrd/(#s)LOCAL://usr/local/share/fsh/}%.ini}.ini" 22 | __wrd="${${__wrd/(#s)HOME:/$HOME/.fsh/}%.ini}.ini" 23 | __wrd="${${__wrd/(#s)OPT://opt/local/share/fsh/}%.ini}.ini" 24 | __wrd=${~__wrd} # allow user to quote ~ 25 | else 26 | __wrd="$FAST_BASE_DIR/themes/$__wrd.ini" 27 | fi 28 | 29 | if [[ -f $__wrd ]]; then 30 | __style=${FAST_THEME_NAME}path 31 | else 32 | __style=${FAST_THEME_NAME}incorrect-subtle 33 | fi 34 | 35 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 36 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 37 | (( this_word = next_word )) 38 | _start_pos=$_end_pos 39 | 40 | return 0 41 | -------------------------------------------------------------------------------- /→chroma/-fpath_peq.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # This chroma does a narrow, obscure but prestigious parsing of fpath+=( elem1 5 | # elem2 ... ) construct to provide *the* *future* contents of $fpath to 6 | # -autoload.ch, so that it can detect functions in those provided directories 7 | # `elem1', `elem2', etc. and highlight the functions with `correct-subtle' 8 | # instead of `incorrect-subtle'. Basically all thit is for command-lines like: 9 | # 10 | # % fpath+=( `pwd` ); autoload my-fun-from-PWD 11 | 12 | # Keep chroma-takever state meaning: until ; or similar (see $__arg_type below) 13 | # The 8192 sum takes care that the next token will be routed to this chroma 14 | (( next_word = 2 | 8192 )) 15 | 16 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 17 | local -a deserialized 18 | 19 | (( __first_call )) && { 20 | case $__wrd in 21 | (fpath=\() 22 | FAST_HIGHLIGHT[fpath_peq_mode]=1 23 | ;; 24 | (fpath+=\() 25 | FAST_HIGHLIGHT[fpath_peq_mode]=2 26 | ;; 27 | (FPATH=) 28 | FAST_HIGHLIGHT[fpath_peq_mode]=4 29 | ;; 30 | (FPATH+=) 31 | FAST_HIGHLIGHT[fpath_peq_mode]=8 32 | ;; 33 | esac 34 | if (( FAST_HIGHLIGHT[fpath_peq_mode] & 5 )); then 35 | FAST_HIGHLIGHT[chroma-fpath_peq-elements]="! ${FAST_HIGHLIGHT[chroma-fpath_peq-elements]}" 36 | fi 37 | return 1 38 | } || { 39 | # Following call, i.e. not the first one 40 | 41 | # Check if chroma should end – test if token is of type 42 | # "starts new command", if so pass-through – chroma ends 43 | [[ "$__arg_type" = 3 ]] && return 2 44 | 45 | [[ "$__wrd" != ")" ]] && { 46 | deserialized=( "${(Q@)${(z@)FAST_HIGHLIGHT[chroma-fpath_peq-elements]}}" ) 47 | [[ -z "${deserialized[1]}" && ${#deserialized} -eq 1 ]] && deserialized=() 48 | # Support ~ and $VAR, for [a-zA-Z_][a-ZA-Z0-9_]# characters in "VAR" 49 | deserialized+=( "${(Q)${${(j: :)__wrd}//(#b)((\$([0-9]##|[a-zA-Z_][a-zA-Z0-9_]#))|(\$\{([0-9]##|[a-zA-Z_][a-zA-Z0-9_]#)\})|(#s)~)/${(P)${${${${match[1]##\$\{(#c0,1)}%\}}:#\~}:-HOME}}}}" ) 50 | FAST_HIGHLIGHT[chroma-fpath_peq-elements]="${(j: :)${(q@)deserialized}}" 51 | } 52 | 53 | return 1 54 | } 55 | 56 | (( this_word = next_word )) 57 | _start_pos=$_end_pos 58 | 59 | return 0 60 | 61 | # vim:ft=zsh:et:sw=4 62 | -------------------------------------------------------------------------------- /→chroma/-grep.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 5 | # 6 | # $2 - the current token, also accessible by $__arg from the above scope - 7 | # basically a private copy of $__arg; the token can be eg.: "grep" 8 | # 9 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 10 | # command line buffer, used to add region_highlight entry (see man), 11 | # because Zsh colorizes by *ranges* in command line buffer 12 | # 13 | # $4 - a private copy of $_end_pos from the above scope 14 | # 15 | 16 | (( next_word = 2 | 8192 )) 17 | 18 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 19 | local __style __chars 20 | integer __idx1 __idx2 21 | 22 | # First call, i.e. command starts, i.e. "grep" token etc. 23 | (( __first_call )) && { 24 | FAST_HIGHLIGHT[chroma-grep-counter]=0 25 | return 1 26 | } || { 27 | # Following call, i.e. not the first one. 28 | 29 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 30 | return 1 31 | fi 32 | 33 | # Check if chroma should end – test if token is of type 34 | # "starts new command", if so pass-through – chroma ends 35 | [[ "$__arg_type" = 3 ]] && return 2 36 | 37 | if [[ "$__wrd" = -* ]]; then 38 | # Detected option, add style for it. 39 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 40 | __style=${FAST_THEME_NAME}single-hyphen-option 41 | else 42 | # Count non-option tokens. 43 | (( FAST_HIGHLIGHT[chroma-grep-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-grep-counter] )) 44 | 45 | # First non-option token is the pattern (regex), we will 46 | # highlight it. 47 | if (( FAST_HIGHLIGHT[chroma-grep-counter] == 1 )); then 48 | [[ "$__wrd" = \"* ]] && __style=${FAST_THEME_NAME}double-quoted-argument 49 | [[ "$__wrd" = \'* ]] && __style=${FAST_THEME_NAME}single-quoted-argument 50 | [[ "$__wrd" = \$\'* ]] && __style=${FAST_THEME_NAME}dollar-quoted-argument 51 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 52 | __style="" 53 | 54 | __chars="*+\\)([]^\$" 55 | __idx1=__start_pos 56 | __idx2=__start_pos 57 | while [[ "$__wrd" = (#b)[^$__chars]#([\\][\\])#((+|\*|\[|\]|\)|\(|\^|\$)|[\\](+|\*|\[|\]|\)|\(|\^|\$))(*) ]]; do 58 | if [[ -n "${match[3]}" ]]; then 59 | __idx1+=${mbegin[3]}-1 60 | __idx2=__idx1+${mend[3]}-${mbegin[3]}+1 61 | (( __start=__idx1-${#PREBUFFER}, __end=__idx2-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}for-loop-operator]}") 62 | __idx1=__idx2 63 | else 64 | __idx1+=${mbegin[5]}-1 65 | fi 66 | __wrd="${match[5]}" 67 | done 68 | elif (( FAST_HIGHLIGHT[chroma-grep-counter] == 2 )); then 69 | # Handle paths, etc. normally - just pass-through to the big 70 | # highlighter (the main FSH highlighter, used before chromas). 71 | return 1 72 | fi 73 | fi 74 | } 75 | 76 | # Add region_highlight entry (via `reply' array). 77 | # 78 | # This is a common place of adding such entry, but any above 79 | # code can do it itself (and it does) and skip setting __style 80 | # to disable this code. 81 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 82 | 83 | # We aren't passing-through (no return 1 occured), do obligatory things ourselves. 84 | (( this_word = next_word )) 85 | _start_pos=$_end_pos 86 | 87 | return 0 88 | 89 | # vim:ft=zsh:et:sw=4 90 | -------------------------------------------------------------------------------- /→chroma/-hub.ch: -------------------------------------------------------------------------------- 1 | # vim:ft=zsh:et:sw=4 2 | (( next_word = 2 | 8192 )) 3 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 4 | 5 | if (( __first_call )); then 6 | chroma/-git.ch $* 7 | return 1 8 | fi 9 | [[ "$__arg_type" = 3 ]] && return 2 10 | 11 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 12 | return 1 13 | fi 14 | 15 | if [[ "$__wrd" != -* ]] && (( FAST_HIGHLIGHT[chroma-git-got-subcommand] == 0 )); then 16 | .fast-run-command "git config --get-regexp 'alias.*'" chroma-git-alias-list "" $(( 5 * 60 )) 17 | # Grep for line: alias.{user-entered-subcmd}[[:space:]], and remove alias. prefix 18 | __lines_list=( ${${(M)__lines_list[@]:#alias.${__wrd}[[:space:]]##*}#alias.} ) 19 | 20 | if (( ${#__lines_list} > 0 )); then 21 | # (*) 22 | # First remove alias name (#*[[:space:]]) and the space after it, then 23 | # remove any leading spaces from what's left (##[[:space:]]##), then 24 | # remove everything except the first word that's in the left line 25 | # (%%[[:space:]]##*, i.e.: "everything from right side up to any space") 26 | FAST_HIGHLIGHT[chroma-git-subcommand]="${${${__lines_list[1]#*[[:space:]]}##[[:space:]]##}%%[[:space:]]##*}" 27 | else 28 | FAST_HIGHLIGHT[chroma-git-subcommand]="$__wrd" 29 | fi 30 | if [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "browse" \ 31 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "ci-status" \ 32 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "compare" \ 33 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "create" \ 34 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "delete" \ 35 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "fork" \ 36 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "issue" \ 37 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "pr" \ 38 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "pull-request" \ 39 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "release" \ 40 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "sync" ]]; then 41 | FAST_HIGHLIGHT[chroma-git-got-subcommand]=1 42 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 43 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}") 44 | (( FAST_HIGHLIGHT[chroma-git-counter] += 1 )) 45 | (( this_word = next_word )) 46 | _start_pos=$4 47 | return 0 48 | fi 49 | fi 50 | 51 | chroma/-git.ch $* 52 | -------------------------------------------------------------------------------- /→chroma/-ionice.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # ------------------------------------------------------------------------------------------------- 3 | # Copyright (c) 2018 Sebastian Gniazdowski 4 | # Copyright (C) 2019 by Philippe Troin (F-i-f on GitHub) 5 | # All rights reserved. 6 | # 7 | # The only licensing for this file follows. 8 | # 9 | # Redistribution and use in source and binary forms, with or without modification, are permitted 10 | # provided that the following conditions are met: 11 | # 12 | # * Redistributions of source code must retain the above copyright notice, this list of conditions 13 | # and the following disclaimer. 14 | # * Redistributions in binary form must reproduce the above copyright notice, this list of 15 | # conditions and the following disclaimer in the documentation and/or other materials provided 16 | # with the distribution. 17 | # * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors 18 | # may be used to endorse or promote products derived from this software without specific prior 19 | # written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 22 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 23 | # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 24 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 27 | # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 28 | # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | # ------------------------------------------------------------------------------------------------- 30 | 31 | setopt local_options extendedglob warn_create_global typeset_silent 32 | 33 | # Keep chroma-takever state meaning: until ;, handle highlighting via chroma. 34 | # So the below 8192 assignment takes care that next token will be routed to chroma. 35 | (( next_word = 2 | 8192 )) 36 | 37 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 38 | local __style option_start=0 option_end=0 number_start=0 number_end=0 39 | local -a match mbegin mend 40 | 41 | (( __first_call )) && { 42 | # Called for the first time - new command. 43 | # FAST_HIGHLIGHT is used because it survives between calls, and 44 | # allows to use a single global hash only, instead of multiple 45 | # global string variables. 46 | FAST_HIGHLIGHT[ionice-option-argument]=0 47 | 48 | # Set style for region_highlight entry. It is used below in 49 | # '[[ -n "$__style" ]] ...' line, which adds highlight entry, 50 | # like "10 12 fg=green", through `reply' array. 51 | # 52 | # Could check if command `example' exists and set `unknown-token' 53 | # style instead of `command' 54 | __style=${FAST_THEME_NAME}precommand 55 | 56 | } || { 57 | # Following call, i.e. not the first one 58 | 59 | # Check if chroma should end – test if token is of type 60 | # "starts new command", if so pass-through – chroma ends 61 | [[ "$__arg_type" = 3 ]] && return 2 62 | 63 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 64 | return 1 65 | fi 66 | 67 | if (( FAST_HIGHLIGHT[ionice-option-argument] )); then 68 | (( FAST_HIGHLIGHT[ionice-option-argument] = 0 )) 69 | [[ $__wrd == [0-9]# ]] && __style=${FAST_THEME_NAME}mathnum || __style=${FAST_THEME_NAME}incorrect-subtle 70 | else 71 | case $__wrd in 72 | --(class(data|)|(u|p(g|))id)) 73 | __style=${FAST_THEME_NAME}double-hyphen-option 74 | FAST_HIGHLIGHT[ionice-option-argument]=1 75 | ;; 76 | -[cnpPu]) 77 | __style=${FAST_THEME_NAME}single-hyphen-option 78 | FAST_HIGHLIGHT[ionice-option-argument]=1 79 | ;; 80 | --*) 81 | __style=${FAST_THEME_NAME}double-hyphen-option 82 | ;; 83 | -*) 84 | __style=${FAST_THEME_NAME}single-hyphen-option 85 | ;; 86 | *) 87 | this_word=1 88 | next_word=2 89 | return 1 90 | ;; 91 | esac 92 | fi 93 | } 94 | 95 | # Add region_highlight entry (via `reply' array). 96 | # If 1 will be added to __start_pos, this will highlight "oken". 97 | # If 1 will be subtracted from __end_pos, this will highlight "toke". 98 | # $PREBUFFER is for specific situations when users does command \ 99 | # i.e. when multi-line command using backslash is entered. 100 | # 101 | # This is a common place of adding such entry, but any above code can do 102 | # it itself (and it does in other chromas) and skip setting __style to 103 | # this way disable this code. 104 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 105 | 106 | # We aren't passing-through, do obligatory things ourselves. 107 | # _start_pos=$_end_pos advainces pointers in command line buffer. 108 | # 109 | # To pass through means to `return 1'. The highlighting of 110 | # this single token is then done by fast-syntax-highlighting's 111 | # main code and chroma doesn't have to do anything. 112 | (( this_word = next_word )) 113 | _start_pos=$_end_pos 114 | 115 | return 0 116 | 117 | # vim:ft=zsh:et:sw=4 118 | -------------------------------------------------------------------------------- /→chroma/-lab.ch: -------------------------------------------------------------------------------- 1 | # vim:ft=zsh:et:sw=4 2 | # 3 | # The `lab' tool after which this chroma is modeled after: 4 | # https://github.com/zaquestion/lab 5 | # 6 | (( next_word = 2 | 8192 )) 7 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 8 | 9 | if (( __first_call )); then 10 | chroma/-git.ch $* 11 | return 1 12 | fi 13 | [[ "$__arg_type" = 3 ]] && return 2 14 | 15 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 16 | return 1 17 | fi 18 | 19 | if [[ "$__wrd" != -* ]] && (( FAST_HIGHLIGHT[chroma-git-got-subcommand] == 0 )); then 20 | .fast-run-command "git config --get-regexp 'alias.*'" chroma-git-alias-list "" $(( 5 * 60 )) 21 | # Grep for line: alias.{user-entered-subcmd}[[:space:]], and remove alias. prefix 22 | __lines_list=( ${${(M)__lines_list[@]:#alias.${__wrd}[[:space:]]##*}#alias.} ) 23 | 24 | if (( ${#__lines_list} > 0 )); then 25 | # (*) 26 | # First remove alias name (#*[[:space:]]) and the space after it, then 27 | # remove any leading spaces from what's left (##[[:space:]]##), then 28 | # remove everything except the first word that's in the left line 29 | # (%%[[:space:]]##*, i.e.: "everything from right side up to any space") 30 | FAST_HIGHLIGHT[chroma-git-subcommand]="${${${__lines_list[1]#*[[:space:]]}##[[:space:]]##}%%[[:space:]]##*}" 31 | else 32 | FAST_HIGHLIGHT[chroma-git-subcommand]="$__wrd" 33 | fi 34 | if [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "browse" \ 35 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "ci" \ 36 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "mr" \ 37 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "project" \ 38 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "snippet" \ 39 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "ci-status" \ 40 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "compare" \ 41 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "create" \ 42 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "delete" \ 43 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "fork" \ 44 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "issue" \ 45 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "pr" \ 46 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "pull-request" \ 47 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "release" \ 48 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "sync" ]]; then 49 | FAST_HIGHLIGHT[chroma-git-got-subcommand]=1 50 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 51 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}") 52 | (( FAST_HIGHLIGHT[chroma-git-counter] += 1 )) 53 | (( this_word = next_word )) 54 | _start_pos=$4 55 | return 0 56 | fi 57 | fi 58 | 59 | chroma/-git.ch $* 60 | -------------------------------------------------------------------------------- /→chroma/-make.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # Chroma function for command `make'. 5 | # 6 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 7 | # $2 - the current token, also accessible by $__arg from the above scope - 8 | # basically a private copy of $__arg 9 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 10 | # command line buffer, used to add region_highlight entry (see man), 11 | # because Zsh colorizes by *ranges* in command line buffer 12 | # $4 - a private copy of $_end_pos from the above scope 13 | # 14 | 15 | (( next_word = 2 | 8192 )) 16 | 17 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 18 | local __style 19 | integer __idx1 __idx2 20 | local -a __lines_list reply2 21 | 22 | (( __first_call )) && { 23 | # Called for the first time - new command. 24 | # FAST_HIGHLIGHT is used because it survives between calls, and 25 | # allows to use a single global hash only, instead of multiple 26 | # global variables. 27 | FAST_HIGHLIGHT[chroma-make-counter]=0 28 | FAST_HIGHLIGHT[chroma-make-skip-two]=0 29 | FAST_HIGHLIGHT[chroma-make-custom-dir]="./" 30 | FAST_HIGHLIGHT[chroma-make-custom-file]="Makefile" 31 | FAST_HIGHLIGHT[chroma-make-got-custom-dir-opt]=0 32 | FAST_HIGHLIGHT[chroma-make-got-custom-file-opt]=0 33 | return 1 34 | } || { 35 | # Following call, i.e. not the first one. 36 | 37 | # Check if chroma should end – test if token is of type 38 | # "starts new command", if so pass-through – chroma ends 39 | [[ "$__arg_type" = 3 ]] && return 2 40 | 41 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 42 | return 1 43 | fi 44 | 45 | if [[ "$__wrd" = -* || "$__wrd" = *=* ]]; then 46 | [[ "$__wrd" = *=* ]] && { 47 | __style=${FAST_THEME_NAME}variable 48 | } || { 49 | __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option} 50 | } 51 | 52 | if [[ "$__wrd" = (-I|-o|-W) ]]; then 53 | FAST_HIGHLIGHT[chroma-make-skip-two]=1 54 | elif [[ "$__wrd" = "-C" ]]; then 55 | FAST_HIGHLIGHT[chroma-make-got-custom-dir-opt]=1 56 | elif [[ "$__wrd" = "-f" ]]; then 57 | FAST_HIGHLIGHT[chroma-make-got-custom-file-opt]=1 58 | fi 59 | else 60 | if (( FAST_HIGHLIGHT[chroma-make-skip-two] )); then 61 | FAST_HIGHLIGHT[chroma-make-skip-two]=0 62 | elif (( FAST_HIGHLIGHT[chroma-make-got-custom-dir-opt] )); then 63 | FAST_HIGHLIGHT[chroma-make-got-custom-dir-opt]=0 64 | FAST_HIGHLIGHT[chroma-make-custom-dir]="$__wrd" 65 | elif (( FAST_HIGHLIGHT[chroma-make-got-custom-file-opt] )); then 66 | FAST_HIGHLIGHT[chroma-make-got-custom-file-opt]=0 67 | FAST_HIGHLIGHT[chroma-make-custom-file]="$__wrd" 68 | else 69 | # Count non-option tokens. 70 | (( FAST_HIGHLIGHT[chroma-make-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-make-counter] )) 71 | if (( FAST_HIGHLIGHT[chroma-make-counter] == 1 )); then 72 | __wrd="${__wrd//\`/x}" 73 | __wrd="${(Q)__wrd}" 74 | 75 | if [[ -f "${FAST_HIGHLIGHT[chroma-make-custom-dir]%/}/${FAST_HIGHLIGHT[chroma-make-custom-file]}" ]] && \ 76 | .fast-make-targets < "${FAST_HIGHLIGHT[chroma-make-custom-dir]%/}/${FAST_HIGHLIGHT[chroma-make-custom-file]}" 77 | then 78 | if [[ "${reply2[(r)$__wrd]}" ]]; then 79 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") 80 | else 81 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") 82 | fi 83 | fi 84 | else 85 | # Pass-through to the big-loop outside 86 | return 1 87 | fi 88 | fi 89 | fi 90 | } 91 | 92 | # Add region_highlight entry (via `reply' array) 93 | # 94 | # This is a common place of adding such entry, but any above 95 | # code can do it itself (and it does) and skip setting __style 96 | # to disable this code. 97 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 98 | 99 | # We aren't passing-through, do obligatory things ourselves 100 | (( this_word = next_word )) 101 | _start_pos=$_end_pos 102 | 103 | return 0 104 | 105 | # vim:ft=zsh:et:sw=4 106 | -------------------------------------------------------------------------------- /→chroma/-nice.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # ------------------------------------------------------------------------------------------------- 3 | # Copyright (c) 2018 Sebastian Gniazdowski 4 | # Copyright (C) 2019 by Philippe Troin (F-i-f on GitHub) 5 | # All rights reserved. 6 | # 7 | # The only licensing for this file follows. 8 | # 9 | # Redistribution and use in source and binary forms, with or without modification, are permitted 10 | # provided that the following conditions are met: 11 | # 12 | # * Redistributions of source code must retain the above copyright notice, this list of conditions 13 | # and the following disclaimer. 14 | # * Redistributions in binary form must reproduce the above copyright notice, this list of 15 | # conditions and the following disclaimer in the documentation and/or other materials provided 16 | # with the distribution. 17 | # * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors 18 | # may be used to endorse or promote products derived from this software without specific prior 19 | # written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 22 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 23 | # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 24 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 27 | # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 28 | # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | # ------------------------------------------------------------------------------------------------- 30 | 31 | setopt local_options extendedglob warn_create_global typeset_silent 32 | 33 | # Keep chroma-takever state meaning: until ;, handle highlighting via chroma. 34 | # So the below 8192 assignment takes care that next token will be routed to chroma. 35 | (( next_word = 2 | 8192 )) 36 | 37 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 38 | local __style option_start=0 option_end=0 number_start=0 number_end=0 39 | local -a match mbegin mend 40 | 41 | (( __first_call )) && { 42 | # Called for the first time - new command. 43 | # FAST_HIGHLIGHT is used because it survives between calls, and 44 | # allows to use a single global hash only, instead of multiple 45 | # global string variables. 46 | FAST_HIGHLIGHT[nice-arg-count]=0 47 | FAST_HIGHLIGHT[nice-increment-argument]=0 48 | 49 | # Set style for region_highlight entry. It is used below in 50 | # '[[ -n "$__style" ]] ...' line, which adds highlight entry, 51 | # like "10 12 fg=green", through `reply' array. 52 | # 53 | # Could check if command `example' exists and set `unknown-token' 54 | # style instead of `command' 55 | __style=${FAST_THEME_NAME}precommand 56 | 57 | } || { 58 | # Following call, i.e. not the first one 59 | 60 | # Check if chroma should end – test if token is of type 61 | # "starts new command", if so pass-through – chroma ends 62 | [[ "$__arg_type" = 3 ]] && return 2 63 | 64 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 65 | return 1 66 | fi 67 | 68 | if (( FAST_HIGHLIGHT[nice-increment-argument] )); then 69 | (( FAST_HIGHLIGHT[nice-increment-argument] = 0 )) 70 | [[ $__wrd = (-|+|)[0-9]## ]] \ 71 | && __style=${FAST_THEME_NAME}mathnum \ 72 | || __style=${FAST_THEME_NAME}incorrect-subtle 73 | else 74 | case $__wrd in 75 | -(-|+|)[0-9]##) 76 | (( option_start = __start_pos-${#PREBUFFER} , 77 | option_end = option_start+1 , 78 | number_start = option_end , 79 | number_end = __end_pos-${#PREBUFFER} )) 80 | option_style=${FAST_THEME_NAME}single-hyphen-option 81 | ;; 82 | (#b)(--adjustment)(=(-|+|)[0-9]#|)) 83 | (( option_start = __start_pos-${#PREBUFFER} , 84 | option_end = option_start+mend[1] )) 85 | option_style=${FAST_THEME_NAME}double-hyphen-option 86 | [[ -z $match[2] ]] \ 87 | && (( FAST_HIGHLIGHT[nice-increment-argument] = 1 )) \ 88 | || (( option_end += 1 , 89 | number_start = option_start+mbegin[2]-mbegin[1]+1 , 90 | number_end = __end_pos-${#PREBUFFER} )) 91 | ;; 92 | -n) 93 | __style=${FAST_THEME_NAME}double-hyphen-option 94 | FAST_HIGHLIGHT[nice-increment-argument]=1 95 | ;; 96 | --*) 97 | __style=${FAST_THEME_NAME}double-hyphen-option 98 | ;; 99 | -*) 100 | __style=${FAST_THEME_NAME}single-hyphen-option 101 | ;; 102 | *) 103 | this_word=1 104 | next_word=2 105 | return 1 106 | ;; 107 | esac 108 | 109 | (( option_start > 0 && option_end )) \ 110 | && reply+=("$option_start $option_end ${FAST_HIGHLIGHT_STYLES[$option_style]}") 111 | (( number_start > 0 && number_end )) \ 112 | && reply+=("$number_start $number_end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}mathnum]}") 113 | fi 114 | } 115 | 116 | # Add region_highlight entry (via `reply' array). 117 | # If 1 will be added to __start_pos, this will highlight "oken". 118 | # If 1 will be subtracted from __end_pos, this will highlight "toke". 119 | # $PREBUFFER is for specific situations when users does command \ 120 | # i.e. when multi-line command using backslash is entered. 121 | # 122 | # This is a common place of adding such entry, but any above code can do 123 | # it itself (and it does in other chromas) and skip setting __style to 124 | # this way disable this code. 125 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 126 | 127 | # We aren't passing-through, do obligatory things ourselves. 128 | # _start_pos=$_end_pos advainces pointers in command line buffer. 129 | # 130 | # To pass through means to `return 1'. The highlighting of 131 | # this single token is then done by fast-syntax-highlighting's 132 | # main code and chroma doesn't have to do anything. 133 | (( this_word = next_word )) 134 | _start_pos=$_end_pos 135 | 136 | return 0 137 | 138 | # vim:ft=zsh:et:sw=4 139 | -------------------------------------------------------------------------------- /→chroma/-nmcli.ch: -------------------------------------------------------------------------------- 1 | # vim:ft=zsh:et:sw=4 2 | (( next_word = 2 | 8192 )) 3 | [[ "$__arg_type" = 3 ]] && return 2 4 | 5 | typeset -A subcommands 6 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" subcommand 7 | subcommands=( 8 | help "_" 9 | general "help status hostname permissions logging _" 10 | networking "help on off connectivity _" 11 | radio "help all wifi wwan _" 12 | connection "help show up down add modify clone edit delete monitor reload load import export _" 13 | device "help status show set connect reapply modify disconnect delete monitor wifi lldp _" 14 | agent "help secret polkit all _" 15 | monitor "help _" 16 | _ "_" 17 | ) 18 | 19 | if (( __first_call )); then 20 | FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]="" 21 | FAST_HIGHLIGHT[chroma-nmcli-subcommand-b]="" 22 | return 1 23 | elif (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 24 | return 1 25 | elif [[ "$2" = -* ]]; then 26 | return 1 27 | elif [[ -z ${FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]} ]]; then 28 | for subcommand in ${(@k)subcommands}; do 29 | [[ $subcommand = $__wrd* ]] && break || subcommand="_" 30 | done 31 | if [[ $subcommand = _ ]]; then 32 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 33 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") 34 | else 35 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 36 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}") 37 | fi 38 | FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]="$subcommand" 39 | elif [[ -z ${FAST_HIGHLIGHT[chroma-nmcli-subcommand-b]} ]]; then 40 | for subcommand in ${(s. .)subcommands[${FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]}]}; do 41 | [[ "$subcommand" = $__wrd* ]] && break || subcommand="_" 42 | done 43 | if [[ $subcommand = _ ]]; then 44 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 45 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") 46 | else 47 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 48 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}") 49 | fi 50 | FAST_HIGHLIGHT[chroma-nmcli-subcommand-b]="$subcommand" 51 | else 52 | return 1 53 | fi 54 | 55 | (( this_word = next_word )) 56 | _start_pos=$_end_pos 57 | 58 | return 0 59 | -------------------------------------------------------------------------------- /→chroma/-node.ch: -------------------------------------------------------------------------------- 1 | # vim:ft=zsh:et:sw=4 2 | (( next_word = 2 | 8192 )) 3 | [[ "$__arg_type" = 3 ]] && return 2 4 | 5 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 6 | local __style 7 | 8 | if (( __first_call )); then 9 | FAST_HIGHLIGHT[chroma-node-file]=1 10 | elif (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 11 | return 1 12 | elif [[ "$__wrd" = -- ]]; then 13 | FAST_HIGHLIGHT[chroma-node-file]=2 14 | elif (( FAST_HIGHLIGHT[chroma-node-file] != 2 )) && [[ "$__wrd" = -* ]]; then 15 | if [[ "$__wrd" = -*e* || "$__wrd" = --eval ]]; then 16 | FAST_HIGHLIGHT[chroma-node-file]=0 17 | fi 18 | elif (( FAST_HIGHLIGHT[chroma-node-file] )); then 19 | if [[ "$__wrd" = debug || "$__wrd" = inspect ]]; then 20 | __style=${FAST_THEME_NAME}subcommand 21 | else 22 | FAST_HIGHLIGHT[chroma-node-file]=0 23 | if [[ -f ${~__wrd} || -f ${~__wrd}.js || -f ${~__wrd}/index.js ]]; then 24 | __style=${FAST_THEME_NAME}path 25 | else 26 | __style=${FAST_THEME_NAME}incorrect-subtle 27 | fi 28 | fi 29 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 30 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 31 | (( this_word = next_word )) 32 | _start_pos=$_end_pos 33 | 34 | return 0 35 | fi 36 | 37 | return 1 38 | -------------------------------------------------------------------------------- /→chroma/-perl.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # Chroma function for command `perl'. It highlights code passed to perl 5 | # with -e option - does syntax check by calling `perl -ce', then highlights 6 | # as correct or incorrect code. 7 | # 8 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 9 | # $2 - the current token, also accessible by $__arg from the above scope - 10 | # basically a private copy of $__arg 11 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 12 | # command line buffer, used to add region_highlight entry (see man), 13 | # because Zsh colorizes by *ranges* in command line buffer 14 | # $4 - a private copy of $_end_pos from the above scope 15 | # 16 | 17 | (( next_word = 2 | 8192 )) 18 | 19 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 20 | local __style 21 | integer __idx1 __idx2 22 | 23 | (( __first_call )) && { 24 | # Called for the first time - new command. 25 | # FAST_HIGHLIGHT is used because it survives between calls, and 26 | # allows to use a single global hash only, instead of multiple 27 | # global variables. 28 | FAST_HIGHLIGHT[chrome-perl-got-eswitch]=0 29 | return 1 30 | } || { 31 | # Following call, i.e. not the first one. 32 | 33 | # Check if chroma should end – test if token is of type 34 | # "starts new command", if so pass-through – chroma ends 35 | [[ "$__arg_type" = 3 ]] && return 2 36 | 37 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 38 | return 1 39 | fi 40 | 41 | if [[ "$__wrd" = -* && ${FAST_HIGHLIGHT[chroma-perl-got-subcommand]} -eq 0 ]]; then 42 | __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option} 43 | 44 | if [[ "$__wrd" = "-e" || ("$__wrd" = -*e* && "$__wrd" != --*) ]]; then 45 | FAST_HIGHLIGHT[chrome-perl-got-eswitch]=1 46 | fi 47 | else 48 | __wrd="${__wrd//\`/x}" 49 | __arg="${__arg//\`/x}" 50 | __wrd="${(Q)__wrd}" 51 | if (( FAST_HIGHLIGHT[chrome-perl-got-eswitch] == 1 )); then 52 | FAST_HIGHLIGHT[chrome-perl-got-eswitch]=0 53 | if perl -ce "$__wrd" >/dev/null 2>&1; then 54 | # Add correct-subtle style 55 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") 56 | else 57 | # Add incorrect-subtle style 58 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") 59 | fi 60 | else 61 | # Pass-through to the big-loop outside 62 | return 1 63 | fi 64 | fi 65 | } 66 | 67 | # Add region_highlight entry (via `reply' array) 68 | # 69 | # This is a common place of adding such entry, but any above 70 | # code can do it itself (and it does) and skip setting __style 71 | # to disable this code. 72 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 73 | 74 | # We aren't passing-through, do obligatory things ourselves 75 | (( this_word = next_word )) 76 | _start_pos=$_end_pos 77 | 78 | return 0 79 | 80 | # vim:ft=zsh:et:sw=4 81 | -------------------------------------------------------------------------------- /→chroma/-precommand.ch: -------------------------------------------------------------------------------- 1 | # vim:ft=zsh:et:sw=4 2 | 3 | local __first_call="$1" __start_pos="$3" __end_pos="$4" 4 | 5 | [[ "$__arg_type" = 3 ]] && return 2 6 | 7 | (( __first_call )) && { 8 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 9 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}precommand]}") 10 | (( next_word = (next_word & ~2) | 4 | 1 )) 11 | } || { 12 | return 1 13 | } 14 | 15 | (( this_word = next_word )) 16 | _start_pos=$_end_pos 17 | return 0 18 | -------------------------------------------------------------------------------- /→chroma/-printf.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # Highlights the special sequences like "%s" in string passed to `printf'. 5 | # 6 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 7 | # 8 | # $2 - the current token, also accessible by $__arg from the above scope - 9 | # basically a private copy of $__arg; the token can be eg.: "grep" 10 | # 11 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 12 | # command line buffer, used to add region_highlight entry (see man), 13 | # because Zsh colorizes by *ranges* in command line buffer 14 | # 15 | # $4 - a private copy of $_end_pos from the above scope 16 | # 17 | 18 | (( next_word = 2 | 8192 )) 19 | 20 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 21 | local __style __val 22 | integer __idx1 __idx2 23 | 24 | # First call, i.e. command starts, i.e. "grep" token etc. 25 | (( __first_call )) && { 26 | FAST_HIGHLIGHT[chroma-printf-counter]=0 27 | FAST_HIGHLIGHT[chroma-printf-counter-all]=1 28 | FAST_HIGHLIGHT[chroma-printf-message]="" 29 | FAST_HIGHLIGHT[chroma-printf-skip-two]=0 30 | return 1 31 | # Following call (not first one). 32 | } || { 33 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 34 | return 1 35 | fi 36 | (( FAST_HIGHLIGHT[chroma-printf-counter-all] += 1, __idx2 = FAST_HIGHLIGHT[chroma-printf-counter-all] )) 37 | 38 | # Check if chroma should end – test if token is of type 39 | # "starts new command", if so pass-through – chroma ends 40 | [[ "$__arg_type" = 3 ]] && return 2 41 | 42 | if [[ "$__wrd" = -* ]]; then 43 | if [[ "$__wrd" = "-v" ]]; then 44 | FAST_HIGHLIGHT[chroma-printf-skip-two]=1 45 | fi 46 | return 1 47 | else 48 | # Count non-option tokens. 49 | if (( FAST_HIGHLIGHT[chroma-printf-skip-two] )); then 50 | FAST_HIGHLIGHT[chroma-printf-skip-two]=0 51 | return 1 52 | else 53 | (( FAST_HIGHLIGHT[chroma-printf-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-printf-counter] )) 54 | if [[ "$__idx1" -eq 1 ]]; then 55 | [[ "$__wrd" = \"* ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 56 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}") 57 | [[ "$__wrd" = \'* ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 58 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}single-quoted-argument]}") 59 | FSH_LIST=() # use fsh_sy_h_append function to write to FSH_LIST 60 | : "${__wrd//(#m)\%[\#\+\ 0-]#[0-9]#([.][0-9]#)(#c0,1)[diouxXfFeEgGaAcsb]/$(( fsh_sy_h_append($MBEGIN, $MEND) ))}"; 61 | for __val in "${FSH_LIST[@]}" ; do 62 | __idx1=$(( __start_pos + ${__val%%;;*} )) 63 | __idx2=__idx1+${__val##*;;}-${__val%%;;*}+1 64 | (( __start=__idx1-${#PREBUFFER}, __end=__idx2-${#PREBUFFER}-1, __start >= 0 )) && \ 65 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}mathnum]}") 66 | done 67 | else 68 | return 1 69 | fi 70 | fi 71 | fi 72 | } 73 | 74 | # Add region_highlight entry (via `reply' array). 75 | # 76 | # This is a common place of adding such entry, but any above code 77 | # can do it itself and skip setting __style to disable this code. 78 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 79 | 80 | # We aren't passing-through (no return 1 occured), do obligatory things ourselves. 81 | (( this_word = next_word )) 82 | _start_pos=$_end_pos 83 | 84 | return 0 85 | 86 | # vim:ft=zsh:et:sw=4 87 | -------------------------------------------------------------------------------- /→chroma/-ruby.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # Chroma function for command `ruby'. It highlights code passed to ruby 5 | # with -e option - does syntax check by calling `ruby -ce', then highlights 6 | # as correct or incorrect code. 7 | # 8 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 9 | # $2 - the current token, also accessible by $__arg from the above scope - 10 | # basically a private copy of $__arg 11 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 12 | # command line buffer, used to add region_highlight entry (see man), 13 | # because Zsh colorizes by *ranges* in command line buffer 14 | # $4 - a private copy of $_end_pos from the above scope 15 | # 16 | 17 | (( next_word = 2 | 8192 )) 18 | 19 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 20 | local __style 21 | integer __idx1 __idx2 22 | 23 | (( __first_call )) && { 24 | # Called for the first time - new command. 25 | # FAST_HIGHLIGHT is used because it survives between calls, and 26 | # allows to use a single global hash only, instead of multiple 27 | # global variables. 28 | FAST_HIGHLIGHT[chrome-ruby-got-eswitch]=0 29 | return 1 30 | } || { 31 | # Following call, i.e. not the first one. 32 | 33 | # Check if chroma should end – test if token is of type 34 | # "starts new command", if so pass-through – chroma ends 35 | [[ "$__arg_type" = 3 ]] && return 2 36 | 37 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 38 | return 1 39 | fi 40 | 41 | if [[ "$__wrd" = -* && ${FAST_HIGHLIGHT[chroma-ruby-got-subcommand]} -eq 0 ]]; then 42 | __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option} 43 | 44 | if [[ "$__wrd" = "-e" || ("$__wrd" = -*e* && "$__wrd" != --*) ]]; then 45 | FAST_HIGHLIGHT[chrome-ruby-got-eswitch]=1 46 | fi 47 | else 48 | __wrd="${__wrd//\`/x}" 49 | __arg="${__arg//\`/x}" 50 | __wrd="${(Q)__wrd}" 51 | if (( FAST_HIGHLIGHT[chrome-ruby-got-eswitch] == 1 )); then 52 | FAST_HIGHLIGHT[chrome-ruby-got-eswitch]=0 53 | if ruby -ce "$__wrd" >/dev/null 2>&1; then 54 | # Add correct-subtle style 55 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") 56 | else 57 | # Add incorrect-subtle style 58 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") 59 | fi 60 | else 61 | # Pass-through to the big-loop outside 62 | return 1 63 | fi 64 | FAST_HIGHLIGHT[chrome-ruby-got-eswitch]=0 65 | fi 66 | } 67 | 68 | # Add region_highlight entry (via `reply' array) 69 | # 70 | # This is a common place of adding such entry, but any above 71 | # code can do it itself (and it does) and skip setting __style 72 | # to disable this code. 73 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 74 | 75 | # We aren't passing-through, do obligatory things ourselves 76 | (( this_word = next_word )) 77 | _start_pos=$_end_pos 78 | 79 | return 0 80 | 81 | # vim:ft=zsh:et:sw=4 82 | -------------------------------------------------------------------------------- /→chroma/-scp.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # Tracks scp command and emits message when one tries to pass port to hostspec. 5 | # 6 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 7 | # 8 | # $2 - the current token, also accessible by $__arg from the above scope - 9 | # basically a private copy of $__arg; the token can be eg.: "grep" 10 | # 11 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 12 | # command line buffer, used to add region_highlight entry (see man), 13 | # because Zsh colorizes by *ranges* in command line buffer 14 | # 15 | # $4 - a private copy of $_end_pos from the above scope 16 | # 17 | 18 | (( next_word = 2 | 8192 )) 19 | 20 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 21 | local __style __chars 22 | integer __idx1 __idx2 23 | local -a __results 24 | 25 | # First call, i.e. command starts, i.e. "grep" token etc. 26 | (( __first_call )) && { 27 | FAST_HIGHLIGHT[chroma-scp-counter]=0 28 | FAST_HIGHLIGHT[chroma-scp-counter-all]=1 29 | FAST_HIGHLIGHT[chroma-scp-message]="" 30 | FAST_HIGHLIGHT[chroma-scp-skip-two]=0 31 | return 1 32 | } || { 33 | (( FAST_HIGHLIGHT[chroma-scp-counter-all] += 1, __idx2 = FAST_HIGHLIGHT[chroma-scp-counter-all] )) 34 | 35 | # Following call, i.e. not the first one. 36 | 37 | # Check if chroma should end – test if token is of type 38 | # "starts new command", if so pass-through – chroma ends 39 | [[ "$__arg_type" = 3 ]] && return 2 40 | 41 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 42 | return 1 43 | fi 44 | 45 | if [[ "$__wrd" = -* ]]; then 46 | # Detected option, add style for it. 47 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 48 | __style=${FAST_THEME_NAME}single-hyphen-option 49 | if [[ "$__wrd" = (-c|-F|-i|-l|-o|-P|-S) ]]; then 50 | FAST_HIGHLIGHT[chroma-scp-skip-two]=1 51 | fi 52 | else 53 | # Count non-option tokens. 54 | if (( FAST_HIGHLIGHT[chroma-scp-skip-two] )); then 55 | FAST_HIGHLIGHT[chroma-scp-skip-two]=0 56 | else 57 | (( FAST_HIGHLIGHT[chroma-scp-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-scp-counter] )) 58 | if [[ "${FAST_HIGHLIGHT[chroma-scp-counter]}" -eq 1 ]]; then 59 | if [[ "$__arg" = [^:]##:[0-9]## ]]; then 60 | FAST_HIGHLIGHT[chroma-scp-message]+="Format of hostname incorrect, use -P to pass port number" 61 | else 62 | return 1 63 | fi 64 | else 65 | return 1 66 | fi 67 | fi 68 | fi 69 | 70 | if (( ${#${(z)BUFFER}} <= FAST_HIGHLIGHT[chroma-scp-counter-all] )); then 71 | [[ -n "${FAST_HIGHLIGHT[chroma-scp-message]}" ]] && zle -M "${FAST_HIGHLIGHT[chroma-scp-message]}" 72 | fi 73 | } 74 | 75 | # Add region_highlight entry (via `reply' array). 76 | # 77 | # This is a common place of adding such entry, but any above code 78 | # can do it itself and skip setting __style to disable this code. 79 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 80 | 81 | # We aren't passing-through (no return 1 occured), do obligatory things ourselves. 82 | (( this_word = next_word )) 83 | _start_pos=$_end_pos 84 | 85 | return 0 86 | 87 | # vim:ft=zsh:et:sw=4 88 | -------------------------------------------------------------------------------- /→chroma/-sh.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # Chroma function for `sh' shell. It colorizes string passed with -c option. 5 | # 6 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 7 | # $2 - the current token, also accessible by $__arg from the above scope - 8 | # basically a private copy of $__arg 9 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 10 | # command line buffer, used to add region_highlight entry (see man), 11 | # because Zsh colorizes by *ranges* in command line buffer 12 | # $4 - a private copy of $_end_pos from the above scope 13 | # 14 | 15 | (( next_word = 2 | 8192 )) 16 | 17 | local __first_call=$1 __wrd=$2 __start_pos=$3 __end_pos=$4 18 | local __style 19 | integer __idx1 __idx2 20 | local -a __lines_list 21 | 22 | (( __first_call )) && { 23 | # Called for the first time - new command 24 | FAST_HIGHLIGHT[chrome-git-got-c]=0 25 | return 1 26 | } || { 27 | # Following call, i.e. not the first one 28 | 29 | # Check if chroma should end – test if token is of type 30 | # "starts new command", if so pass-through – chroma ends 31 | [[ $__arg_type = 3 ]] && return 2 32 | 33 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 34 | return 1 35 | fi 36 | 37 | __wrd=${${${(Q)__wrd}#[\"\']}%[\"\']} 38 | if [[ $__wrd = -* && $__wrd != -*c* ]]; then 39 | __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option} 40 | else 41 | if (( FAST_HIGHLIGHT[chrome-git-got-c] == 1 )); then 42 | for (( __idx1 = 1, __idx2 = 1; __idx2 <= __asize; ++ __idx1 )); do 43 | [[ ${__arg[__idx2]} = ${__wrd[__idx1]} ]] && break 44 | while [[ ${__arg[__idx2]} != ${__wrd[__idx1]} ]]; do 45 | (( ++ __idx2 )) 46 | (( __idx2 > __asize )) && { __idx2=0; break; } 47 | done 48 | (( __idx2 == 0 )) && break 49 | [[ ${__arg[__idx2]} = ${__wrd[__idx1]} ]] && break 50 | done 51 | 52 | FAST_HIGHLIGHT[chrome-git-got-c]=0 53 | (( _start_pos-__PBUFLEN >= 0 )) && \ 54 | -fast-highlight-process "$PREBUFFER" "${__wrd}" "$(( __start_pos + __idx2 - 1 ))" 55 | elif [[ $__wrd = -*c* ]]; then 56 | FAST_HIGHLIGHT[chrome-git-got-c]=1 57 | else 58 | return 1 59 | fi 60 | fi 61 | } 62 | 63 | # Add region_highlight entry (via `reply' array) 64 | [[ -n $__style ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 65 | 66 | # We aren't passing-through, do obligatory things ourselves 67 | (( this_word = next_word )) 68 | _start_pos=$_end_pos 69 | 70 | return 0 71 | 72 | # vim:ft=zsh:et:sw=4 73 | -------------------------------------------------------------------------------- /→chroma/-source.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # Chroma for `source' builtin - verifies if file to be sourced compiles 5 | # correctly. 6 | # 7 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 8 | # 9 | # $2 - the current token, also accessible by $__arg from the above scope - 10 | # basically a private copy of $__arg; the token can be eg.: "grep" 11 | # 12 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 13 | # command line buffer, used to add region_highlight entry (see man), 14 | # because Zsh colorizes by *ranges* in command line buffer 15 | # 16 | # $4 - a private copy of $_end_pos from the above scope 17 | # 18 | 19 | (( next_word = 2 | 8192 )) 20 | 21 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 22 | local __style __chars __home=${XDG_CACHE_HOME:-$HOME/.cache}/fsh 23 | integer __idx1 __idx2 24 | 25 | # First call, i.e. command starts, i.e. "grep" token etc. 26 | (( __first_call )) && { 27 | FAST_HIGHLIGHT[chroma-src-counter]=0 28 | __style=${FAST_THEME_NAME}builtin 29 | 30 | } || { 31 | # Following call, i.e. not the first one. 32 | 33 | # Check if chroma should end – test if token is of type 34 | # "starts new command", if so pass-through – chroma ends 35 | [[ "$__arg_type" = 3 ]] && return 2 36 | 37 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 38 | return 1 39 | fi 40 | 41 | if [[ "$__wrd" = -* ]]; then 42 | # Detected option, add style for it. 43 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 44 | __style=${FAST_THEME_NAME}single-hyphen-option 45 | else 46 | # Count non-option tokens. 47 | (( FAST_HIGHLIGHT[chroma-src-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-src-counter] )) 48 | 49 | if (( FAST_HIGHLIGHT[chroma-src-counter] == 1 )); then 50 | command mkdir -p "$__home" 51 | command cp -f "${__wrd}" "$__home" 2>/dev/null && { 52 | zcompile "$__home"/"${__wrd:t}" 2>/dev/null 1>&2 && __style=${FAST_THEME_NAME}correct-subtle || __style=${FAST_THEME_NAME}incorrect-subtle 53 | } 54 | elif (( FAST_HIGHLIGHT[chroma-src-counter] == 2 )); then 55 | # Handle paths, etc. normally - just pass-through to the big 56 | # highlighter (the main FSH highlighter, used before chromas). 57 | return 1 58 | fi 59 | fi 60 | } 61 | 62 | # Add region_highlight entry (via `reply' array). 63 | # 64 | # This is a common place of adding such entry, but any above 65 | # code can do it itself (and it does) and skip setting __style 66 | # to disable this code. 67 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 68 | 69 | # We aren't passing-through (no return 1 occured), do obligatory things ourselves. 70 | (( this_word = next_word )) 71 | _start_pos=$_end_pos 72 | 73 | return 0 74 | 75 | # vim:ft=zsh:et:sw=4 76 | -------------------------------------------------------------------------------- /→chroma/-ssh.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # Copyright (C) 2019 by Philippe Troin (F-i-f on GitHub) 4 | # 5 | # Tracks ssh command and emits message when one tries to pass port to hostspec. 6 | # 7 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 8 | # 9 | # $2 - the current token, also accessible by $__arg from the above scope - 10 | # basically a private copy of $__arg; the token can be eg.: "grep" 11 | # 12 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 13 | # command line buffer, used to add region_highlight entry (see man), 14 | # because Zsh colorizes by *ranges* in command line buffer 15 | # 16 | # $4 - a private copy of $_end_pos from the above scope 17 | # 18 | 19 | emulate -LR zsh 20 | setopt extended_glob warn_create_global typeset_silent 21 | 22 | # This chroma guards that port number isn't passed in hostname (no :{port} occurs). 23 | 24 | (( next_word = 2 | 8192 )) 25 | 26 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 27 | local __style check_port=0 host_start_offset host_style user_style possible_host 28 | local -a match mbegin mend completions_users completions_host 29 | 30 | # First call, i.e. command starts, i.e. "grep" token etc. 31 | (( __first_call )) && { 32 | FAST_HIGHLIGHT[chroma-ssh-counter]=0 33 | FAST_HIGHLIGHT[chroma-ssh-counter-all]=1 34 | FAST_HIGHLIGHT[chroma-ssh-message]="" 35 | FAST_HIGHLIGHT[chroma-ssh-skip-two]=0 36 | return 1 37 | } || { 38 | # Following call, i.e. not the first one. 39 | 40 | # Check if chroma should end – test if token is of type 41 | # "starts new command", if so pass-through – chroma ends 42 | [[ "$__arg_type" = 3 ]] && return 2 43 | 44 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 45 | return 1 46 | fi 47 | 48 | (( FAST_HIGHLIGHT[chroma-ssh-counter-all] += 1 )) 49 | 50 | if [[ "$__wrd" = -* ]]; then 51 | # Detected option, add style for it. 52 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 53 | __style=${FAST_THEME_NAME}single-hyphen-option 54 | if [[ "$__wrd" = (-b|-c|-D|-E|-e|-F|-I|-i|-J|-L|-l|-m|-O|-o|-p|Q|R|-S|-W|-w) ]]; then 55 | FAST_HIGHLIGHT[chroma-ssh-skip-two]=1 56 | fi 57 | else 58 | if (( FAST_HIGHLIGHT[chroma-ssh-skip-two] )); then 59 | FAST_HIGHLIGHT[chroma-ssh-skip-two]=0 60 | else 61 | # Count non-option tokens. 62 | (( FAST_HIGHLIGHT[chroma-ssh-counter] += 1 )) 63 | if [[ "${FAST_HIGHLIGHT[chroma-ssh-counter]}" -eq 1 ]]; then 64 | if [[ $__arg = (#b)(([^@]#)(@)|)(*) ]] 65 | then 66 | [[ -n $match[2] ]] \ 67 | && { 68 | user_style= 69 | () { 70 | # Zstyle clobbers reply for sure 71 | zstyle -a ":completion:*:users" users completions_users 72 | } 73 | if (( $#completions_users )); then 74 | [[ $match[2] = ${~${:-(${(j:|:)completions_users})}} ]] \ 75 | && user_style=${FAST_THEME_NAME}correct-subtle \ 76 | || user_style=${FAST_THEME_NAME}incorrect-subtle 77 | elif (( $#userdirs )); then 78 | [[ -n $userdirs[$match[2]] ]] \ 79 | && user_style=${FAST_THEME_NAME}correct-subtle \ 80 | || user_style=${FAST_THEME_NAME}incorrect-subtle 81 | fi 82 | [[ -n $user_style ]] \ 83 | && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}-(mend[5]-mend[2]), __start >= 0 )) \ 84 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$user_style]}") 85 | } 86 | [[ -n $match[3] ]] \ 87 | && (( __start=__start_pos-${#PREBUFFER}+(mbegin[3]-mbegin[1]), __end=__end_pos-${#PREBUFFER}-(mend[5]-mend[3]), __start >= 0 )) \ 88 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subtle-separator]}") 89 | 90 | host_style= 91 | case $match[4] in 92 | (<->|<0-255>.<0-255>.<0-255>.<0-255>) 93 | host_style=${FAST_THEME_NAME}mathnum 94 | check_port=1 95 | ;; 96 | (([0-9a-fA-F][0-9a-fA-F:]#|)::([0-9a-fA-F:]#[0-9a-fA-F]|)|[0-9a-fA-F]##:[0-9a-fA-F:]#[0-9a-fA-F]) 97 | host_style=${FAST_THEME_NAME}mathnum 98 | ;; 99 | (*) 100 | check_port=1 101 | ;; 102 | esac 103 | possible_host=$match[4] 104 | (( host_start_offset = mbegin[4] - mbegin[1], host_end_offset = 0 )) 105 | 106 | if (( check_port )) && [[ $possible_host = (#b)(*)(:[0-9]##) ]]; then 107 | (( __start=__start_pos-${#PREBUFFER}+(host_start_offset+mbegin[2]-mbegin[1]), __end=__end_pos-host_end_offset-${#PREBUFFER}, __start >= 0, 108 | host_end_offset+=mend[2]-mend[1] )) \ 109 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") \ 110 | && possible_host=$match[1] \ 111 | && FAST_HIGHLIGHT[chroma-ssh-message]+="Format of hostname incorrect, use -p to pass port number" 112 | 113 | fi 114 | 115 | if [[ -z $host_style ]]; then 116 | () { 117 | # Zstyle clobbers reply for sure 118 | local mbegin mend match reply 119 | zstyle -a ":completion:*:hosts" hosts completions_host 120 | } 121 | (( ! $#completions_host && $+_cache_hosts )) && completions_host=($_cache_hosts[*]) 122 | if (( $#completions_host )); then 123 | [[ $possible_host = ${~${:-(${(j:|:)completions_host})}} ]] \ 124 | && host_style=${FAST_THEME_NAME}correct-subtle \ 125 | || host_style=${FAST_THEME_NAME}incorrect-subtle 126 | fi 127 | fi 128 | 129 | [[ -n $host_style ]] \ 130 | && (( __start=__start_pos-${#PREBUFFER}+host_start_offset, __end=__end_pos-${#PREBUFFER}-host_end_offset, __start >= 0 )) \ 131 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$host_style]}") 132 | else 133 | __style=${FAST_THEME_NAME}incorrect-subtle 134 | fi 135 | 136 | (( next_word = 1 )) 137 | 138 | fi 139 | fi 140 | fi 141 | 142 | if (( ${#${(z)BUFFER}} <= FAST_HIGHLIGHT[chroma-ssh-counter-all] )); then 143 | [[ -n "${FAST_HIGHLIGHT[chroma-ssh-message]}" ]] && zle -M "${FAST_HIGHLIGHT[chroma-ssh-message]}" 144 | fi 145 | } 146 | 147 | # Add region_highlight entry (via `reply' array). 148 | # 149 | # This is a common place of adding such entry, but any above code 150 | # can do it itself and skip setting __style to disable this code. 151 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 152 | 153 | # We aren't passing-through (no return 1 occured), do obligatory things ourselves. 154 | (( this_word = next_word )) 155 | _start_pos=$_end_pos 156 | 157 | return 0 158 | 159 | # vim:ft=zsh:et:sw=4 160 | -------------------------------------------------------------------------------- /→chroma/-subcommand.ch: -------------------------------------------------------------------------------- 1 | # vim:ft=zsh:et:sw=4 2 | (( next_word = 2 | 8192 )) 3 | [[ "$__arg_type" = 3 ]] && return 2 4 | 5 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 6 | 7 | if (( __first_call )); then 8 | FAST_HIGHLIGHT[chroma-subcommand]="" 9 | return 1 10 | elif (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 11 | return 1 12 | elif [[ "$2" = -* ]]; then 13 | return 1 14 | elif [[ -z "${FAST_HIGHLIGHT[chroma-subcommand]}" ]]; then 15 | FAST_HIGHLIGHT[chroma-subcommand]="$__wrd" 16 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 17 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}") 18 | else 19 | return 1 20 | fi 21 | 22 | (( this_word = next_word )) 23 | _start_pos=$_end_pos 24 | 25 | return 0 26 | -------------------------------------------------------------------------------- /→chroma/-subversion.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # ------------------------------------------------------------------------------------------------- 3 | # Copyright (c) 2018 Sebastian Gniazdowski 4 | # Copyright (C) 2019 by Philippe Troin (F-i-f on GitHub) 5 | # All rights reserved. 6 | # 7 | # The only licensing for this file follows. 8 | # 9 | # Redistribution and use in source and binary forms, with or without modification, are permitted 10 | # provided that the following conditions are met: 11 | # 12 | # * Redistributions of source code must retain the above copyright notice, this list of conditions 13 | # and the following disclaimer. 14 | # * Redistributions in binary form must reproduce the above copyright notice, this list of 15 | # conditions and the following disclaimer in the documentation and/or other materials provided 16 | # with the distribution. 17 | # * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors 18 | # may be used to endorse or promote products derived from this software without specific prior 19 | # written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 22 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 23 | # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 24 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 27 | # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 28 | # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | # ------------------------------------------------------------------------------------------------- 30 | 31 | →chroma/-subversion.ch/parse-revision() { 32 | setopt local_options extendedglob warn_create_global typeset_silent 33 | local __wrd="$1" __start_pos="$2" __end_pos="$3" __style __start __end 34 | case $__wrd in 35 | (r|)[0-9]##) __style=${FAST_THEME_NAME}mathnum ;; 36 | (HEAD|BASE|COMITTED|PREV)) __style=${FAST_THEME_NAME}correct-subtle ;; 37 | '{'[^}]##'}') __style=${FAST_THEME_NAME}subtle-bg ;; 38 | *) __style=${FAST_THEME_NAME}incorrect-subtle ;; 39 | esac 40 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 41 | } 42 | 43 | →chroma/-subversion.ch/parse-target() { 44 | setopt local_options extendedglob warn_create_global typeset_silent 45 | local __wrd="$1" __start_pos="$2" __end_pos="$3" __style __start __end 46 | if [[ $__wrd == *@[^/]# ]] 47 | then 48 | local place=${__wrd%@[^/]#} 49 | local rev=$__wrd[$(($#place+2)),$#__wrd] 50 | if [[ -e $place ]]; then 51 | local __style 52 | [[ -d $place ]] && __style="${FAST_THEME_NAME}path-to-dir" || __style="${FAST_THEME_NAME}path" 53 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}-$#rev-1, __start >= 0 )) \ 54 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 55 | fi 56 | (( __start=__start_pos-${#PREBUFFER}+$#place, __end=__end_pos-${#PREBUFFER}-$#rev, __start >= 0 )) \ 57 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}for-loop-separator]}") 58 | →chroma/-subversion.ch/parse-revision $rev $((__start_pos+$#place+1)) $__end_pos 59 | else 60 | return 1 61 | fi 62 | } 63 | 64 | setopt local_options extendedglob warn_create_global 65 | 66 | # Keep chroma-takever state meaning: until ;, handle highlighting via chroma. 67 | # So the below 8192 assignment takes care that next token will be routed to chroma. 68 | (( next_word = 2 | 8192 )) 69 | 70 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 71 | local __style 72 | integer __idx1 __idx2 73 | 74 | (( __first_call )) && { 75 | # Called for the first time - new command. 76 | # FAST_HIGHLIGHT is used because it survives between calls, and 77 | # allows to use a single global hash only, instead of multiple 78 | # global string variables. 79 | FAST_HIGHLIGHT[subversion-command]=$__wrd 80 | FAST_HIGHLIGHT[subversion-option-argument]= 81 | FAST_HIGHLIGHT[subversion-subcommand]= 82 | FAST_HIGHLIGHT[subversion-subcommand-arguments]=0 83 | 84 | # Set style for region_highlight entry. It is used below in 85 | # '[[ -n "$__style" ]] ...' line, which adds highlight entry, 86 | # like "10 12 fg=green", through `reply' array. 87 | # 88 | # Could check if command `example' exists and set `unknown-token' 89 | # style instead of `command' 90 | __style=${FAST_THEME_NAME}command 91 | 92 | } || { 93 | # Following call, i.e. not the first one 94 | 95 | # Check if chroma should end – test if token is of type 96 | # "starts new command", if so pass-through – chroma ends 97 | [[ "$__arg_type" = 3 ]] && return 2 98 | 99 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 100 | return 1 101 | fi 102 | 103 | if [[ "$__wrd" = -* ]]; then 104 | # Detected option, add style for it. 105 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 106 | __style=${FAST_THEME_NAME}single-hyphen-option 107 | case $FAST_HIGHLIGHT[subversion-command]/$FAST_HIGHLIGHT[subversion-subcommand] in 108 | svn/) 109 | case $__wrd in 110 | --username|-u) FAST_HIGHLIGHT[subversion-option-argument]=any;; 111 | --password|-p) FAST_HIGHLIGHT[subversion-option-argument]=any;; 112 | --config-(dir|option)) FAST_HIGHLIGHT[subversion-option-argument]=any;; 113 | esac 114 | ;; 115 | svn/?*) 116 | case $__wrd in 117 | --accept) FAST_HIGHLIGHT[subversion-option-argument]=accept;; 118 | --change|-c) FAST_HIGHLIGHT[subversion-option-argument]=revision;; 119 | --changelist|--cl) FAST_HIGHLIGHT[subversion-option-argument]=any;; 120 | --(set-|)depth) FAST_HIGHLIGHT[subversion-option-argument]=depth;; 121 | --diff(3|)-cmd) FAST_HIGHLIGHT[subversion-option-argument]=cmd;; 122 | --editor-cmd) FAST_HIGHLIGHT[subversion-option-argument]=cmd;; 123 | --encoding) FAST_HIGHLIGHT[subversion-option-argument]=any;; 124 | --file) FAST_HIGHLIGHT[subversion-option-argument]=any;; 125 | --limit|-l) FAST_HIGHLIGHT[subversion-option-argument]=number;; 126 | --message|-m) FAST_HIGHLIGHT[subversion-option-argument]=any;; 127 | --native-eol) FAST_HIGHLIGHT[subversion-option-argument]=eol;; 128 | --new|--old) FAST_HIGHLIGHT[subversion-option-argument]=target;; 129 | --revision|-r) FAST_HIGHLIGHT[subversion-option-argument]=revision-pair;; 130 | --show-revs) FAST_HIGHLIGHT[subversion-option-argument]=show-revs;; 131 | --strip) FAST_HIGHLIGHT[subversion-option-argument]=number;; 132 | --with-revprop) FAST_HIGHLIGHT[subversion-option-argument]=revprop;; 133 | esac 134 | ;; 135 | svnadmin/*) 136 | case $__wrd in 137 | --config-dir) FAST_HIGHLIGHT[subversion-option-argument]=any;; 138 | --fs-type) FAST_HIGHLIGHT[subversion-option-argument]=any;; 139 | --memory-cache-size|-M) FAST_HIGHLIGHT[subversion-option-argument]=number;; 140 | --parent-dir) FAST_HIGHLIGHT[subversion-option-argument]=any;; 141 | --revision|-r) FAST_HIGHLIGHT[subversion-option-argument]=revision-pair;; 142 | esac 143 | ;; 144 | svndumpfilter/*) 145 | case $__wrd in 146 | --targets) FAST_HIGHLIGHT[subversion-option-argument]=any;; 147 | esac 148 | ;; 149 | esac 150 | elif [[ -n $FAST_HIGHLIGHT[subversion-option-argument] ]]; then 151 | case $FAST_HIGHLIGHT[subversion-option-argument] in 152 | any) 153 | FAST_HIGHLIGHT[subversion-option-argument]= 154 | return 1 155 | ;; 156 | accept) 157 | [[ $__wrd = (p(|ostpone)|e(|dit)|l(|aunch)|base|working|recommended|[mt][cf]|(mine|theirs)-(conflict|full)) ]] \ 158 | && __style=${FAST_THEME_NAME}correct-subtle \ 159 | || __style=${FAST_THEME_NAME}incorrect-subtle 160 | ;; 161 | depth) 162 | [[ $__wrd = (empty|files|immediates|infinity) ]] \ 163 | && __style=${FAST_THEME_NAME}correct-subtle \ 164 | || __style=${FAST_THEME_NAME}incorrect-subtle 165 | ;; 166 | number) 167 | [[ $__wrd = [0-9]## ]] \ 168 | && __style=${FAST_THEME_NAME}mathnum \ 169 | || __style=${FAST_THEME_NAME}incorrect-subtle 170 | ;; 171 | eol) 172 | [[ $__wrd = (CR(|LF)|LF) ]] \ 173 | && __style=${FAST_THEME_NAME}correct-subtle \ 174 | || __style=${FAST_THEME_NAME}incorrect-subtle 175 | ;; 176 | show-revs) 177 | [[ $__wrd = (merged|eligible) ]] \ 178 | && __style=${FAST_THEME_NAME}correct-subtle \ 179 | || __style=${FAST_THEME_NAME}incorrect-subtle 180 | ;; 181 | revision) 182 | →chroma/-subversion.ch/parse-revision $__wrd $__start_pos $__end_pos 183 | ;; 184 | revision-pair) 185 | local -a match mbegin mend 186 | if [[ $__wrd = (#b)(\{[^}]##\}|[^:]##)(:)(*) ]]; then 187 | →chroma/-subversion.ch/parse-revision $match[1] $__start_pos $(( __end_pos - ( mend[3]-mend[2] ) - 1 )) 188 | →chroma/-subversion.ch/parse-revision $match[3] $(( __start_pos + ( mbegin[3]-mbegin[1] ) )) $__end_pos 189 | (( __start=__start_pos-${#PREBUFFER}+(mbegin[2]-mbegin[1]), __end=__end_pos-${#PREBUFFER}-(mend[3]-mend[2]), __start >= 0 )) \ 190 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}for-loop-separator]}") 191 | else 192 | →chroma/-subversion.ch/parse-revision $__wrd $__start_pos $__end_pos 193 | fi 194 | ;; 195 | target) 196 | →chroma/-subversion.ch/parse-target $__wrd $__start_pos $__end_pos || return $? 197 | ;; 198 | cmd) 199 | this_word=1 200 | return 1 201 | ;; 202 | esac 203 | FAST_HIGHLIGHT[subversion-option-argument]= 204 | elif [[ -z $FAST_HIGHLIGHT[subversion-subcommand] ]] 205 | then 206 | FAST_HIGHLIGHT[subversion-subcommand]=$__wrd 207 | local subcmds 208 | case $FAST_HIGHLIGHT[subversion-command] in 209 | svn) subcmds='(add|auth|blame|praise|annotate|ann|cat|changelist|cl|checkout|co|cleanup|commit|ci|copy|cp|delete|del|remove|rm|diff|di|export|help|\?|h|import|info|list|ls|lock|log|merge|mergeinfo|mkdir|move|mv|rename|ren|patch|propdel|pdel|pd|propedit|pedit|pe|propget|pget|pg|proplist|plist|pl|propset|pset|ps|relocate|resolve|resolved|revert|status|stat|st|switch|sw|unlock|update|up|upgrade|x-shelf-diff|x-shelf-drop|x-shelf-list|x-shelves|x-shelf-list-by-paths|x-shelf-log|x-shelf-save|x-shelve|x-unshelve)' ;; 210 | svnadmin) subcmds="(crashtest|create|delrevprop|deltify|dump|dump-revprops|freeze|help|\?|h|hotcopy|info|list-dblogs|list-unused-dblogs|load|load-revprops|lock|lslocks|lstxns|pack|recover|rmlocks|rmtxns|setlog|setrevprop|setuuid|unlock|upgrade|verify)";; 211 | svndumpfilter) subcmds='(include|exclude|help|\?)';; 212 | esac 213 | [[ $FAST_HIGHLIGHT[subversion-subcommand] = $~subcmds ]] \ 214 | && __style=${FAST_THEME_NAME}subcommand \ 215 | || __style=${FAST_THEME_NAME}incorrect-subtle 216 | FAST_HIGHLIGHT[subversion-subcommand-arguments]=0 217 | else 218 | (( FAST_HIGHLIGHT[subversion-subcommand-arguments]+=1 )) 219 | if [[ ( $FAST_HIGHLIGHT[subversion-subcommand] == (checkout|co|export|log|merge|switch|sw) && $FAST_HIGHLIGHT[subversion-subcommand-arguments] -eq 1 ) \ 220 | || $FAST_HIGHLIGHT[subversion-subcommand] == (blame|praise|annotate|ann|cat|copy|cp|diff|info|list|ls|mergeinfo) ]]; then 221 | →chroma/-subversion.ch/parse-target $__wrd $__start_pos $__end_pos || return $? 222 | else 223 | return 1 224 | fi 225 | fi 226 | } 227 | 228 | # Add region_highlight entry (via `reply' array). 229 | # If 1 will be added to __start_pos, this will highlight "oken". 230 | # If 1 will be subtracted from __end_pos, this will highlight "toke". 231 | # $PREBUFFER is for specific situations when users does command \ 232 | # i.e. when multi-line command using backslash is entered. 233 | # 234 | # This is a common place of adding such entry, but any above code can do 235 | # it itself (and it does in other chromas) and skip setting __style to 236 | # this way disable this code. 237 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 238 | 239 | # We aren't passing-through, do obligatory things ourselves. 240 | # _start_pos=$_end_pos advainces pointers in command line buffer. 241 | # 242 | # To pass through means to `return 1'. The highlighting of 243 | # this single token is then done by fast-syntax-highlighting's 244 | # main code and chroma doesn't have to do anything. 245 | (( this_word = next_word )) 246 | _start_pos=$_end_pos 247 | 248 | return 0 249 | 250 | # vim:ft=zsh:et:sw=4 251 | -------------------------------------------------------------------------------- /→chroma/-vim.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # Chroma for vim, shows last opened files under prompt. 5 | # 6 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 7 | # 8 | # $2 - the current token, also accessible by $__arg from the above scope - 9 | # basically a private copy of $__arg; the token can be eg.: "grep" 10 | # 11 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 12 | # command line buffer, used to add region_highlight entry (see man), 13 | # because Zsh colorizes by *ranges* in command line buffer 14 | # 15 | # $4 - a private copy of $_end_pos from the above scope 16 | # 17 | 18 | (( next_word = 2 | 8192 )) 19 | 20 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 21 | local __style __chars 22 | integer __idx1 __idx2 23 | local -a __viminfo 24 | 25 | # First call, i.e. command starts, i.e. "grep" token etc. 26 | (( __first_call )) && { 27 | (( ${+commands[vim]} )) && __style=${FAST_THEME_NAME}command || __style=${FAST_THEME_NAME}unknown-token 28 | 29 | { __viminfo=( ${(f)"$(<$HOME/.viminfo)"} ); } >> /dev/null 30 | __viminfo=( "${${(M)__viminfo[@]:#>*}[@]:t}" ) 31 | __viminfo=( "${__viminfo[@]:#COMMIT_EDITMSG}" ) 32 | zle -M "Last opened:"$'\n'"${(F)__viminfo[1,5]}" 33 | } || { 34 | # Pass almost everything to big loop 35 | return 1 36 | } 37 | 38 | # Add region_highlight entry (via `reply' array). 39 | # 40 | # This is a common place of adding such entry, but any above 41 | # code can do it itself (and it does, see other chromas) and 42 | # skip setting __style to disable this code. 43 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 44 | 45 | # We aren't passing-through (no return 1 occured), do obligatory things ourselves. 46 | (( this_word = next_word )) 47 | _start_pos=$_end_pos 48 | 49 | return 0 50 | 51 | # vim:ft=zsh:et:sw=4 52 | -------------------------------------------------------------------------------- /→chroma/-whatis.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018-2019 Sebastian Gniazdowski 3 | 4 | (( next_word = 2 | 8192 )) 5 | local THEFD check __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 6 | local __style __term __section __section_flag 7 | 8 | # extact manual subsection 9 | # NOTE: __term should be separated from __wrd to prevent incorrect cache hits 10 | if command -v mandb > /dev/null; then 11 | __term="${__wrd%.[0-8n](|p|type|const|head|perl)}" 12 | __section="${${2#$__term}#.}" 13 | else 14 | __term=$__wrd 15 | fi 16 | 17 | [[ -n $__section ]] && __section_flag="-s $__section" 18 | 19 | (( ! ${+FAST_HIGHLIGHT[whatis_chroma_callback_was_ran]} )) && \ 20 | FAST_HIGHLIGHT[whatis_chroma_callback_was_ran]=0 21 | 22 | (( ! ${+FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]} )) && { 23 | is-at-least 5.0.6 && local __res=1 || local __res=0 24 | FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]="$__res" 25 | } 26 | 27 | -fast-whatis-chroma-callback() { 28 | emulate -L zsh 29 | setopt extendedglob warncreateglobal typesetsilent 30 | 31 | local THEFD="$1" input check=2 nl=$'\n' __wrd __style 32 | 33 | .fast-zts-read-all "$THEFD" input 34 | 35 | zle -F "$THEFD" 36 | exec {THEFD}<&- 37 | 38 | __wrd="${${input#[^$nl]#$nl}%%$nl*}" 39 | if [[ "$input" = test* ]]; then 40 | if [[ "${input%$nl}" = *[^0-9]'0' ]]; then 41 | if [[ "${input#test$nl}" = *nothing\ appropriate* ]]; then 42 | FAST_HIGHLIGHT[whatis_chroma_type]=2 43 | else 44 | FAST_HIGHLIGHT[whatis_chroma_type]=0 45 | fi 46 | else 47 | FAST_HIGHLIGHT[whatis_chroma_type]=1 48 | fi 49 | elif [[ "$input" = type2* ]]; then 50 | [[ "$input" != *nothing\ appropriate* ]] && check=1 || check=0 51 | elif [[ "$input" = type1* ]]; then 52 | [[ "${input%$nl}" = *0 ]] && check=1 || check=0 53 | fi 54 | 55 | if (( check != 2 )); then 56 | FAST_HIGHLIGHT[whatis-cache-$__wrd]=$check 57 | if (( check )) then 58 | __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]} 59 | elif [[ ${~__wrd} = */* && -e ${~__wrd} ]] then 60 | __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]} 61 | else 62 | __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]} 63 | fi 64 | local -a start_end 65 | start_end=( ${(s:/:)${${(M)${${input#type?${nl}[^$nl]#$nl}}#*$nl}%$nl}} ) 66 | (( start_end[1] >= 0 )) && region_highlight+=("$start_end[1] $start_end[2] $__style") 67 | zle -R 68 | fi 69 | 70 | FAST_HIGHLIGHT[whatis_chroma_callback_was_ran]=1 71 | return 0 72 | } 73 | 74 | zle -N -- -fast-whatis-chroma-callback 75 | 76 | if (( __first_call )) && [[ -z "${FAST_HIGHLIGHT[whatis_chroma_type]}" ]] ;then 77 | if ! command -v whatis > /dev/null; then 78 | FAST_HIGHLIGHT[whatis_chroma_type]=0 79 | return 1 80 | fi 81 | 82 | exec {THEFD}< <( 83 | print "test" 84 | LANG=C whatis "osx whatis fallback check" 85 | print "$?" 86 | ) 87 | command true # a workaround of Zsh bug 88 | zle -F ${${FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]:#0}:+-w} "$THEFD" -fast-whatis-chroma-callback 89 | fi 90 | 91 | [[ "$__arg_type" = 3 ]] && return 2 92 | 93 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 94 | return 1 95 | fi 96 | 97 | if (( __first_call )) || [[ "$__wrd" = -* ]]; then 98 | return 1 99 | elif (( ! FAST_HIGHLIGHT[whatis_chroma_type] )); then 100 | # Return 1 (i.e. treat the argument as a path) only if the callback have 101 | # had a chance to establish the whatis_chroma_type field 102 | (( FAST_HIGHLIGHT[whatis_chroma_callback_was_ran] )) && return 1 103 | else 104 | if [[ -z "${FAST_HIGHLIGHT[whatis-cache-$__wrd]}" ]]; then 105 | if (( FAST_HIGHLIGHT[whatis_chroma_type] == 2 )); then 106 | exec {THEFD}< <( 107 | print "type2" 108 | print "$__wrd" 109 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER} )) 110 | print "$__start/$__end" 111 | LANG=C whatis "${(z)__section_flag}" "$__term" 2>/dev/null 112 | ) 113 | command true # see above 114 | zle -F ${${FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]:#0}:+-w} "$THEFD" -fast-whatis-chroma-callback 115 | else 116 | exec {THEFD}< <( 117 | print "type1" 118 | print "$__wrd" 119 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER} )) 120 | print "$__start/$__end" 121 | LANG=C whatis "${(z)__section_flag}" "$__term" &> /dev/null 122 | print "$?" 123 | ) 124 | command true 125 | zle -F ${${FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]:#0}:+-w} "$THEFD" -fast-whatis-chroma-callback 126 | fi 127 | __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]} 128 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \ 129 | reply+=("$__start $__end $__style") 130 | else 131 | check=${FAST_HIGHLIGHT[whatis-cache-$__wrd]} 132 | if (( check )) then 133 | __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]} 134 | elif [[ ${~__wrd} = */* && -e ${~__wrd} ]] then 135 | __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]} 136 | elif (( FAST_HIGHLIGHT[whatis_chroma_type] )); then 137 | __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]} 138 | fi 139 | [[ -n "$__style" ]] && \ 140 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \ 141 | reply+=("$__start $__end $__style") 142 | fi 143 | fi 144 | (( this_word = next_word )) 145 | _start_pos=$_end_pos 146 | 147 | return 0 148 | 149 | # vim:ft=zsh:et:sw=4:sts=4 150 | -------------------------------------------------------------------------------- /→chroma/-which.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018 Sebastian Gniazdowski 3 | # 4 | # Outputs (under prompt) result of query done with `which', `type -w', 5 | # `whence -v', `whereis', `whatis'. 6 | # 7 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 8 | # 9 | # $2 - the current token, also accessible by $__arg from the above scope - 10 | # basically a private copy of $__arg; the token can be eg.: "grep" 11 | # 12 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 13 | # command line buffer, used to add region_highlight entry (see man), 14 | # because Zsh colorizes by *ranges* in command line buffer 15 | # 16 | # $4 - a private copy of $_end_pos from the above scope 17 | # 18 | 19 | (( next_word = 2 | 8192 )) 20 | 21 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 22 | local __style __output __chars 23 | integer __idx1 __idx2 24 | local -a __results 25 | 26 | # First call, i.e. command starts, i.e. "grep" token etc. 27 | (( __first_call )) && { 28 | FAST_HIGHLIGHT[chroma-which-counter]=0 29 | FAST_HIGHLIGHT[chroma-which-counter-all]=1 30 | FAST_HIGHLIGHT[chroma-which-message]="" 31 | FAST_HIGHLIGHT[chroma-which-skip-two]=0 32 | __style=${FAST_THEME_NAME}command 33 | __output="" 34 | 35 | # Following call (not first one). 36 | } || { 37 | (( FAST_HIGHLIGHT[chroma-which-counter-all] += 1, __idx2 = FAST_HIGHLIGHT[chroma-which-counter-all] )) 38 | 39 | # Check if chroma should end – test if token is of type 40 | # "starts new command", if so pass-through – chroma ends 41 | [[ "$__arg_type" = 3 ]] && return 2 42 | 43 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 44 | return 1 45 | fi 46 | 47 | if [[ "$__wrd" = -* ]]; then 48 | # Detected option, add style for it. 49 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 50 | __style=${FAST_THEME_NAME}single-hyphen-option 51 | if [[ "$__wrd" = "-x" ]]; then 52 | FAST_HIGHLIGHT[chroma-which-skip-two]=1 53 | fi 54 | else 55 | # Count non-option tokens. 56 | if (( FAST_HIGHLIGHT[chroma-which-skip-two] )); then 57 | FAST_HIGHLIGHT[chroma-which-skip-two]=0 58 | else 59 | (( FAST_HIGHLIGHT[chroma-which-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-which-counter] )) 60 | if [[ "$__idx1" -eq 1 ]]; then 61 | __chars="{" 62 | __output="$(command which "$__wrd" 2>/dev/null)" 63 | FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"command which: $__output" 64 | __output="$(builtin which "$__wrd" 2>/dev/null)" 65 | FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"builtin which: ${${${${__output[1,100]}//$'\n'/;}//$'\t'/ }//$__chars;/$__chars}${__output[101,101]:+...}" 66 | __output="$(builtin type -w "$__wrd" 2>/dev/null)" 67 | FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"type -w: $__output" 68 | __output="$(builtin whence -v "$__wrd" 2>/dev/null)" 69 | FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"whence -v: $__output" 70 | __output="$(command whereis "$__wrd" 2>/dev/null)" 71 | FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"whereis: $__output" 72 | __output="$(command whatis "$__wrd" 2>/dev/null)" 73 | __output="${${__output%%$'\n'*}//[[:blank:]]##/ }" 74 | FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"whatis: $__output" 75 | fi 76 | fi 77 | fi 78 | 79 | if (( ${#${(z)BUFFER}} <= FAST_HIGHLIGHT[chroma-which-counter-all] )); then 80 | [[ -n "${FAST_HIGHLIGHT[chroma-which-message]}" ]] && zle -M "${FAST_HIGHLIGHT[chroma-which-message]#$'\n'}" 81 | fi 82 | } 83 | 84 | # Add region_highlight entry (via `reply' array). 85 | # 86 | # This is a common place of adding such entry, but any above code 87 | # can do it itself and skip setting __style to disable this code. 88 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 89 | 90 | # We aren't passing-through (no return 1 occured), do obligatory things ourselves. 91 | (( this_word = next_word )) 92 | _start_pos=$_end_pos 93 | 94 | return 0 95 | 96 | # vim:ft=zsh:et:sw=4 97 | -------------------------------------------------------------------------------- /→chroma/-zinit.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 2 | # Copyright (c) 2018-2019 Sebastian Gniazdowski 3 | # 4 | # Chroma function for command `git'. It colorizes the part of command 5 | # line that holds `git' invocation. 6 | 7 | (( FAST_HIGHLIGHT[-zinit.ch-chroma-def] )) && return 1 8 | 9 | FAST_HIGHLIGHT[-zinit.ch-chroma-def]=1 10 | 11 | typeset -gA fsh__zinit__chroma__def 12 | fsh__zinit__chroma__def=( 13 | ## 14 | ## No subcommand 15 | ## 16 | ## {{{ 17 | 18 | subcmd:NULL "NULL_0_opt" 19 | NULL_0_opt "(-help|--help|-h) 20 | <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action" 21 | 22 | "subcommands" "(help|man|self-update|cd|times|zstatus|load|light|unload|snippet|ls|ice||update|status|report|delete|loaded|list|cd|create|edit|glance|stress|changes|recently|clist|completions|cdisable|cname|cenable|cname|creinstall|cuninstall|csearch|compinit|dtrace|dstart|dstop|dunload|dreport|dclear|compile|uncompile|compiled|cdlist|cdreplay|cdclear|srv|recall|env-whitelist|bindkeys|module)" 23 | 24 | ## }}} 25 | 26 | # Generic actions 27 | NO_MATCH_\#_opt "* <<>> __style=\${FAST_THEME_NAME}incorrect-subtle // NO-OP" 28 | NO_MATCH_\#_arg "__style=\${FAST_THEME_NAME}incorrect-subtle // NO-OP" 29 | 30 | 31 | ## 32 | ## `ice' 33 | ## 34 | ## {{{ 35 | 36 | subcmd:ice "ICE_#_arg // NO_MATCH_#_opt" 37 | 38 | "ICE_#_arg" "NO-OP // ::→chroma/-zinit-check-ice-mod" 39 | 40 | ## }}} 41 | 42 | ## 43 | ## `snippet' 44 | ## 45 | ## {{{ 46 | 47 | subcmd:snippet "SNIPPET_0_opt // SNIPPET_1_arg // NO_MATCH_#_opt // 48 | NO_MATCH_#_arg" 49 | 50 | SNIPPET_0_opt "(-f|--command) 51 | <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action" 52 | 53 | SNIPPET_1_arg "NO-OP // ::→chroma/-zinit-verify-snippet" 54 | 55 | ## }}} 56 | 57 | ## 58 | ## `load' 59 | ## 60 | ## {{{ 61 | 62 | "subcmd:load" 63 | "LOAD_1_arg // LOAD_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 64 | 65 | LOAD_1_arg "NO-OP // ::→chroma/-zinit-verify-plugin" 66 | 67 | LOAD_2_arg "NO-OP // ::→chroma/-zinit-verify-plugin" 68 | 69 | ## }}} 70 | 71 | ## 72 | ## `compile|uncompile|stress|edit|glance|recall|status|cd|changes` 73 | ## 74 | ## {{{ 75 | 76 | "subcmd:(compile|uncompile|stress|edit|glance|recall|status|cd|changes)" 77 | "PLGSNP_1_arg // PLGSNP_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 78 | 79 | PLGSNP_1_arg "NO-OP // ::→chroma/-zinit-verify-plugin-or-snippet" 80 | 81 | PLGSNP_2_arg "NO-OP // ::→chroma/-zinit-verify-plugin-or-snippet" 82 | 83 | ## }}} 84 | 85 | ## 86 | ## `update' 87 | ## 88 | ## {{{ 89 | 90 | subcmd:update "UPDATE_0_opt // PLGSNP_1_arg // PLGSNP_2_arg // 91 | NO_MATCH_#_opt // NO_MATCH_#_arg" 92 | 93 | UPDATE_0_opt " 94 | (--all|-r|--reset|-q|--quiet|-p|--parallel) 95 | <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action" 96 | 97 | ## }}} 98 | 99 | ## 100 | ## `light' 101 | ## 102 | ## {{{ 103 | 104 | subcmd:light "LIGHT_0_opt // LOAD_1_arg // LOAD_2_arg // NO_MATCH_#_opt // 105 | NO_MATCH_#_arg" 106 | 107 | LIGHT_0_opt "-b 108 | <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action" 109 | 110 | ## }}} 111 | 112 | ## 113 | ## `unload' 114 | ## 115 | ## {{{ 116 | 117 | subcmd:unload "UNLOAD_0_opt // UNLOAD_1_arg // UNLOAD_2_arg // NO_MATCH_#_opt // 118 | NO_MATCH_#_arg" 119 | 120 | UNLOAD_0_opt "-q 121 | <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action" 122 | 123 | UNLOAD_1_arg "NO-OP // ::→chroma/-zinit-verify-loaded-plugin" 124 | 125 | UNLOAD_2_arg "NO-OP // ::→chroma/-zinit-verify-loaded-plugin" 126 | 127 | ## }}} 128 | 129 | ## 130 | ## `report' 131 | ## 132 | ## {{{ 133 | 134 | subcmd:report "REPORT_0_opt // UNLOAD_1_arg // UNLOAD_2_arg // NO_MATCH_#_opt // 135 | NO_MATCH_#_arg" 136 | 137 | REPORT_0_opt "--all 138 | <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action" 139 | 140 | ## }}} 141 | 142 | ## 143 | ## `delete' 144 | ## 145 | ## {{{ 146 | 147 | "subcmd:delete" 148 | "DELETE_0_opt // PLGSNP_1_arg // PLGSNP_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 149 | 150 | DELETE_0_opt " 151 | (--all|--clean|-y|--yes|-q|--quiet) 152 | <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action" 153 | 154 | ## }}} 155 | 156 | ## 157 | ## `cenable' 158 | ## 159 | ## {{{ 160 | 161 | subcmd:cenable "COMPLETION_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 162 | 163 | COMPLETION_1_arg "NO-OP // ::→chroma/-zinit-verify-disabled-completion" 164 | 165 | ## }}} 166 | 167 | ## 168 | ## `cdisable' 169 | ## 170 | ## {{{ 171 | 172 | subcmd:cdisable "DISCOMPLETION_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 173 | 174 | DISCOMPLETION_1_arg "NO-OP // ::→chroma/-zinit-verify-completion" 175 | 176 | ## }}} 177 | 178 | 179 | ## 180 | ## `light' 181 | ## 182 | ## {{{ 183 | 184 | subcmd:uncompile "UNCOMPILE_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 185 | 186 | UNCOMPILE_1_arg "NO-OP // ::→chroma/-zinit-verify-compiled-plugin" 187 | 188 | ## }}} 189 | 190 | ## 191 | ## `*' 192 | ## 193 | ## {{{ 194 | 195 | "subcmd:*" "CATCH_ALL_#_opt" 196 | "CATCH_ALL_#_opt" "* <<>> NO-OP // ::→chroma/main-chroma-std-aopt-SEMI-action" 197 | 198 | ## }}} 199 | ) 200 | 201 | #→chroma/-zinit-first-call() { 202 | # This is being done in the proper place - in -fast-highlight-process 203 | #FAST_HIGHLIGHT[chroma-zinit-ice-elements-svn]=0 204 | #} 205 | 206 | →chroma/-zinit-verify-plugin() { 207 | local _scmd="$1" _wrd="$4" 208 | 209 | [[ -d "$_wrd" ]] && \ 210 | { __style=${FAST_THEME_NAME}correct-subtle; return 0; } 211 | 212 | typeset -a plugins 213 | plugins=( "${ZINIT[PLUGINS_DIR]}"/*(N:t) ) 214 | plugins=( "${plugins[@]//---//}" ) 215 | plugins=( "${plugins[@]:#_local/zinit}" ) 216 | plugins=( "${plugins[@]:#custom}" ) 217 | 218 | [[ -n "${plugins[(r)$_wrd]}" ]] && \ 219 | __style=${FAST_THEME_NAME}correct-subtle || \ 220 | return 1 221 | #__style=${FAST_THEME_NAME}incorrect-subtle 222 | return 0 223 | } 224 | 225 | →chroma/-zinit-verify-plugin-or-snippet() { 226 | →chroma/-zinit-verify-plugin "$1" "" "" "$4" || \ 227 | →chroma/-zinit-verify-snippet "$1" "" "" "$4" 228 | return $? 229 | } 230 | 231 | →chroma/-zinit-verify-loaded-plugin() { 232 | local _scmd="$1" _wrd="$4" 233 | typeset -a plugins absolute1 absolute2 absolute3 normal 234 | plugins=( "${ZINIT_REGISTERED_PLUGINS[@]:#_local/zinit}" ) 235 | normal=( "${plugins[@]:#%*}" ) 236 | absolute1=( "${(M)plugins[@]:#%*}" ) 237 | absolute1=( "${absolute1[@]/\%\/\//%/}" ) 238 | local hm="${HOME%/}" 239 | absolute2=( "${absolute1[@]/$hm/HOME}" ) 240 | absolute3=( "${absolute1[@]/\%/}" ) 241 | plugins=( $absolute1 $absolute2 $absolute3 $normal ) 242 | 243 | [[ -n "${plugins[(r)$_wrd]}" ]] && \ 244 | __style=${FAST_THEME_NAME}correct-subtle || \ 245 | return 1 246 | #__style=${FAST_THEME_NAME}incorrect-subtle 247 | 248 | return 0 249 | } 250 | 251 | →chroma/-zinit-verify-completion() { 252 | local _scmd="$1" _wrd="$4" 253 | # Find enabled completions 254 | typeset -a completions 255 | completions=( "${ZINIT[COMPLETIONS_DIR]}"/_*(N:t) ) 256 | completions=( "${completions[@]#_}" ) 257 | 258 | [[ -n "${completions[(r)${_wrd#_}]}" ]] && \ 259 | __style=${FAST_THEME_NAME}correct-subtle || \ 260 | return 1 261 | 262 | return 0 263 | } 264 | 265 | →chroma/-zinit-verify-disabled-completion() { 266 | local _scmd="$1" _wrd="$4" 267 | # Find enabled completions 268 | typeset -a completions 269 | completions=( "${ZINIT[COMPLETIONS_DIR]}"/[^_]*(N:t) ) 270 | 271 | [[ -n "${completions[(r)${_wrd#_}]}" ]] && \ 272 | __style=${FAST_THEME_NAME}correct-subtle || \ 273 | return 1 274 | 275 | return 0 276 | } 277 | 278 | →chroma/-zinit-verify-compiled-plugin() { 279 | local _scmd="$1" _wrd="$4" 280 | 281 | typeset -a plugins 282 | plugins=( "${ZINIT[PLUGINS_DIR]}"/*(N) ) 283 | 284 | typeset -a show_plugins p matches 285 | for p in "${plugins[@]}"; do 286 | matches=( $p/*.zwc(N) ) 287 | if [ "$#matches" -ne "0" ]; then 288 | p="${p:t}" 289 | [[ "$p" = (_local---zinit|custom) ]] && continue 290 | p="${p//---//}" 291 | show_plugins+=( "$p" ) 292 | fi 293 | done 294 | 295 | [[ -n "${show_plugins[(r)$_wrd]}" ]] && \ 296 | { __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \ 297 | return 1 298 | } 299 | 300 | →chroma/-zinit-verify-snippet() { 301 | local _scmd="$1" url="$4" dirname local_dir 302 | url="${${url#"${url%%[! $'\t']*}"}%/}" 303 | id_as="${FAST_HIGHLIGHT[chroma-zinit-ice-elements-id-as]:-${ZINIT_ICE[id-as]:-$url}}" 304 | 305 | filename="${${id_as%%\?*}:t}" 306 | dirname="${${id_as%%\?*}:t}" 307 | local_dir="${${${id_as%%\?*}:h}/:\/\//--}" 308 | [[ "$local_dir" = "." ]] && local_dir="" || local_dir="${${${${${local_dir#/}//\//--}//=/--EQ--}//\?/--QM--}//\&/--AMP--}" 309 | local_dir="${ZINIT[SNIPPETS_DIR]}${local_dir:+/$local_dir}" 310 | 311 | (( ${+ZINIT_ICE[svn]} || ${FAST_HIGHLIGHT[chroma-zinit-ice-elements-svn]} )) && { 312 | # TODO: handle the SVN path's specifics 313 | [[ -d "$local_dir/$dirname" ]] && \ 314 | { __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \ 315 | return 1 316 | } || { 317 | # TODO: handle the non-SVN path's specifics 318 | [[ -d "$local_dir/$dirname" ]] && \ 319 | { __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \ 320 | return 1 321 | } 322 | } 323 | 324 | →chroma/-zinit-check-ice-mod() { 325 | local _scmd="$1" _wrd="$4" 326 | [[ "$_wrd" = (svn(\'|\")*|svn) ]] && \ 327 | FAST_HIGHLIGHT[chroma-zinit-ice-elements-svn]=1 328 | [[ "$_wrd" = (#b)(id-as(:|)(\'|\")(*)(\'|\")|id-as:(*)|id-as(*)) ]] && \ 329 | FAST_HIGHLIGHT[chroma-zinit-ice-elements-id-as]="${match[4]}${match[6]}${match[7]}" 330 | 331 | # Copy from zinit-autoload.zsh / -zplg-recall 332 | local -a ice_order nval_ices ext_val_ices 333 | ext_val_ices=( ${(@)${(@Ms.|.)ZINIT_EXTS[ice-mods]:#*\'\'*}//\'\'/} ) 334 | 335 | ice_order=( 336 | svn proto from teleid bindmap cloneopts id-as depth if wait load 337 | unload blockf pick bpick src as ver silent lucid notify mv cp 338 | atinit atclone atload atpull nocd run-atpull has cloneonly make 339 | service trackbinds multisrc compile nocompile nocompletions 340 | reset-prompt wrap-track reset sh \!sh bash \!bash ksh \!ksh csh 341 | \!csh aliases countdown ps-on-unload ps-on-update trigger-load 342 | light-mode is-snippet atdelete pack git verbose on-update-of 343 | subscribe param extract 344 | # Include all additional ices – after 345 | # stripping them from the possible: '' 346 | ${(@s.|.)${ZINIT_EXTS[ice-mods]//\'\'/}} 347 | ) 348 | nval_ices=( 349 | blockf silent lucid trackbinds cloneonly nocd run-atpull 350 | nocompletions sh \!sh bash \!bash ksh \!ksh csh \!csh 351 | aliases countdown light-mode is-snippet git verbose 352 | 353 | # Include only those additional ices, 354 | # don't have the '' in their name, i.e. 355 | # aren't designed to hold value 356 | ${(@)${(@s.|.)ZINIT_EXTS[ice-mods]}:#*\'\'*} 357 | 358 | # Must be last 359 | svn 360 | ) 361 | 362 | if [[ "$_wrd" = (#b)(${(~j:|:)${ice_order[@]:#(${(~j:|:)nval_ices[@]:#(${(~j:|:)ext_val_ices[@]})})}})(*) ]]; then 363 | reply+=("$(( __start )) $(( __start+${mend[1]} )) ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-hyphen-option]}") 364 | reply+=("$(( __start+${mbegin[2]} )) $(( __end )) ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}optarg-string]}") 365 | -fast-highlight-string 366 | return 0 367 | elif [[ "$_wrd" = (#b)(${(~j:|:)nval_ices[@]}) ]]; then 368 | __style=${FAST_THEME_NAME}single-hyphen-option 369 | return 0 370 | else 371 | __style=${FAST_THEME_NAME}incorrect-subtle 372 | return 1 373 | fi 374 | } 375 | 376 | return 0 377 | 378 | # vim:ft=zsh:et:sw=4 379 | --------------------------------------------------------------------------------