added zsh-server

This commit is contained in:
Christoph J. Scherr 2023-01-07 21:57:26 +01:00
parent 5cb48fa65c
commit 93619f7f3d
273 changed files with 42102 additions and 3 deletions

View File

@ -11,4 +11,4 @@ cp -fr ~/.zsh ./home/
cp -fr ~/.zshrc ./home/
cp -fr ~/.p10k.zsh ./home
cp -fr ~/.gitconfig ./home
cp -fr /usr/share/fzf ./usr/share/fzf
#cp -fr /usr/share/fzf ./usr/share/fzf

View File

@ -1 +1 @@
FF:FF:FF:FF:FF:FF 255.255.255.255
FF:FF:FF:FF:FF:FF 192.168.178.255

View File

@ -0,0 +1,98 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Almost all code borrowed from Zshell's _make function
#
# Copyright (c) 2018 Sebastian Gniazdowski
local -a TARGETS
.make-expandVars() {
local open close var val front='' rest=$1
while [[ $rest == (#b)[^$]#($)* ]]; do
front=$front${rest[1,$mbegin[1]-1]}
rest=${rest[$mbegin[1],-1]}
case $rest[2] in
($) # '$$'. may not appear in target and variable's value
front=$front\$\$
rest=${rest[3,-1]}
continue
;;
(\() # Variable of the form $(foobar)
open='('
close=')'
;;
({) # ${foobar}
open='{'
close='}'
;;
([[:alpha:]]) # $foobar. This is exactly $(f)oobar.
open=''
close=''
var=$rest[2]
;;
(*) # bad parameter name
print -- $front$rest
return 1
;;
esac
if [[ -n $open ]]; then
if [[ $rest == \$$open(#b)([[:alnum:]_]##)(#B)$close* ]]; then
var=$match
else # unmatched () or {}, or bad parameter name
print -- $front$rest
return 1
fi
fi
val=''
if [[ -n ${VAR_ARGS[(i)$var]} ]]; then
val=${VAR_ARGS[$var]}
else
if [[ -n $opt_args[(I)(-e|--environment-overrides)] ]]; then
if [[ $parameters[$var] == scalar-export* ]]; then
val=${(P)var}
elif [[ -n ${VARIABLES[(i)$var]} ]]; then
val=${VARIABLES[$var]}
fi
else
if [[ -n ${VARIABLES[(i)$var]} ]]; then
val=${VARIABLES[$var]}
elif [[ $parameters[$var] == scalar-export* ]]; then
val=${(P)var}
fi
fi
fi
rest=${rest//\$$open$var$close/$val}
done
print -- ${front}${rest}
}
.make-parseMakefile () {
local input var val target dep TAB=$'\t' tmp IFS=
while read input
do
case "$input " in
# TARGET: dependencies
# TARGET1 TARGET2 TARGET3: dependencies
([[*?[:alnum:]$][^$TAB:=%]#:[^=]*)
target=$(.make-expandVars ${input%%:*})
TARGETS+=( ${(z)target} )
;;
esac
done
}
if [[ -z "${FAST_HIGHLIGHT[chroma-make-cache]}" || $(( EPOCHSECONDS - FAST_HIGHLIGHT[chroma-make-cache-born-at] )) -gt 7 ]]; then
.make-parseMakefile
FAST_HIGHLIGHT[chroma-make-cache-born-at]="$EPOCHSECONDS"
FAST_HIGHLIGHT[chroma-make-cache]="${(j:;:)TARGETS}"
fi
reply2=( "${(s:;:)FAST_HIGHLIGHT[chroma-make-cache]}" )
# vim:ft=zsh:et

View File

@ -0,0 +1,30 @@
# Copyright (c) 2018 Sebastian Gniazdowski
#
# $1 - path to the ini file to parse
# $2 - name of output hash (INI by default)
# $3 - prefix for keys in the hash (can be empty)
#
# Writes to given hash under keys built in following way: ${3}<section>_field.
# Values are values from ini file.
local __ini_file="$1" __out_hash="${2:-INI}" __key_prefix="$3"
local IFS='' __line __cur_section="void" __access_string
local -a match mbegin mend
[[ ! -r "$__ini_file" ]] && { builtin print -r "fast-syntax-highlighting: an ini file is unreadable ($__ini_file)"; return 1; }
while read -r -t 1 __line; do
if [[ "$__line" = [[:blank:]]#\;* ]]; then
continue
elif [[ "$__line" = (#b)[[:blank:]]#\[([^\]]##)\][[:blank:]]# ]]; then
__cur_section="${match[1]}"
elif [[ "$__line" = (#b)[[:blank:]]#([^[:blank:]=]##)[[:blank:]]#[=][[:blank:]]#(*) ]]; then
match[2]="${match[2]%"${match[2]##*[! $'\t']}"}" # remove trailing whitespace
__access_string="${__out_hash}[${__key_prefix}<$__cur_section>_${match[1]}]"
: "${(P)__access_string::=${match[2]}}"
fi
done < "$__ini_file"
return 0
# vim:ft=zsh:sw=4:sts=4:et

View File

@ -0,0 +1,37 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# FAST_HIGHLIGHT hash serves as container for variables that
# prevents creating them in global scope. (P) flag is not used,
# output array is fixed (__lines_list).
#
# $1 - the command, e.g. "git remote"; 2>/dev/null redirection is
# added automatically
# $2 - FAST_HIGHLIGHT field name, e.g. "chroma-git-branches"; two
# additional fields will be used, $2-cache, $2-cache-born-at
# $3 - what to remove from beginning of the lines returned by the
# command
# $4 - cache validity time, default 5 (seconds)
#
# Output: array __lines_list, with output of the command ran
# User should not forget to define this array, the below code
# will only ensure that it's array (can also define a global)
typeset -ga __lines_list
local -a __response
if [[ -z "${FAST_HIGHLIGHT[$2-cache]}" || $(( EPOCHSECONDS - FAST_HIGHLIGHT[$2-cache-born-at] )) -gt ${4:-5} ]]; then
FAST_HIGHLIGHT[$2-cache-born-at]="$EPOCHSECONDS"
__response=( ${${(f)"$(command ${(Qz)1#+} 2>/dev/null)"}#${~3}} )
[[ "$1" = "+"* ]] && __lines_list+=( "${__response[@]}" ) || __lines_list=( "${__response[@]}" )
FAST_HIGHLIGHT[$2-cache]="${(j:;:)__response}"
else
# Quoted (s:;:) flag without @ will skip empty elements. It
# still produces array output, interesingly. All this is for
# the trailing ";" above, to skip last, empty element.
[[ "$1" = "+"* ]] && \
__lines_list+=( "${(@s:;:)FAST_HIGHLIGHT[$2-cache]}" ) || \
__lines_list=( "${(@s:;:)FAST_HIGHLIGHT[$2-cache]}" )
fi
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,60 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# It runs given command, which in general will be a git command,
# automatically looking at cache first (a field named *-cache,
# in FAST_HIGHLIGHT), which is valid for 5 seconds, and in case
# of outdated or not existing cache, runs the command, splitting
# on new-lines, first checking if PWD is inside git repository.
#
# FAST_HIGHLIGHT hash serves as container for variables that
# prevents creating them in global scope. (P) flag is not used,
# output array is fixed (__lines_list).
#
# $1 - the command, e.g. "git remote"; 2>/dev/null redirection is
# added automatically
# $2 - FAST_HIGHLIGHT field name, e.g. "chroma-git-branches"; two
# additional fields will be used, $2-cache, $2-cache-born-at
# $3 - what to remove from beginning of the lines returned by the
# command
# $4 - cache validity time, default 5 (seconds)
#
# Output: array __lines_list, with output of the (git) command ran
# User should not forget to define this array, the below code
# will only ensure that it's array (can also define a global)
typeset -ga __lines_list
local -a __response
if [[ $1 == --status ]] {
integer __status=1
shift
}
if [[ -z ${FAST_HIGHLIGHT[$2-cache]} || $(( EPOCHSECONDS - FAST_HIGHLIGHT[$2-cache-born-at] )) -gt ${4:-5} ]]; then
FAST_HIGHLIGHT[$2-cache-born-at]=$EPOCHSECONDS
if [[ "$(command git rev-parse --is-inside-work-tree 2>/dev/null)" = true ]]; then
__response=( ${${(f)"$(command ${(Qz)${1#+}} 2>/dev/null)"}#$3} )
integer retval=$?
if (( __status )) {
__response=( $retval )
__lines_list=( $retval )
} else {
[[ "$1" = "+"* ]] && \
__lines_list+=( "${__response[@]}" ) || \
__lines_list=( "${__response[@]}" )
}
else
__lines_list=()
fi
FAST_HIGHLIGHT[$2-cache]="${(j:;:)__response}"
else
# Quoted (s:;:) flag without @ will skip empty elements. It
# still produces array output, interesingly. All this is for
# the trailing ";" above, to skip last, empty element.
[[ "$1" = "+"* ]] && \
__lines_list+=( "${(@s:;:)FAST_HIGHLIGHT[$2-cache]}" ) || \
__lines_list=( "${(@s:;:)FAST_HIGHLIGHT[$2-cache]}" )
fi
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,17 @@
# $1 - file-descriptor to be read from
# $2 - name of output variable (default: REPLY)
local __in_fd=${1:-0} __out_var=${2:-REPLY}
local -a __tmp
integer __ret=1 __repeat=10 __tmp_size=0
while sysread -s 65535 -i "$__in_fd" '__tmp[__tmp_size + 1]'; do
(( ( __ret=$? ) == 0 )) && (( ++ __tmp_size ))
(( __ret == 5 )) && { __ret=0; (( --__repeat == 0 )) && break; }
done
: ${(P)__out_var::="${(j::)__tmp}"}
return __ret
# vim: ft=zsh:et:sw=4:sts=4

View File

@ -0,0 +1,24 @@
current_theme.zsh
secondary_theme.zsh
theme_overlay.zsh
*.txt
test/out.parse
test/res
hold/*
*.zwc
### Vim
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
# Session
Session.vim
# Temporary
.netrwhist
*~
# Auto-generated tag files
tags

View File

@ -0,0 +1,13 @@
addons:
apt:
packages:
zsh
install:
- mkdir .bin
- curl -L https://github.com/zunit-zsh/zunit/releases/download/v0.8.2/zunit > .bin/zunit
- curl -L https://raw.githubusercontent.com/molovo/revolver/master/revolver > .bin/revolver
- curl -L https://raw.githubusercontent.com/molovo/color/master/color.zsh > .bin/color
before_script:
- chmod u+x .bin/{color,revolver,zunit}
- export PATH="$PWD/.bin:$PATH"
script: zunit

View File

@ -0,0 +1,8 @@
tap: false
directories:
tests: tests
output: tests/_output
support: tests/_support
time_limit: 0
fail_fast: false
allow_risky: false

View File

@ -0,0 +1,166 @@
# Chroma Guide for F-Sy-H
## Motivation
Someone might want to create a detailed highlighting for a **specific program**
and this document helps achieving this. It explains how chroma functions the
code behind such detailed highlighting are constructed and used.
## Keywords
- `chroma` - a shorthand for `chroma function` the thing that literally colorizes selected commands, like `git`, `grep`, etc. invocations, see `chroma function` below,
- `big loop` - main highlighting code, a loop over tokens and at least 2 large structular constructs (big `if` and `case`);
it is advanced, e.g. parses `case` statements, here-string, it basically constitutes 90% of the F-Sy-H project,
- `chroma function` - a plugin-function that is called when a specific command occurs (e.g. when user enters `git` at
command line) suppressing activity of `big loop` (i.e. no standard highlighting unless requested),
- `token` - result of splitting whole command line (i.e. `$BUFFER`, the Zle variable) into bits called tokens, which are
words in general, separated by spaces on the command line.
## Overview Of Functioning
1. Big loop is working token by token processes command line, changes states (e.g. enters state "inside case
statement") and in the end decides on color of the token currently processed.
2. Big loop occurs a command that has a chroma, e.g. `git`.
3. Big loop enters "chroma" state, calls associated chroma function.
4. Chroma takes care of "chroma" state, ensures it will be set also for next token.
5. "chroma" state is active, so all following tokens are routed to the chroma (in general skipping big-loop, see next items),
6. When processing of a single token is complete, the associated chroma returns 0
(shell-truth) to request no further processing by the big loop.
7. It can also return 1 so that single, current token will be passed into big-loop
for processing (to do a standard highlighting).
## Chroma-Function Arguments
- `$1` - 0 or 1, denoting if it's the first call to the chroma, or a following one,
- `$2` - the current token, also accessible by `$\__arg` from the upper scope -
basically a private copy of `$__arg`; the token can be eg.: "grep",
- `$3` - a private copy of `$_start_pos`, i.e. the position of the token in the
command line buffer, used to add region_highlight entry (see man),
because Zsh colorizes by *ranges* applied onto command line buffer (e.g.
`from-10 to-13 fg=red`),
- `$4` - a private copy of `$_end_pos` from the upper scope; denotes where current token
ends (at which index in the string being the command line).
So example invocation could look like this:
----
chroma/-example.ch 1 "grep" "$_start_pos" "$_end_pos"
----
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.).
## Example Chroma-Function
[source,zsh]
----
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Example chroma function. It colorizes first two arguments as `builtin' style,
# third and following arguments as `globbing' style. First two arguments may
# be "strings", they will be passed through to normal higlighter (by returning 1).
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
#
# $2 - like above document says
#
# $3 - ...
#
# $4 - ...
#
# Other tips are:
# - $CURSOR holds cursor position
# - $BUFFER holds whole command line buffer
# - $LBUFFER holds command line buffer that is left from the cursor, i.e. it's a
# BUFFER substring 1 .. $CURSOR
# - $RBUFFER is the same as LBUFFER but holds part of BUFFER right to the cursor
#
# The function receives $BUFFER but via sequence of tokens, which are shell words,
# e.g. "a b c" is a shell word, while a b c are 3 shell words.
#
# FAST_HIGHLIGHT is a friendly hash array which allows to store strings without
# creating global parameters (variables). If you need hash, go ahead and use it,
# declaring first, under some distinct name like: typeset -gA CHROMA_EXPLE_DICT.
# Remember to reset the hash and others at __first_call == 1, so that you have
# a fresh state for new command.
# Keep chroma-takever state meaning: until ;, handle highlighting via chroma.
# So the below 8192 assignment takes care that next token will be routed to chroma.
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style
integer __idx1 __idx2
(( __first_call )) && {
# Called for the first time - new command.
# FAST_HIGHLIGHT is used because it survives between calls, and
# allows to use a single global hash only, instead of multiple
# global string variables.
FAST_HIGHLIGHT[chroma-example-counter]=0
# Set style for region_highlight entry. It is used below in
# '[[ -n "$__style" ]] ...' line, which adds highlight entry,
# like "10 12 fg=green", through `reply' array.
#
# Could check if command `example' exists and set `unknown-token'
# style instead of `command'
__style=${FAST_THEME_NAME}command
} || {
# Following call, i.e. not the first one
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if [[ "$__wrd" = -* ]]; then
# Detected option, add style for it.
[[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \
__style=${FAST_THEME_NAME}single-hyphen-option
else
# Count non-option tokens
(( FAST_HIGHLIGHT[chroma-example-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-example-counter] ))
# Colorize 1..2 as builtin, 3.. as glob
if (( FAST_HIGHLIGHT[chroma-example-counter] <= 2 )); then
if [[ "$__wrd" = \"* ]]; then
# Pass through, fsh main code will do the highlight!
return 1
else
__style=${FAST_THEME_NAME}builtin
fi
else
__style=${FAST_THEME_NAME}globbing
fi
fi
}
# Add region_highlight entry (via `reply' array).
# If 1 will be added to __start_pos, this will highlight "oken".
# If 1 will be subtracted from __end_pos, this will highlight "toke".
# $PREBUFFER is for specific situations when users does command \<ENTER>
# i.e. when multi-line command using backslash is entered.
#
# This is a common place of adding such entry, but any above code can do
# it itself (and it does in other chromas) and skip setting __style to
# this way disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through, do obligatory things ourselves.
# _start_pos=$_end_pos advainces pointers in command line buffer.
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
----

View File

@ -0,0 +1,23 @@
Copyright (c) 2010-2016 zsh-syntax-highlighting contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
may be used to endorse or promote products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,290 @@
[![paypal](https://img.shields.io/badge/-Donate-yellow.svg?longCache=true&style=for-the-badge)](https://www.paypal.me/ZdharmaInitiative)
[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=D54B3S7C6HGME)
[![patreon](https://img.shields.io/badge/-Patreon-orange.svg?longCache=true&style=for-the-badge)](https://www.patreon.com/psprint)
<br/>New: You can request a feature when donating, even fancy or advanced ones get implemented this way. [There are
reports](DONATIONS.md) about what is being done with the money received.
# Fast Syntax Highlighting (F-Sy-H)
Feature rich syntax highlighting for Zsh.
<div style="width:100%;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px">
<img
src="https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/highlight-much.png"
alt="image could not be loaded"
style="color:red;background-color:black;font-weight:bold"
/>
</div>
### Table of Contents
- [News](#news)
- [Installation](#installation)
- [Features](#features)
- [Performance](#performance)
- [IRC Channel](#irc-channel)
### Other Contents
- [License](https://github.com/zdharma/fast-syntax-highlighting/blob/master/LICENSE)
- [Changelog](https://github.com/zdharma/fast-syntax-highlighting/blob/master/CHANGELOG.md)
- [Theme Guide](https://github.com/zdharma/fast-syntax-highlighting/blob/master/THEME_GUIDE.md)
- [Chroma Guide](https://github.com/zdharma/fast-syntax-highlighting/blob/master/CHROMA_GUIDE.adoc)
# News
* 15-06-2019
- A new architecture for defining the highlighting for **specific commands**: it now
uses **abstract definitions** instead of **top-down, regular code**. The first effect
is the highlighting for the `git` command it is now **maximally faithful**, it
follows the `git` command almost completely.
[Screencast](https://asciinema.org/a/253411)
# Installation
### Manual
Clone the Repository.
```zsh
git clone https://github.com/zdharma/fast-syntax-highlighting ~/path/to/fsh
```
And add the following to your `zshrc` file.
```zsh
source ~/path/to/fsh/fast-syntax-highlighting.plugin.zsh
```
### Zinit
Add the following to your `zshrc` file.
```zsh
zinit light zdharma/fast-syntax-highlighting
```
Here's an example of how to load the plugin together with a few other popular
ones with the use of
[Turbo](https://zdharma.org/zinit/wiki/INTRODUCTION/#turbo_mode_zsh_62_53),
i.e.: speeding up the Zsh startup by loading the plugin right after the first
prompt, in background:
```zsh
zinit wait lucid for \
atinit"ZINIT[COMPINIT_OPTS]=-C; zicompinit; zicdreplay" \
zdharma/fast-syntax-highlighting \
blockf \
zsh-users/zsh-completions \
atload"!_zsh_autosuggest_start" \
zsh-users/zsh-autosuggestions
```
### Antigen
Add the following to your `zshrc` file.
```zsh
antigen bundle zdharma/fast-syntax-highlighting
```
### Zgen
Add the following to your `.zshrc` file in the same place you're doing
your other `zgen load` calls in.
```zsh
zgen load zdharma/fast-syntax-highlighting
```
### Oh-My-Zsh
Clone the Repository.
```zsh
git clone https://github.com/zdharma/fast-syntax-highlighting.git \
${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting
```
And add `fast-syntax-highlighting` to your plugin list.
# Features
### Themes
Switch themes via `fast-theme {theme-name}`.
<div style="width:100%;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px">
<img
src="https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/theme.png"
alt="image could not be loaded"
style="color:red;background-color:black;font-weight:bold"
/>
</div>
Run `fast-theme -t {theme-name}` option to obtain the snippet above.
Run `fast-theme -l` to list available themes.
### Variables
Comparing to the project `zsh-users/zsh-syntax-highlighting` (the upper line):
<div style="width:100%;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px">
<img
src="https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/parameter.png"
alt="image could not be loaded"
style="color:red;background-color:black;font-weight:bold"
/>
</div>
<div style="width:100%;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px">
<img
src="https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/in_string.png"
alt="image could not be loaded"
style="color:red;background-color:black;font-weight:bold"
/>
</div>
### Brackets
<div style="width:100%;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px">
<img
src="https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/brackets.gif"
alt="image could not be loaded"
style="color:red;background-color:black;font-weight:bold"
/>
</div>
### Conditions
Comparing to the project `zsh-users/zsh-syntax-highlighting` (the upper line):
<div style="width:100%;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px">
<img
src="https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/cplx_cond.png"
alt="image could not be loaded"
style="color:red;background-color:black;font-weight:bold"
/>
</div>
### Strings
Exact highlighting that recognizes quotings.
<div style="width:100%;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px">
<img
src="https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/ideal-string.png"
alt="image could not be loaded"
style="color:red;background-color:black;font-weight:bold"
/>
</div>
### here-strings
<div style="width:100%;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px">
<img
src="https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/herestring.png"
alt="image could not be loaded"
style="color:red;background-color:black;font-weight:bold"
/>
</div>
### `exec` descriptor-variables
Comparing to the project `zsh-users/zsh-syntax-highlighting` (the upper line):
<div style="width:100%;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px">
<img
src="https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/execfd_cmp.png"
alt="image could not be loaded"
style="color:red;background-color:black;font-weight:bold"
/>
</div>
### for-loops and alternate syntax (brace `{`/`}` blocks)
<div style="width:100%;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px">
<img
src="https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/for-loop-cmp.png"
alt="image could not be loaded"
style="color:red;background-color:black;font-weight:bold"
/>
</div>
### Function definitions
Comparing to the project `zsh-users/zsh-syntax-highlighting` (the upper 2 lines):
<div style="width:100%;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px">
<img
src="https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/function.png"
alt="image could not be loaded"
style="color:red;background-color:black;font-weight:bold"
/>
</div>
### Recursive `eval` and `$( )` highlighting
Comparing to the project `zsh-users/zsh-syntax-highlighting` (the upper line):
<div style="width:100%;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px">
<img
src="https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/eval_cmp.png"
alt="image could not be loaded"
style="color:red;background-color:black;font-weight:bold"
/>
</div>
### Chroma functions
Highlighting that is specific for a given command.
<div style="width:100%;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px">
<img
src="https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/git_chroma.png"
alt="image could not be loaded"
style="color:red;background-color:black;font-weight:bold"
/>
</div>
The [chromas](https://github.com/zdharma/fast-syntax-highlighting/tree/master/chroma)
that are enabled by default can be found
[here](https://github.com/zdharma/fast-syntax-highlighting/blob/master/fast-highlight#L166).
### Math-mode highlighting
<div style="width:100%;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px">
<img
src="https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/math.gif"
alt="image could not be loaded"
style="color:red;background-color:black;font-weight:bold"
/>
</div>
### Zcalc highlighting
<div style="width:100%;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px">
<img
src="https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/zcalc.png"
alt="image could not be loaded"
style="color:red;background-color:black;font-weight:bold"
/>
</div>
# Performance
Performance differences can be observed in this Asciinema recording, where a `10 kB` function is being edited.
<div style="width:100%;background-color:#121314;border:3px solid #121314;border-radius:6px;margin:5px 0;padding:2px 5px">
<a href="https://asciinema.org/a/112367">
<img src="https://asciinema.org/a/112367.png" alt="asciicast">
</a>
</div>
## IRC Channel
Channel `#zinit@freenode` is a support place for all author's projects. Connect to:
[chat.freenode.net:6697](ircs://chat.freenode.net:6697/%23zinit) (SSL) or [chat.freenode.net:6667](irc://chat.freenode.net:6667/%23zinit)
and join #zinit.
Following is a quick access via Webchat [![IRC](https://kiwiirc.com/buttons/chat.freenode.net/zinit.png)](https://kiwiirc.com/client/chat.freenode.net:+6697/#zinit)

View File

@ -0,0 +1,76 @@
# Theme Guide for F-Sy-H
`fast-theme` tool is used to select a theme. There are 6 shipped themes, they can be listed with `fast-theme -l`.
Themes are basic [INI files](https://github.com/zdharma/fast-syntax-highlighting/tree/master/themes) where each
key is a *style*.
Besides shipped themes, user can point this tool to any other theme, by simple `fast-theme ~/mytheme.ini`. To
obtain template to work on when creating own theme, issue `fast-theme --copy-shipped-theme {theme-name}`.
To alter just a few styles and not create a whole new theme, use **overlay**. What is overlay? It is in the same
format as full theme, but can have only a few styles defined, and these styles will overwrite styles in main-theme.
Example overlay file:
```ini
; overlay.ini
[base]
commandseparator = yellow,bold
comment = 17
[command-point]
function = green
command = 180
```
File name `overlay.ini` is treated specially.
When specifing path, following short-hands can be used:
```
XDG: = ~/.config/fsh (respects $XDG_CONFIG_HOME env var)
LOCAL: = /usr/local/share/fsh/
HOME: = ~/.fsh/
OPT: = /opt/local/share/fsh/
```
So for example, issue `fast-theme XDG:overlay` to load `~/.config/fsh/overlay.ini` as overlay. The `.ini`
extension is optional.
## Secondary Theme
Each theme has key `secondary`, e.g. for theme `free`:
```ini
; free.ini
[base]
default = none
unknown-token = red,bold
; ...
; ...
; ...
secondary = zdharma
```
Secondary theme (`zdharma` in the example) will be used for highlighting of argument for `eval`
and of `$( ... )` interior (i.e. of interior of command substitution). Basically, recursive
highlighting uses alternate theme to make the highlighted code distinct:
![sshot](https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/cmdsubst.png)
In the above screen-shot the interior of `$( ... )` uses different colors than the rest of the
code. Example for `eval`:
![image](https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/images/eval_cmp.png)
First line doesn't use recursive highlighting, highlights `eval` argument as regular string.
Second line switches theme to `zdharma` and does full recursive highlighting of eval argument.
## Custom Working Directory
Set `$FAST_WORK_DIR` before loading the plugin to have e.g. processed theme files (ready to
load, in Zsh format, not INI) kept under specified location. This is handy if e.g. you install
Fast-Syntax-Highlighting system-wide (e.g. from AUR on ArchLinux) and want to have per-user
theme setup.
You can use "~" in the path, e.g. `FAST_WORK_DIR=~/.fsh` and also the `XDG:`, `LOCAL:`, `OPT:`,
etc. short-hands, so 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 default by F-Sy-H loader).

View File

@ -0,0 +1,39 @@
#compdef fast-theme
#
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Completion for theme-switching function, fast-theme,
# part of zdharma/fast-syntax-highlighting.
#
integer ret=1
local -a arguments
arguments=(
{-h,--help}'[display help text]'
{-l,--list}'[list available themes]'
{-r,--reset}'[unset any theme (revert to default highlighting)]'
{-R,--ov-reset}'[unset overlay, use styles only from main-theme (requires restart)]'
{-q,--quiet}'[no default messages]'
{-s,--show}'[get and display the theme currently being set]'
{-v,--verbose}'[more messages during operation]'
{-t,--test}'[test theme after setting it (show example code)]'
{-p,--palette}'[just print all 256 colors and exit (useful when creating a theme)]'
{-w,--workdir}'[cd into $FAST_WORK_DIR (if not set, then into the plugin directory)]'
)
typeset -a themes
themes=( "$FAST_WORK_DIR"/themes/*.ini(:t:r) )
if [[ -d ${XDG_CONFIG_HOME:-$HOME/.config}/fsh ]] {
typeset -a themes2
themes2=( "${XDG_CONFIG_HOME:-$HOME/.config}"/fsh/*.ini(:t:r) )
themes+=( XDG:${^themes2[@]} )
}
_wanted themes expl "Themes" \
compadd "$@" -a - themes && ret=0
_arguments -s $arguments && ret=0
return $ret

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,77 @@
# vim:ft=zsh:sw=4:sts=4
#
# $1 - PREBUFFER
# $2 - BUFFER
#
function -fast-highlight-string-process {
emulate -LR zsh
setopt extendedglob warncreateglobal typesetsilent
local -A pos_to_level level_to_pos pair_map final_pairs
local input=$1$2 _mybuf=$1$2 __style __quoting
integer __idx=0 __pair_idx __level=0 __start __end
local -a match mbegin mend
pair_map=( "(" ")" "{" "}" "[" "]" )
while [[ $_mybuf = (#b)([^"{}()[]\\\"'"]#)((["({[]})\"'"])|[\\](*))(*) ]]; do
if [[ -n ${match[4]} ]] {
__idx+=${mbegin[2]}
[[ $__quoting = \' ]] && _mybuf=${match[4]} || { _mybuf=${match[4]:1}; (( ++ __idx )); }
} else {
__idx+=${mbegin[2]}
[[ -z $__quoting && -z ${_FAST_COMPLEX_BRACKETS[(r)$((__idx-${#PREBUFFER}-1))]} ]] && {
if [[ ${match[2]} = ["({["] ]]; then
pos_to_level[$__idx]=$(( ++__level ))
level_to_pos[$__level]=$__idx
elif [[ ${match[2]} = ["]})"] ]]; then
if (( __level > 0 )); then
__pair_idx=${level_to_pos[$__level]}
pos_to_level[$__idx]=$(( __level -- ))
[[ ${pair_map[${input[__pair_idx]}]} = ${input[__idx]} ]] && {
final_pairs[$__idx]=$__pair_idx
final_pairs[$__pair_idx]=$__idx
}
else
pos_to_level[$__idx]=-1
fi
fi
}
if [[ ${match[2]} = \" && $__quoting != \' ]] {
[[ $__quoting = '"' ]] && __quoting="" || __quoting='"';
}
if [[ ${match[2]} = \' && $__quoting != \" ]] {
if [[ $__quoting = ("'"|"$'") ]] {
__quoting=""
} else {
if [[ $match[1] = *\$ ]] {
__quoting="\$'";
} else {
__quoting="'";
}
}
}
_mybuf=${match[5]}
}
done
for __idx in ${(k)pos_to_level}; do
(( ${+final_pairs[$__idx]} )) && __style=${FAST_THEME_NAME}bracket-level-$(( ( (pos_to_level[$__idx]-1) % 3 ) + 1 )) || __style=${FAST_THEME_NAME}unknown-token
(( __start=__idx-${#PREBUFFER}-1, __end=__idx-${#PREBUFFER}, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
done
# If cursor is on a bracket, then highlight corresponding bracket, if any.
if [[ $WIDGET != zle-line-finish ]]; then
__idx=$(( CURSOR + 1 ))
if (( ${+pos_to_level[$__idx]} )) && (( ${+final_pairs[$__idx]} )); then
(( __start=final_pairs[$__idx]-${#PREBUFFER}-1, __end=final_pairs[$__idx]-${#PREBUFFER}, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}paired-bracket]}") && \
reply+=("$CURSOR $__idx ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}paired-bracket]}")
fi
fi
return 0
}

View File

@ -0,0 +1,384 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2010-2016 zsh-syntax-highlighting contributors
# Copyright (c) 2017-2019 Sebastian Gniazdowski (modifications)
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
# Standarized way of handling finding plugin dir,
# regardless of functionargzero and posixargzero,
# and with an option for a plugin manager to alter
# the plugin directory (i.e. set ZERO parameter)
# http://zdharma.org/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
0="${${(M)0:#/*}:-$PWD/$0}"
typeset -g FAST_HIGHLIGHT_VERSION=1.55
typeset -g FAST_BASE_DIR="${0:h}"
typeset -ga _FAST_MAIN_CACHE
# Holds list of indices pointing at brackets that
# are complex, i.e. e.g. part of "[[" in [[ ... ]]
typeset -ga _FAST_COMPLEX_BRACKETS
typeset -g FAST_WORK_DIR=${FAST_WORK_DIR:-${XDG_CACHE_HOME:-~/.cache}/fast-syntax-highlighting}
: ${FAST_WORK_DIR:=$FAST_BASE_DIR}
# Expand any tilde in the (supposed) path.
FAST_WORK_DIR=${~FAST_WORK_DIR}
# Last (currently, possibly) loaded plugin isn't "fast-syntax-highlighting"?
# And FPATH isn't containing plugin dir?
if [[ ${zsh_loaded_plugins[-1]} != */fast-syntax-highlighting && -z ${fpath[(r)${0:h}]} ]]
then
fpath+=( "${0:h}" )
fi
if [[ ! -w $FAST_WORK_DIR ]]; then
FAST_WORK_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/fsh"
command mkdir -p "$FAST_WORK_DIR"
fi
# Invokes each highlighter that needs updating.
# This function is supposed to be called whenever the ZLE state changes.
_zsh_highlight()
{
# Store the previous command return code to restore it whatever happens.
local ret=$?
# Remove all highlighting in isearch, so that only the underlining done by zsh itself remains.
# For details see FAQ entry 'Why does syntax highlighting not work while searching history?'.
if [[ $WIDGET == zle-isearch-update ]] && ! (( $+ISEARCHMATCH_ACTIVE )); then
region_highlight=()
return $ret
fi
emulate -LR zsh
setopt extendedglob warncreateglobal typesetsilent noshortloops
local REPLY # don't leak $REPLY into global scope
local -a reply
# Do not highlight if there are more than 300 chars in the buffer. It's most
# likely a pasted command or a huge list of files in that case..
[[ -n ${ZSH_HIGHLIGHT_MAXLENGTH:-} ]] && [[ $#BUFFER -gt $ZSH_HIGHLIGHT_MAXLENGTH ]] && return $ret
# Do not highlight if there are pending inputs (copy/paste).
[[ $PENDING -gt 0 ]] && return $ret
# Reset region highlight to build it from scratch
# may need to remove path_prefix highlighting when the line ends
if [[ $WIDGET == zle-line-finish ]] || _zsh_highlight_buffer_modified; then
-fast-highlight-init
-fast-highlight-process "$PREBUFFER" "$BUFFER" 0
(( FAST_HIGHLIGHT[use_brackets] )) && {
_FAST_MAIN_CACHE=( $reply )
-fast-highlight-string-process "$PREBUFFER" "$BUFFER"
}
region_highlight=( $reply )
else
local char="${BUFFER[CURSOR+1]}"
if [[ "$char" = ["{([])}"] || "${FAST_HIGHLIGHT[prev_char]}" = ["{([])}"] ]]; then
FAST_HIGHLIGHT[prev_char]="$char"
(( FAST_HIGHLIGHT[use_brackets] )) && {
reply=( $_FAST_MAIN_CACHE )
-fast-highlight-string-process "$PREBUFFER" "$BUFFER"
region_highlight=( $reply )
}
fi
fi
{
local cache_place
local -a region_highlight_copy
# Re-apply zle_highlight settings
# region
if (( REGION_ACTIVE == 1 )); then
_zsh_highlight_apply_zle_highlight region standout "$MARK" "$CURSOR"
elif (( REGION_ACTIVE == 2 )); then
() {
local needle=$'\n'
integer min max
if (( MARK > CURSOR )) ; then
min=$CURSOR max=$(( MARK + 1 ))
else
min=$MARK max=$CURSOR
fi
(( min = ${${BUFFER[1,$min]}[(I)$needle]} ))
(( max += ${${BUFFER:($max-1)}[(i)$needle]} - 1 ))
_zsh_highlight_apply_zle_highlight region standout "$min" "$max"
}
fi
# yank / paste (zsh-5.1.1 and newer)
(( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END"
# isearch
(( $+ISEARCHMATCH_ACTIVE )) && (( ISEARCHMATCH_ACTIVE )) && _zsh_highlight_apply_zle_highlight isearch underline "$ISEARCHMATCH_START" "$ISEARCHMATCH_END"
# suffix
(( $+SUFFIX_ACTIVE )) && (( SUFFIX_ACTIVE )) && _zsh_highlight_apply_zle_highlight suffix bold "$SUFFIX_START" "$SUFFIX_END"
return $ret
} always {
typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER="$BUFFER"
typeset -g _ZSH_HIGHLIGHT_PRIOR_RACTIVE="$REGION_ACTIVE"
typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=$CURSOR
}
}
# Apply highlighting based on entries in the zle_highlight array.
# This function takes four arguments:
# 1. The exact entry (no patterns) in the zle_highlight array:
# region, paste, isearch, or suffix
# 2. The default highlighting that should be applied if the entry is unset
# 3. and 4. Two integer values describing the beginning and end of the
# range. The order does not matter.
_zsh_highlight_apply_zle_highlight() {
local entry="$1" default="$2"
integer first="$3" second="$4"
# read the relevant entry from zle_highlight
local region="${zle_highlight[(r)${entry}:*]}"
if [[ -z "$region" ]]; then
# entry not specified at all, use default value
region=$default
else
# strip prefix
region="${region#${entry}:}"
# no highlighting when set to the empty string or to 'none'
if [[ -z "$region" ]] || [[ "$region" == none ]]; then
return
fi
fi
integer start end
if (( first < second )); then
start=$first end=$second
else
start=$second end=$first
fi
region_highlight+=("$start $end $region")
}
# -------------------------------------------------------------------------------------------------
# API/utility functions for highlighters
# -------------------------------------------------------------------------------------------------
# Whether the command line buffer has been modified or not.
#
# Returns 0 if the buffer has changed since _zsh_highlight was last called.
_zsh_highlight_buffer_modified()
{
[[ "${_ZSH_HIGHLIGHT_PRIOR_BUFFER:-}" != "$BUFFER" ]] || [[ "$REGION_ACTIVE" != "$_ZSH_HIGHLIGHT_PRIOR_RACTIVE" ]] || { _zsh_highlight_cursor_moved && [[ "$REGION_ACTIVE" = 1 || "$REGION_ACTIVE" = 2 ]] }
}
# Whether the cursor has moved or not.
#
# Returns 0 if the cursor has moved since _zsh_highlight was last called.
_zsh_highlight_cursor_moved()
{
[[ -n $CURSOR ]] && [[ -n ${_ZSH_HIGHLIGHT_PRIOR_CURSOR-} ]] && (($_ZSH_HIGHLIGHT_PRIOR_CURSOR != $CURSOR))
}
# -------------------------------------------------------------------------------------------------
# Setup functions
# -------------------------------------------------------------------------------------------------
# Helper for _zsh_highlight_bind_widgets
# $1 is name of widget to call
_zsh_highlight_call_widget()
{
integer ret
builtin zle "$@"
ret=$?
_zsh_highlight
return $ret
}
# Rebind all ZLE widgets to make them invoke _zsh_highlights.
_zsh_highlight_bind_widgets()
{
setopt localoptions noksharrays
local -F2 SECONDS
local prefix=orig-s${SECONDS/./}-r$(( RANDOM % 1000 )) # unique each time, in case we're sourced more than once
# Load ZSH module zsh/zleparameter, needed to override user defined widgets.
zmodload zsh/zleparameter 2>/dev/null || {
print -r -- >&2 'zsh-syntax-highlighting: failed loading zsh/zleparameter.'
return 1
}
# Override ZLE widgets to make them invoke _zsh_highlight.
local -U widgets_to_bind
widgets_to_bind=(${${(k)widgets}:#(.*|run-help|which-command|beep|set-local-history|yank|zle-line-pre-redraw)})
# Always wrap special zle-line-finish widget. This is needed to decide if the
# current line ends and special highlighting logic needs to be applied.
# E.g. remove cursor imprint, don't highlight partial paths, ...
widgets_to_bind+=(zle-line-finish)
# Always wrap special zle-isearch-update widget to be notified of updates in isearch.
# This is needed because we need to disable highlighting in that case.
widgets_to_bind+=(zle-isearch-update)
local cur_widget
for cur_widget in $widgets_to_bind; do
case $widgets[$cur_widget] in
# Already rebound event: do nothing.
user:_zsh_highlight_widget_*);;
# The "eval"'s are required to make $cur_widget a closure: the value of the parameter at function
# definition time is used.
#
# We can't use ${0/_zsh_highlight_widget_} because these widgets are always invoked with
# NO_function_argzero, regardless of the option's setting here.
# User defined widget: override and rebind old one with prefix "orig-".
user:*) zle -N -- $prefix-$cur_widget ${widgets[$cur_widget]#*:}
eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }"
zle -N -- $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
# Completion widget: override and rebind old one with prefix "orig-".
completion:*) zle -C $prefix-$cur_widget ${${(s.:.)widgets[$cur_widget]}[2,3]}
eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }"
zle -N -- $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
# Builtin widget: override and make it call the builtin ".widget".
builtin) eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$@\" }"
zle -N -- $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
# Incomplete or nonexistent widget: Bind to z-sy-h directly.
*)
if [[ $cur_widget == zle-* ]] && [[ -z $widgets[$cur_widget] ]]; then
_zsh_highlight_widget_${cur_widget}() { :; _zsh_highlight }
zle -N -- $cur_widget _zsh_highlight_widget_$cur_widget
else
# Default: unhandled case.
print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}"
fi
esac
done
}
# -------------------------------------------------------------------------------------------------
# Setup
# -------------------------------------------------------------------------------------------------
# Try binding widgets.
_zsh_highlight_bind_widgets || {
print -r -- >&2 'zsh-syntax-highlighting: failed binding ZLE widgets, exiting.'
return 1
}
# Reset scratch variables when commandline is done.
_zsh_highlight_preexec_hook()
{
typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER=
typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=0
typeset -ga _FAST_MAIN_CACHE
_FAST_MAIN_CACHE=()
}
autoload -Uz add-zsh-hook
add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || {
print -r -- >&2 'zsh-syntax-highlighting: failed loading add-zsh-hook.'
}
/fshdbg() {
print -r -- "$@" >>! /tmp/reply
}
ZSH_HIGHLIGHT_MAXLENGTH=10000
# Load zsh/parameter module if available
zmodload zsh/parameter 2>/dev/null
zmodload zsh/system 2>/dev/null
autoload -Uz -- is-at-least fast-theme .fast-read-ini-file .fast-run-git-command \
.fast-make-targets .fast-run-command .fast-zts-read-all
autoload -Uz -- →chroma/-git.ch →chroma/-hub.ch →chroma/-lab.ch →chroma/-example.ch \
→chroma/-grep.ch →chroma/-perl.ch →chroma/-make.ch →chroma/-awk.ch \
→chroma/-vim.ch →chroma/-source.ch →chroma/-sh.ch →chroma/-docker.ch \
→chroma/-autoload.ch →chroma/-ssh.ch →chroma/-scp.ch →chroma/-which.ch \
→chroma/-printf.ch →chroma/-ruby.ch →chroma/-whatis.ch →chroma/-alias.ch \
→chroma/-subcommand.ch →chroma/-autorandr.ch →chroma/-nmcli.ch \
→chroma/-fast-theme.ch →chroma/-node.ch →chroma/-fpath_peq.ch \
→chroma/-precommand.ch →chroma/-subversion.ch →chroma/-ionice.ch \
→chroma/-nice.ch →chroma/main-chroma.ch →chroma/-ogit.ch →chroma/-zinit.ch
source "${0:h}/fast-highlight"
source "${0:h}/fast-string-highlight"
local __fsyh_theme
zstyle -s :plugin:fast-syntax-highlighting theme __fsyh_theme
[[ ( "${+termcap}" != 1 || "${termcap[Co]}" != <-> || "${termcap[Co]}" -lt "256" ) && "$__fsyh_theme" = (default|) ]] && {
FAST_HIGHLIGHT_STYLES[defaultvariable]="none"
FAST_HIGHLIGHT_STYLES[defaultglobbing-ext]="fg=blue,bold"
FAST_HIGHLIGHT_STYLES[defaulthere-string-text]="bg=blue"
FAST_HIGHLIGHT_STYLES[defaulthere-string-var]="fg=cyan,bg=blue"
FAST_HIGHLIGHT_STYLES[defaultcorrect-subtle]="bg=blue"
FAST_HIGHLIGHT_STYLES[defaultsubtle-bg]="bg=blue"
[[ "${FAST_HIGHLIGHT_STYLES[variable]}" = "fg=113" ]] && FAST_HIGHLIGHT_STYLES[variable]="none"
[[ "${FAST_HIGHLIGHT_STYLES[globbing-ext]}" = "fg=13" ]] && FAST_HIGHLIGHT_STYLES[globbing-ext]="fg=blue,bold"
[[ "${FAST_HIGHLIGHT_STYLES[here-string-text]}" = "bg=18" ]] && FAST_HIGHLIGHT_STYLES[here-string-text]="bg=blue"
[[ "${FAST_HIGHLIGHT_STYLES[here-string-var]}" = "fg=cyan,bg=18" ]] && FAST_HIGHLIGHT_STYLES[here-string-var]="fg=cyan,bg=blue"
[[ "${FAST_HIGHLIGHT_STYLES[correct-subtle]}" = "fg=12" ]] && FAST_HIGHLIGHT_STYLES[correct-subtle]="bg=blue"
[[ "${FAST_HIGHLIGHT_STYLES[subtle-bg]}" = "bg=18" ]] && FAST_HIGHLIGHT_STYLES[subtle-bg]="bg=blue"
}
unset __fsyh_theme
alias fsh-alias=fast-theme
-fast-highlight-fill-option-variables
if [[ ! -e $FAST_WORK_DIR/secondary_theme.zsh ]] {
if { type curl &>/dev/null } {
curl -fsSL -o "$FAST_WORK_DIR/secondary_theme.zsh" \
https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/share/free_theme.zsh \
&>/dev/null
} elif { type wget &>/dev/null } {
wget -O "$FAST_WORK_DIR/secondary_theme.zsh" \
https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master/share/free_theme.zsh \
&>/dev/null
}
touch "$FAST_WORK_DIR/secondary_theme.zsh"
}
if [[ $(uname -a) = (#i)*darwin* ]] {
typeset -gA FAST_HIGHLIGHT
FAST_HIGHLIGHT[chroma-man]=
}
[[ $COLORTERM == (24bit|truecolor) || ${terminfo[colors]} -eq 16777216 ]] || zmodload zsh/nearcolor &>/dev/null

View File

@ -0,0 +1,385 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
# Copyright (c) 2018, 2019 Philippe Troin (F-i-f on GitHub)
#
# Theme support using ini-files.
#
zmodload zsh/zutil 2>/dev/null
emulate -LR zsh
setopt extendedglob typesetsilent warncreateglobal
autoload colors; colors
typeset -g FAST_WORK_DIR
: ${FAST_WORK_DIR:=$FAST_BASE_DIR}
FAST_WORK_DIR=${~FAST_WORK_DIR}
local -A map
map=( "XDG:" "${XDG_CONFIG_HOME:-$HOME/.config}/fsh/"
"LOCAL:" "/usr/local/share/fsh/"
"HOME:" "$HOME/.fsh/"
"OPT:" "/opt/local/share/fsh/"
)
FAST_WORK_DIR=${${FAST_WORK_DIR/(#m)(#s)(XDG|LOCAL|HOME|OPT):(#c0,1)/${map[${MATCH%:}:]}}%/}
local OPT_HELP OPT_VERBOSE OPT_QUIET OPT_RESET OPT_LIST OPT_TEST OPT_SECONDARY OPT_SHOW OPT_COPY OPT_OV_RESET
local OPT_PALETTE OPT_CDWD OPT_XCHG OPT_OV_XCHG
local -A opthash
zparseopts -E -D -A opthash h -help v -verbose q -quiet r -reset l -list t -test -secondary \
s -show -copy-shipped-theme: R -ov-reset p -palette w -workdir \
x -xchg y -ov-xchg || \
{ echo "Improper options given, see help (-h/--help)"; return 1; }
(( ${+opthash[-h]} + ${+opthash[--help]} )) && OPT_HELP="-h"
(( ${+opthash[-v]} + ${+opthash[--verbose]} )) && OPT_VERBOSE="-v"
(( ${+opthash[-q]} + ${+opthash[--quiet]} )) && OPT_QUIET="-q"
(( ${+opthash[-r]} + ${+opthash[--reset]} )) && OPT_RESET="-r"
(( ${+opthash[-l]} + ${+opthash[--list]} )) && OPT_LIST="-l"
(( ${+opthash[-t]} + ${+opthash[--test]} )) && OPT_TEST="-t"
(( ${+opthash[--secondary]} )) && OPT_SECONDARY="--secondary"
(( ${+opthash[-s]} + ${+opthash[--show]} )) && OPT_SHOW="-s"
(( ${+opthash[--copy-shipped-theme]} )) && OPT_COPY="${opthash[--copy-shipped-theme]}"
(( ${+opthash[-R]} + ${+opthash[--ov-reset]} )) && OPT_OV_RESET="-R"
(( ${+opthash[-p]} + ${+opthash[--palette]} )) && OPT_PALETTE="-p"
(( ${+opthash[-w]} + ${+opthash[--workdir]} )) && OPT_CDWD="-w"
(( ${+opthash[-x]} + ${+opthash[--xchg]} )) && OPT_XCHG="-x"
(( ${+opthash[-y]} + ${+opthash[--ov-xchg]} )) && OPT_OV_XCHG="-y"
local -a match mbegin mend
local MATCH; integer MBEGIN MEND
[[ -n "$OPT_CDWD" ]] && {
builtin cd $FAST_WORK_DIR
return 0
}
[[ -n "$OPT_PALETTE" ]] && {
local n
local -a __colors
for n in {000..255}
do
__colors+=("%F{$n}$n%f")
done
print -cP $__colors
return
}
[[ -n "$OPT_SHOW" ]] && {
print -r -- "Currently active theme: ${fg_bold[yellow]}$FAST_THEME_NAME$reset_color"
( source "$FAST_WORK_DIR"/current_theme.zsh 2>/dev/null && print "Main theme (loaded at startup of a session): ${fg_bold[yellow]}$FAST_THEME_NAME$reset_color" || print "No main theme is set"; )
return 0
}
[[ -n "$OPT_COPY" ]] && {
[[ ! -f "$FAST_BASE_DIR"/themes/"${OPT_COPY%.ini}.ini" ]] && { print "Theme \`$OPT_COPY' doesn't exist in FSH plugin dir ($FAST_BASE_DIR/themes)"; return 1; }
[[ ! -r "$FAST_BASE_DIR"/themes/"${OPT_COPY%.ini}.ini" ]] && { print "Theme \`$OPT_COPY' isn't readable in FSH plugin dir ($FAST_BASE_DIR/themes)"; return 1; }
[[ -n "$1" ]] && {
[[ ! -e "$1" && ! -e ${1:h} ]] && { print "Destination path doesn't exist, aborting"; return 1; }
}
command cp -vf "$FAST_BASE_DIR"/themes/"${OPT_COPY%.ini}.ini" "${${1:-.}%.ini}.ini" || return 1
return 0
}
[[ -n "$OPT_RESET" ]] && { command rm -f "$FAST_WORK_DIR"/{current_theme.zsh,secondary_theme.zsh}; [[ -z "$OPT_QUIET" ]] && print "Reset done (no theme is now set, restart is required)"; return 0; }
[[ -n "$OPT_OV_RESET" ]] && { command rm -f "$FAST_WORK_DIR"/theme_overlay.zsh; [[ -z "$OPT_QUIET" ]] && print "Overlay-reset done, it is inactive (restart is required)"; return 0; }
[[ -n "$OPT_LIST" ]] && {
[[ -z "$OPT_QUIET" ]] && print -r -- "Available themes:"
print -rl -- "$FAST_BASE_DIR"/themes/*.ini(:t:r)
return 0
}
[[ -n "$OPT_HELP" ]] && {
print -r -- "Usage: fast-theme [-h/--help] [-v/--verbose] [-q/--quiet] [-t/--test] <theme-name|theme-path>"
print -r -- " fast-theme [-r/--reset] [-l/--list] [-s/--show] [-p/--palette] [-w/--workdir]"
print -r -- " fast-theme --copy-shipped-theme {theme-name} [destination-path]"
print -r -- ""
print -r -- "Default action (after providing <theme-name> or <theme-path>) is to switch"
print -r -- "current session and any future sessions to the new theme. Using <theme-path>,"
print -r -- "i.e.: a path to an ini file means using custom, own theme. The path can use an"
print -r -- "\"XDG:\" shorthand (e.g.: \"XDG:mytheme\") that will point to ~/.config/fsh/<theme>.ini"
print -r -- "(or \$XDG_CONFIG_HOME/fsh/<theme>.ini in general if the variable is set in the"
print -r -- "environment). If the INI file pointed in the path is \"*overlay*\", then it is"
print -r -- "not a full theme, but an additional theme-snippet that overwrites only selected"
print -r -- "styles of the main theme."
print -r -- ""
print -r -- "Other path-shorthands:"
print -r -- "LOCAL: = /usr/local/share/fsh/"
print -r -- "HOME: = $HOME/.fsh/"
print -r -- "OPT: = /opt/local/share/fsh/"
print -r -- ""
print -r -- "-r/--reset - unset any theme, use default highlighting (requires restart)"
print -r -- "-R/--ov-reset - unset overlay, use styles only from main-theme (requires restart)"
print -r -- "-l/--list - list names of available themes"
print -r -- "-t/--test - show test block of code after switching theme"
print -r -- "-s/--show - get and display the theme currently being set"
print -r -- "-p/--palette - just print all 256 colors and exit (useful when creating a theme)"
print -r -- "-w/--workdir - cd into \$FAST_WORK_DIR (if not set, then into the plugin directory)"
print -r -- "-v/--verbose - more messages during operation"
print -r -- "-q/--quiet - no default messages"
print -r -- ""
print -r -- "The option --copy-shipped-theme allows easy copying of one of the 6 shipped"
print -r -- "themes into given destination path. Normal use means changing directory to"
print -r -- "e.g.: ~/.config/fsh, and then issuing e.g.: \`fast-theme --copy-shipped-theme"
print -r -- "clean mytheme', to obtain a template for own new theme."
return 0
}
[[ -z "$1" ]] && { print -u2 "Provide a theme (its name or path to its file) to switch to, aborting (see -h/--help)"; return 1; }
# FAST_HIGHLIGHT_STYLES key onto ini-file key
map=(
default "-"
unknown-token "-"
reserved-word "-"
subcommand "- reserved-word"
alias "- command builtin"
suffix-alias "- alias command builtin"
builtin "-"
function "- builtin command"
command "-"
precommand "- command"
commandseparator "-"
hashed-command "- command"
path "-"
path_pathseparator "pathseparator"
globbing "- back-or-dollar-double-quoted-argument" # fallback: variable in string "text $var text"
globbing-ext "- double-quoted-argument" # fallback: the string "abc..."
history-expansion "-"
single-hyphen-option "- single-quoted-argument"
double-hyphen-option "- double-quoted-argument"
back-quoted-argument "-"
single-quoted-argument "-"
double-quoted-argument "-"
dollar-quoted-argument "-"
back-or-dollar-double-quoted-argument "- back-dollar-quoted-argument"
back-dollar-quoted-argument "- back-or-dollar-double-quoted-argument"
assign "- reserved-word"
redirection "- reserved-word"
comment "-"
variable "-"
mathvar "- forvar variable"
mathnum "- fornum"
matherr "- incorrect-subtle"
assign-array-bracket "-"
for-loop-variable "forvar mathvar variable"
for-loop-number "fornum mathnum"
for-loop-operator "foroper reserved-word"
for-loop-separator "forsep commandseparator"
exec-descriptor "- reserved-word"
here-string-tri "-"
here-string-text "- subtle-bg"
here-string-var "- back-or-dollar-double-quoted-argument"
secondary "-"
recursive-base "- default"
case-input "- variable"
case-parentheses "- reserved-word"
case-condition "- correct-subtle"
correct-subtle "-"
incorrect-subtle "-"
subtle-separator "- commandseparator"
subtle-bg "- correct-subtle"
path-to-dir "- path"
paired-bracket "- subtle-bg correct-subtle"
bracket-level-1 "-"
bracket-level-2 "-"
bracket-level-3 "-"
global-alias "- alias suffix-alias"
single-sq-bracket "-"
double-sq-bracket "-"
double-paren "-"
optarg-string "- double-quoted-argument"
optarg-number "- mathnum"
)
# In which order to generate entries
local -a order
order=(
default unknown-token reserved-word alias suffix-alias builtin function command precommand
commandseparator hashed-command path path_pathseparator globbing globbing-ext history-expansion
single-hyphen-option double-hyphen-option back-quoted-argument single-quoted-argument
double-quoted-argument dollar-quoted-argument back-or-dollar-double-quoted-argument
back-dollar-quoted-argument assign redirection comment variable mathvar
mathnum matherr assign-array-bracket for-loop-variable for-loop-number for-loop-operator
for-loop-separator exec-descriptor here-string-tri here-string-text here-string-var secondary
case-input case-parentheses case-condition correct-subtle incorrect-subtle subtle-separator subtle-bg
path-to-dir paired-bracket bracket-level-1 bracket-level-2 bracket-level-3
global-alias subcommand single-sq-bracket double-sq-bracket double-paren
optarg-string optarg-number recursive-base
)
[[ -n "$OPT_VERBOSE" ]] && print "Number of styles available for customization: ${#order}"
# Named colors
local -a color
color=( red green blue yellow cyan magenta black white default )
#
# Execution starts here
#
local -A out
local THEME_NAME THEME_PATH="$1"
if [[ "$1" = */* || "$1" = (XDG|LOCAL|HOME|OPT):* ]]; then
1="${${1/(#s)XDG:/${${XDG_CONFIG_HOME:-$HOME/.config}%/}/fsh/}%.ini}.ini"
1="${${1/(#s)LOCAL://usr/local/share/fsh/}%.ini}.ini"
1="${${1/(#s)HOME:/$HOME/.fsh/}%.ini}.ini"
1="${${1/(#s)OPT://opt/local/share/fsh/}%.ini}.ini"
1=${~1} # allow user to quote ~
[[ ! -f "$1" ]] && { print -u2 "No such theme \`$1', aborting"; return 1; }
[[ ! -r "$1" ]] && { print -u2 "Theme \`$1' unreadable, aborting"; return 1; }
THEME_NAME="${1:t:r}"
.fast-read-ini-file "$1" out ""
else
[[ ! -f "$FAST_BASE_DIR/themes/$1.ini" ]] && { print -u2 "No such theme \`$1', aborting"; return 1; }
[[ ! -r "$FAST_BASE_DIR/themes/$1.ini" ]] && { print -u2 "Theme \`$1' unreadable, aborting"; return 1; }
THEME_NAME="$1"
.fast-read-ini-file "$FAST_BASE_DIR/themes/$1.ini" out ""
fi
[[ -z "$OPT_SECONDARY" ]] && { [[ "$THEME_NAME" = *"overlay"* ]] && local outfile="theme_overlay.zsh" || local outfile="current_theme.zsh"; } || local outfile="secondary_theme.zsh"
[[ -z "$OPT_XCHG" && -z "$OPT_OV_XCHG" ]] && command rm -f "$FAST_WORK_DIR"/"$outfile"
# Set a zstyle and a parameter to carry theme name
if [[ -z "$OPT_SECONDARY" && -z "$OPT_XCHG" && -z "$OPT_OV_XCHG" ]]; then
[[ "$THEME_NAME" != *"overlay"* ]] && {
print -r -- 'zstyle :plugin:fast-syntax-highlighting theme "'"$THEME_NAME"'"' >>! "$FAST_WORK_DIR"/"$outfile"
print -r -- 'typeset -g FAST_THEME_NAME="'"$THEME_NAME"'"' >>! "$FAST_WORK_DIR"/"$outfile"
zstyle :plugin:fast-syntax-highlighting theme "$THEME_NAME"
typeset -g FAST_THEME_NAME="$THEME_NAME"
}
elif [[ -z "$OPT_XCHG" && -z "$OPT_OV_XCHG" ]]; then
local FAST_THEME_NAME="$THEME_NAME"
fi
# Store from which file the theme or overlay is being loaded
[[ "$THEME_NAME" != *"overlay" && -z "$OPT_OV_XCHG" ]] && FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}-path]="$THEME_PATH" || FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}-ov-path]="$THEME_PATH"
# Generate current_theme.zsh or secondary_theme.zsh, traversing ini-file associative array
local k kk
local inikey inival result result2 first_val isbg
integer ov_counter=0 first
for k in "${order[@]}"; do
first=1
for kk in ${(s. .)map[$k]} default; do
[[ "$kk" = "-" ]] && kk="$k"
(( first )) && first_val="$kk"
inikey="${out[(i)<*>_${kk}]}"
[[ -n "$inikey" ]] && {
(( !first )) && [[ -z "$OPT_QUIET" ]] && {
[[ $kk = default ]] && {
[[ "$THEME_NAME" != *"overlay"* ]] && print "Missing style: $first_val"
} || print "For style $first_val, went for fallback style $kk"
}
break
}
first=0
[[ "$THEME_NAME" = *"overlay"* ]] && break
done
# ORIG: Clear orig-style when loading a new theme, not overlay
[[ -z "$OPT_OV_XCHG" ]] && unset "FAST_HIGHLIGHT_STYLES[orig-style-$k]"
# ORIG: Restore orig-style when loading a new overlay
[[ -n "$OPT_OV_XCHG" && -n "${FAST_HIGHLIGHT_STYLES[orig-style-$k]}" ]] && { FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}$k]="${FAST_HIGHLIGHT_STYLES[orig-style-$k]}"; unset "FAST_HIGHLIGHT_STYLES[orig-style-$k]"; }
# Set only the keys provided in theme
[[ -z "$inikey" ]] && { [[ -z "$OPT_QUIET" && "$THEME_NAME" != *"overlay"* ]] && print "Missing style $first_val"; continue; }
inival="${out[$inikey]}"
if [[ "$k" = "secondary" && -z "$OPT_SECONDARY" && -n "$inival" ]]; then
fast-theme -q --secondary "$inival"
fi
result=""
if [[ $k = secondary ]]; then
result="$inival"
else
for kk in ${(s:,:)inival}
do
if [[ $kk = (none|(no-|)(bold|blink|conceal|reverse|standout|underline)) ]]; then
result+="${result:+,}$kk"
else
isbg=0
if [[ $kk = bg:* ]]; then
isbg=1
kk=${kk#bg:}
fi
if [[ $kk = (${(~j:|:)color}) || $kk = [0-9]## || $kk = \#[0-9a-fA-F](#c6,6) ]]; then
result+="${result:+,}"
(( isbg )) && result+="bg=" || result+="fg="
result+="$kk"
else
print "cannot parse style $k: unknown color or style element $kk"
fi
fi
done
fi
if [[ "$THEME_NAME" = *"overlay"* || -n "$OPT_OV_XCHG" ]]; then
(( ++ ov_counter ))
[[ -z "$OPT_XCHG$OPT_OV_XCHG" ]] && print -r -- ': ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}'"$k"']::='"$result"'}' >>! "$FAST_WORK_DIR"/"$outfile"
# ORIG: Save original value of the overwritten style
FAST_HIGHLIGHT_STYLES[orig-style-$k]=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}$k]}
# Overwrite theme's style
FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}$k]="$result"
else
[[ -z "$OPT_XCHG$OPT_OV_XCHG" ]] && print -r -- ': ${FAST_HIGHLIGHT_STYLES['"${FAST_THEME_NAME}$k"']:='"$result"'}' >>! "$FAST_WORK_DIR"/"$outfile"
FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}$k]="$result"
fi
done
# This can overwrite some of *_STYLES fields
# Re-apply overlay on top of the theme we switched to
[[ "$THEME_NAME" != *"overlay"* ]] && [[ -r "$FAST_WORK_DIR"/theme_overlay.zsh ]] && source "$FAST_WORK_DIR"/theme_overlay.zsh
zcompile $FAST_WORK_DIR/$outfile 2>/dev/null
[[ -z "$OPT_QUIET" ]] && {
if [[ "$THEME_NAME" != *"overlay"* ]]; then
print "Switched to theme \`$THEME_NAME' (current session, and future sessions)" || \
else
print "Processed the overlay ($ov_counter keys found), it is now active (for current session, and future sessions)"
fi
}
[[ -n "$OPT_TEST" ]] && {
print -zr '
# Subshell, assignments, math-mode
echo $(cat /etc/hosts |& grep -i "hello337")
local param1="text ${+variable[test]} text ${var} text"; typeset param2='"'"'other $variable'"'"'
math=$(( 10 + HISTSIZ + HISTSIZE + $SAVEHIST )) size=$(( 0 ))
# Programming-like usage, bracket matching - through distinct colors; note the backslash quoting
for (( ii = 1; ii <= size; ++ ii )); do
if [[ "${cmds[ii]} string" = "| string" ]]
then
sidx=${buffer[(in:ii:)\$\(?#[^\\\\]\)]} # find opening cmd-subst
(( sidx <= len + 100 )) && {
eidx=${buffer[(b:sidx:ii)[^\\\\]\)]} # find closing cmd-subst
}
fi
done
# Regular command-line usage
repeat 0 {
zsh -i -c "cat /etc/shells* | grep -x --line-buffered -i '"'/bin/zsh'"'"
builtin exit $return_value
fast-theme -tq default
fsh-alias -tq default-X # alias '"'"'fsh-alias=fast-theme'"'"' works just like the previous line
command -v git | grep ".+git" && echo $'"'"'Git is installed'"'"'
git checkout -m --ours /etc/shells && git status-X
gem install asciidoctor
cat <<<$PATH | tr : \\n > /dev/null 2>/usr/local
man -a fopen fopen-X
CFLAGS="-g -Wall -O0" ./configure
}
'
}
return 0
# vim:ft=zsh:et:sw=4:sts=4

View File

@ -0,0 +1,61 @@
: ${FAST_HIGHLIGHT_STYLES[freedefault]:=none}
: ${FAST_HIGHLIGHT_STYLES[freeunknown-token]:=fg=red,bold}
: ${FAST_HIGHLIGHT_STYLES[freereserved-word]:=fg=150}
: ${FAST_HIGHLIGHT_STYLES[freealias]:=fg=180}
: ${FAST_HIGHLIGHT_STYLES[freesuffix-alias]:=fg=180}
: ${FAST_HIGHLIGHT_STYLES[freebuiltin]:=fg=180}
: ${FAST_HIGHLIGHT_STYLES[freefunction]:=fg=180}
: ${FAST_HIGHLIGHT_STYLES[freecommand]:=fg=180}
: ${FAST_HIGHLIGHT_STYLES[freeprecommand]:=fg=180}
: ${FAST_HIGHLIGHT_STYLES[freecommandseparator]:=none}
: ${FAST_HIGHLIGHT_STYLES[freehashed-command]:=fg=180}
: ${FAST_HIGHLIGHT_STYLES[freepath]:=fg=166}
: ${FAST_HIGHLIGHT_STYLES[freepath_pathseparator]:=}
: ${FAST_HIGHLIGHT_STYLES[freeglobbing]:=fg=112}
: ${FAST_HIGHLIGHT_STYLES[freeglobbing-ext]:=fg=118}
: ${FAST_HIGHLIGHT_STYLES[freehistory-expansion]:=fg=blue,bold}
: ${FAST_HIGHLIGHT_STYLES[freesingle-hyphen-option]:=fg=110}
: ${FAST_HIGHLIGHT_STYLES[freedouble-hyphen-option]:=fg=110}
: ${FAST_HIGHLIGHT_STYLES[freeback-quoted-argument]:=none}
: ${FAST_HIGHLIGHT_STYLES[freesingle-quoted-argument]:=fg=150}
: ${FAST_HIGHLIGHT_STYLES[freedouble-quoted-argument]:=fg=150}
: ${FAST_HIGHLIGHT_STYLES[freedollar-quoted-argument]:=fg=150}
: ${FAST_HIGHLIGHT_STYLES[freeback-or-dollar-double-quoted-argument]:=fg=110}
: ${FAST_HIGHLIGHT_STYLES[freeback-dollar-quoted-argument]:=fg=110}
: ${FAST_HIGHLIGHT_STYLES[freeassign]:=none}
: ${FAST_HIGHLIGHT_STYLES[freeredirection]:=none}
: ${FAST_HIGHLIGHT_STYLES[freecomment]:=fg=black,bold}
: ${FAST_HIGHLIGHT_STYLES[freevariable]:=none}
: ${FAST_HIGHLIGHT_STYLES[freemathvar]:=fg=blue,bold}
: ${FAST_HIGHLIGHT_STYLES[freemathnum]:=fg=166}
: ${FAST_HIGHLIGHT_STYLES[freematherr]:=fg=red}
: ${FAST_HIGHLIGHT_STYLES[freeassign-array-bracket]:=fg=180}
: ${FAST_HIGHLIGHT_STYLES[freefor-loop-variable]:=none}
: ${FAST_HIGHLIGHT_STYLES[freefor-loop-number]:=fg=150}
: ${FAST_HIGHLIGHT_STYLES[freefor-loop-operator]:=fg=150}
: ${FAST_HIGHLIGHT_STYLES[freefor-loop-separator]:=fg=109}
: ${FAST_HIGHLIGHT_STYLES[freeexec-descriptor]:=fg=yellow,bold}
: ${FAST_HIGHLIGHT_STYLES[freehere-string-tri]:=fg=yellow}
: ${FAST_HIGHLIGHT_STYLES[freehere-string-text]:=bg=19}
: ${FAST_HIGHLIGHT_STYLES[freehere-string-var]:=fg=110,bg=19}
: ${FAST_HIGHLIGHT_STYLES[freesecondary]:=zdharma}
: ${FAST_HIGHLIGHT_STYLES[freecase-input]:=fg=180}
: ${FAST_HIGHLIGHT_STYLES[freecase-parentheses]:=fg=116}
: ${FAST_HIGHLIGHT_STYLES[freecase-condition]:=bg=19}
: ${FAST_HIGHLIGHT_STYLES[freecorrect-subtle]:=bg=55}
: ${FAST_HIGHLIGHT_STYLES[freeincorrect-subtle]:=bg=52}
: ${FAST_HIGHLIGHT_STYLES[freesubtle-separator]:=none}
: ${FAST_HIGHLIGHT_STYLES[freesubtle-bg]:=bg=18}
: ${FAST_HIGHLIGHT_STYLES[freepath-to-dir]:=fg=166,underline}
: ${FAST_HIGHLIGHT_STYLES[freepaired-bracket]:=bg=blue}
: ${FAST_HIGHLIGHT_STYLES[freebracket-level-1]:=fg=130}
: ${FAST_HIGHLIGHT_STYLES[freebracket-level-2]:=fg=70}
: ${FAST_HIGHLIGHT_STYLES[freebracket-level-3]:=fg=69}
: ${FAST_HIGHLIGHT_STYLES[freeglobal-alias]:=bg=19}
: ${FAST_HIGHLIGHT_STYLES[freesubcommand]:=fg=150}
: ${FAST_HIGHLIGHT_STYLES[freesingle-sq-bracket]:=fg=180}
: ${FAST_HIGHLIGHT_STYLES[freedouble-sq-bracket]:=fg=180}
: ${FAST_HIGHLIGHT_STYLES[freedouble-paren]:=fg=150}
: ${FAST_HIGHLIGHT_STYLES[freeoptarg-string]:=fg=150}
: ${FAST_HIGHLIGHT_STYLES[freeoptarg-number]:=fg=166}
: ${FAST_HIGHLIGHT_STYLES[freerecursive-base]:=fg=183}

View File

@ -0,0 +1,81 @@
[base]
default = none
unknown-token = 124,bold
commandseparator = none
redirection = none
here-string-tri = yellow
here-string-text = bg:19
here-string-var = 185,bg:19
exec-descriptor = yellow,bold
comment = black,bold
correct-subtle = bg:55
incorrect-subtle = bg:52
subtle-bg = bg:17
secondary = zdharma
recursive-base = 183
[command-point]
reserved-word = 146
subcommand = 146
alias = 109
suffix-alias = 109
global-alias = bg:19
builtin = 109
function = 109
command = 109
precommand = 109
hashed-command = 109
single-sq-bracket = 109
double-sq-bracket = 109
double-paren = 146
[paths]
path = 208
pathseparator =
path-to-dir = 208,underline
globbing = 220
globbing-ext = 225
[brackets]
paired-bracket = bg:blue
bracket-level-1 = 115
bracket-level-2 = 177
bracket-level-3 = 220
[arguments]
single-hyphen-option = 185
double-hyphen-option = 185
back-quoted-argument = none
single-quoted-argument = 147
double-quoted-argument = 147
dollar-quoted-argument = 147
[in-string]
; backslash in $'...'
back-dollar-quoted-argument = 185
; backslash or $... in "..." (i.e. variable in string)
back-or-dollar-double-quoted-argument = 185
[other]
variable = none
assign = none
assign-array-bracket = 109
history-expansion = blue,bold
[math]
mathvar = blue,bold
mathnum = 208
matherr = 124
[for-loop]
forvar = none
fornum = 208
; operator
foroper = 147
; separator
forsep = 109
[case]
case-input = 109
case-parentheses = 116
case-condition = bg:19

View File

@ -0,0 +1,84 @@
; default theme, also embedded in the source of fast-syntax-highlighting
[base]
default = none
unknown-token = red,bold
commandseparator = none
redirection = none
here-string-tri = yellow
here-string-text = 18
here-string-var = cyan,bg:18
exec-descriptor = yellow,bold
comment = black,bold
correct-subtle = 12
incorrect-subtle = red
subtle-separator = green
subtle-bg = bg:18
secondary = free
; recursive-base =
[command-point]
reserved-word = yellow
subcommand = yellow
alias = green
suffix-alias = green
global-alias = bg:blue
builtin = green
function = green
command = green
precommand = green
hashed-command = green
single-sq-bracket = green
double-sq-bracket = green
double-paren = yellow
[paths]
path = magenta
pathseparator =
path-to-dir = magenta,underline
globbing = blue,bold
globbing-ext = 13
[brackets]
paired-bracket = bg:blue
bracket-level-1 = green,bold
bracket-level-2 = yellow,bold
bracket-level-3 = cyan,bold
[arguments]
single-hyphen-option = cyan
double-hyphen-option = cyan
back-quoted-argument = none
single-quoted-argument = yellow
double-quoted-argument = yellow
dollar-quoted-argument = yellow
[in-string]
; backslash in $'...'
back-dollar-quoted-argument = cyan
; backslash or $... in "..."
back-or-dollar-double-quoted-argument = cyan
[other]
variable = 113
assign = none
assign-array-bracket = green
history-expansion = blue,bold
[math]
mathvar = blue,bold
mathnum = magenta
matherr = red
[for-loop]
forvar = none
fornum = magenta
; operator
foroper = yellow
; separator
forsep = yellow,bold
[case]
case-input = green
case-parentheses = yellow
case-condition = bg:blue

View File

@ -0,0 +1,81 @@
[base]
default = none
unknown-token = 124,bold
commandseparator = none
redirection = none
here-string-tri = yellow
here-string-text = underline
here-string-var = 65,underline
exec-descriptor = yellow,bold
comment = black,bold
correct-subtle = bg:55
incorrect-subtle = bg:52
subtle-bg = bg:18
secondary = zdharma
recursive-base = 183
[command-point]
reserved-word = 186
subcommand = 186
alias = 101
suffix-alias = 101
global-alias = bg:55
builtin = 101
function = 101
command = 101
precommand = 101
hashed-command = 101
single-sq-bracket = 101
double-sq-bracket = 101
double-paren = 186
[paths]
path = 107
pathseparator =
path-to-dir = 107,underline
globbing = 114
globbing-ext = 118
[brackets]
paired-bracket = bg:blue
bracket-level-1 = green,bold
bracket-level-2 = yellow,bold
bracket-level-3 = cyan,bold
[arguments]
single-hyphen-option = 65
double-hyphen-option = 65
back-quoted-argument = none
single-quoted-argument = 186
double-quoted-argument = 186
dollar-quoted-argument = 186
[in-string]
; backslash in $'...'
back-dollar-quoted-argument = 65
; backslash or $... in "..."
back-or-dollar-double-quoted-argument = 65
[other]
variable = none
assign = none
assign-array-bracket = 101
history-expansion = 114
[math]
mathvar = 114
mathnum = 107
matherr = 124
[for-loop]
forvar = none
fornum = 107
; operator
foroper = 186
; separator
forsep = 109
[case]
case-input = 101
case-parentheses = 65
case-condition = underline

View File

@ -0,0 +1,81 @@
[base]
default = none
unknown-token = red,bold
commandseparator = none
redirection = none
here-string-tri = yellow
here-string-text = bg:19
here-string-var = 110,bg:19
exec-descriptor = yellow,bold
comment = black,bold
correct-subtle = bg:55
incorrect-subtle = bg:52
subtle-bg = bg:18
secondary = zdharma
recursive-base = 183
[command-point]
reserved-word = 150
subcommand = 150
alias = 180
suffix-alias = 180
global-alias = bg:19
builtin = 180
function = 180
command = 180
precommand = 180
hashed-command = 180
single-sq-bracket = 180
double-sq-bracket = 180
double-paren = 150
[paths]
path = 166
pathseparator =
path-to-dir = 166,underline
globbing = 112
globbing-ext = 118
[brackets]
paired-bracket = bg:blue
bracket-level-1 = 130
bracket-level-2 = 70
bracket-level-3 = 69
[arguments]
single-hyphen-option = 110
double-hyphen-option = 110
back-quoted-argument = none
single-quoted-argument = 150
double-quoted-argument = 150
dollar-quoted-argument = 150
[in-string]
; backslash in $'...'
back-dollar-quoted-argument = 110
; backslash or $... in "..." (i.e. variable inside a string)
back-or-dollar-double-quoted-argument = 110
[other]
variable = none
assign = none
assign-array-bracket = 180
history-expansion = blue,bold
[math]
mathvar = blue,bold
mathnum = 166
matherr = red
[for-loop]
forvar = none
fornum = 150
; operator
foroper = 150
; separator
forsep = 109
[case]
case-input = 180
case-parentheses = 116
case-condition = bg:19

View File

@ -0,0 +1,163 @@
; X-JMnemonic theme for Fast-Syntax-Highlighting:
; https://github.com/zdharma/fast-syntax-highlighting
; Version: 1.1
;
; Copyright (c) 2018 Sebastian Gniazdowski
;
; Based on: https://www.syntaxenvy.com/0753499
;
; When I first saw the above theme upon syntaxenvy.com generated it randomly,
; I've had a quick, bold association with the Johnny Mnemonic movie. I don't
; know why, but I've decided to name the theme like this and who knows, maybe
; someone will decipher the connection one day. The theme looks suprisingly
; well IMO and maybe it's the effect of having this movie property/connection.
;
; This theme is a descent of the 40 work hours (or more) non-public theme X-Paragon,
; which was created to say `thanks' to the patrons at Patreon.com/psprint. It should
; carry the same quality.
;
; The palette - naive and CIE L*a*b conversion:
;
; main:
; #5e6466 -> 59 -> CIELab: 241
; comment:
; #434749 -> 16 -> CIELab: 238
; keyword:
; #b77c4b -> 137 -> CIELab: 173
; number, string:
; #5794a2 -> 67 -> CIELab: 66
; title, section, name, selector-id:
; #778ce0 -> 104 -> CIELab: 104
; attribute, variable, type:
; #d55383 -> 168 -> CIELab: 168
; symbol, link:
; #e66493 -> 168 -> CIELab: 168
; builtin, deletion:
; #bd5ac0 -> 133 -> CIELab: 170
; formula-bg:
; #363a3b -> 16 -> CIELab: 237
;
; Token.Literal: "#dc5be0" -> CIELab: 170 (Orchid; naive: 170)
; Token.Operator: "#677dcf" -> CIELab: 68 (SteelBlue3; naive: 68)
;
[base]
default = none
unknown-token = 196
secondary = sv-orple
recursive-base = 183
[background]
correct-subtle = bg:18
incorrect-subtle = bg:238
subtle-bg = bg:17
global-alias = bg:20
;;
;; COLOR-GROUPS
;;
[gray]
comment = 243
[pastel]
here-string-tri = 217
[no-color]
assign = none
back-quoted-argument = none
redirection = none
variable = none
[magenta-3]
dollar-quoted-argument = 173
double-quoted-argument = 173
history-expansion = 173
globbing-ext = 173
precommand = 173
[light-salmon-3]
builtin = 137
subcommand = 137
single-quoted-argument = 137
[steel-blue-3]
command = 68
double-sq-bracket = 68
double-paren = 68
single-sq-bracket = 68
[steel-blue]
reserved-word = 67
[medium-purple]
; backslash in $'...'
back-dollar-quoted-argument = 104
commandseparator = 104
single-hyphen-option = 104
[dark-khaki]
double-hyphen-option = 143
[hot-pink-3]
alias = 168
exec-descriptor = 168
function = 168
hashed-command = 168
here-string-var = 168
suffix-alias = 168
[pale-green-3]
assign-array-bracket = 114
; variable $... or backslash in "..." (i.e. variable in string)
back-or-dollar-double-quoted-argument = 114
globbing = 114
here-string-text = 114
[orchid]
path = 170
path-to-dir = 170,underline
pathseparator =
;;
;; FUNCTIONALITY-GROUPS
;;
[brackets]
paired-bracket = black,bg:216
bracket-level-1 = 117
bracket-level-2 = 217
bracket-level-3 = 220
[math]
mathvar = 68
mathnum = 173
matherr = 124
[for-loop]
forvar = 68
fornum = 173
; operator
foroper = 133
; separator
forsep = 104
[case]
case-input = 168
case-parentheses = 217
case-condition = bg:25

View File

@ -0,0 +1,83 @@
; Light theme with colors of a Sahara oasis
[base]
default = none
unknown-token = red,bold
commandseparator = none
redirection = none
here-string-tri = yellow
here-string-text = bg:19
here-string-var = 153,bg:19
exec-descriptor = yellow,bold
comment = black,bold
correct-subtle = bg:55
incorrect-subtle = bg:52
subtle-bg = bg:18
secondary = zdharma
recursive-base = 183
[command-point]
reserved-word = 150
subcommand = 150
alias = 185
suffix-alias = 185
global-alias = bg:19
builtin = 185
function = 185
command = 185
precommand = 185
hashed-command = 185
single-sq-bracket = 185
double-sq-bracket = 185
double-paren = 150
[paths]
path = 187
pathseparator =
path-to-dir = 187,underline
globbing = 180
globbing-ext = 184
[brackets]
paired-bracket = bg:blue
bracket-level-1 = 178
bracket-level-2 = 148
bracket-level-3 = 141
[arguments]
single-hyphen-option = 152
double-hyphen-option = 152
back-quoted-argument = none
single-quoted-argument = 151
double-quoted-argument = 151
dollar-quoted-argument = 151
[in-string]
; backslash in $'...'
back-dollar-quoted-argument = 153
; backslash or $... in "..." (i.e. variable inside a string)
back-or-dollar-double-quoted-argument = 153
[other]
variable = none
assign = none
assign-array-bracket = 185
history-expansion = blue,bold
[math]
mathvar = blue,bold
mathnum = 187
matherr = red
[for-loop]
forvar = none
fornum = 187
; operator
foroper = 151
; separator
forsep = 109
[case]
case-input = 185
case-parentheses = 116
case-condition = bg:19

View File

@ -0,0 +1,82 @@
; 144, 187, 110, 203
[base]
default = none
unknown-token = 196
commandseparator = 150
redirection = none
here-string-tri = yellow
here-string-text = bg:19
here-string-var = 186,bg:19
exec-descriptor = yellow,bold
comment = black,bold
correct-subtle = bg:55
incorrect-subtle = bg:52
subtle-bg = bg:17
secondary = zdharma
recursive-base = 183
[command-point]
reserved-word = 144
subcommand = 144
alias = 187
suffix-alias = 187
global-alias = bg:19
builtin = 150
function = 187
command = 187
precommand = 187
hashed-command = 187
single-sq-bracket = 150
double-sq-bracket = 150
double-paren = 144
[paths]
path = 110
pathseparator =
path-to-dir = 110,underline
globbing = 220
globbing-ext = 225
[brackets]
paired-bracket = bg:blue
bracket-level-1 = 115
bracket-level-2 = 177
bracket-level-3 = 220
[arguments]
single-hyphen-option = 185
double-hyphen-option = 185
back-quoted-argument = none
single-quoted-argument = 110
double-quoted-argument = 110
dollar-quoted-argument = 110
[in-string]
; backslash in $'...'
back-dollar-quoted-argument = 186
; backslash or $... in "..." (i.e. variable in string)
back-or-dollar-double-quoted-argument = 186
[other]
variable = none
assign = none
assign-array-bracket = 187
history-expansion = blue,bold
[math]
mathvar = 150
mathnum = 110
matherr = 196
[for-loop]
forvar = 71
fornum = 110
; operator
foroper = 203
; separator
forsep = 147
[case]
case-input = 187
case-parentheses = 116
case-condition = bg:19

View File

@ -0,0 +1,100 @@
; https://www.syntaxenvy.com/0073437
;
; comment:
; #363355 -> 61
; keyword:
; #dda69f -> 181 (138)
; number, string:
; #ca887e -> 174 (173)
; title, section, name, selector-id:
; #b3afd9 -> 146 (146)
; attribute, variable, type:
; #be85c0 -> 139 (140)
; symbol, link:
; #d6a2d8 -> 182 (182)
; builtin, deletion:
; #969c77 -> 108 (108)
; formula-bg:
; #211f37 -> 16 (17)
[base]
default = none
unknown-token = 124
commandseparator = 146
redirection = none
here-string-tri = 138
here-string-text = bg:25
here-string-var = 140,bg:25
exec-descriptor = 140
comment = 61
correct-subtle = bg:55
incorrect-subtle = bg:52
subtle-bg = bg:17
secondary = clean
recursive-base = 186
[command-point]
reserved-word = 138
subcommand = 182
alias = 140
suffix-alias = 140
global-alias = bg:17
builtin = 173
function = 140
command = 108
precommand = 138
hashed-command = 140
single-sq-bracket = 173
double-sq-bracket = 173
double-paren = 138
[paths]
path = 182
pathseparator =
path-to-dir = 182,underline
globbing = 138
globbing-ext = 141
[brackets]
paired-bracket = bg:blue
bracket-level-1 = 173
bracket-level-2 = 177
bracket-level-3 = 220
[arguments]
single-hyphen-option = 140
double-hyphen-option = 140
back-quoted-argument = none
single-quoted-argument = 173
double-quoted-argument = 173
dollar-quoted-argument = 173
[in-string]
; backslash in $'...'
back-dollar-quoted-argument = 146
; backslash or $... in "..." (i.e. variable in string)
back-or-dollar-double-quoted-argument = 140
[other]
variable = none
assign = none
assign-array-bracket = 182
history-expansion = blue,bold
[math]
mathvar = 140
mathnum = 173
matherr = 124
[for-loop]
forvar = 140
fornum = 173
; operator
foroper = 147
; separator
forsep = 182
[case]
case-input = 140
case-parentheses = 17
case-condition = bg:25

View File

@ -0,0 +1,100 @@
; https://www.syntaxenvy.com/0854668
;
; comment:
; #5b4e3f -> 58
; keyword:
; #a1f2b2 -> 157
; number, string:
; #91cf9e -> 115 (114)
; title, section, name, selector-id:
; #dadff0 -> 189
; attribute, variable, type:
; #debb91 -> 180
; symbol, link:
; #f1dcc6 -> 224
; builtin, deletion:
; #95cbc1 -> 115
; formula:
; #3f352a -> 16
[base]
default = none
unknown-token = 124
commandseparator = 189
redirection = none
here-string-tri = 157
here-string-text = bg:25
here-string-var = 180,bg:25
exec-descriptor = 180
comment = 58
correct-subtle = bg:55
incorrect-subtle = bg:52
subtle-bg = bg:17
secondary = zdharma
recursive-base = 183
[command-point]
reserved-word = 157
subcommand = 224
alias = 180
suffix-alias = 180
global-alias = bg:58
builtin = 115
function = 180
command = 180
precommand = 157
hashed-command = 180
single-sq-bracket = 115
double-sq-bracket = 115
double-paren = 157
[paths]
path = 224
pathseparator =
path-to-dir = 224,underline
globbing = 157
globbing-ext = 159
[brackets]
paired-bracket = bg:blue
bracket-level-1 = 115
bracket-level-2 = 177
bracket-level-3 = 220
[arguments]
single-hyphen-option = 180
double-hyphen-option = 180
back-quoted-argument = none
single-quoted-argument = 114
double-quoted-argument = 114
dollar-quoted-argument = 114
[in-string]
; backslash in $'...'
back-dollar-quoted-argument = 189
; backslash or $... in "..." (i.e. variable in string)
back-or-dollar-double-quoted-argument = 180
[other]
variable = none
assign = none
assign-array-bracket = 224
history-expansion = blue,bold
[math]
mathvar = 180
mathnum = 114
matherr = 124
[for-loop]
forvar = 180
fornum = 114
; operator
foroper = 147
; separator
forsep = 224
[case]
case-input = 180
case-parentheses = 58
case-condition = bg:25

View File

@ -0,0 +1,81 @@
[base]
default = none
unknown-token = red,bold
commandseparator = none
redirection = none
here-string-tri = 141
here-string-text = bg:19
here-string-var = 177,bg:19
exec-descriptor = yellow,bold
comment = black,bold
correct-subtle = bg:55
incorrect-subtle = bg:52
subtle-bg = bg:17
secondary = safari
recursive-base = 186
[command-point]
reserved-word = 146
reserved-word = 146
alias = 63
suffix-alias = 63
global-alias = bg:19
builtin = 63
function = 63
command = 63
precommand = 63
hashed-command = 63
single-sq-bracket = 63
double-sq-bracket = 63
double-paren = 146
[paths]
path = 154
pathseparator =
path-to-dir = 154,underline
globbing = 114
globbing-ext = 153
[brackets]
paired-bracket = bg:blue
bracket-level-1 = 117
bracket-level-2 = 141
bracket-level-3 = 90
[arguments]
single-hyphen-option = 177
double-hyphen-option = 177
back-quoted-argument = none
single-quoted-argument = 146
double-quoted-argument = 146
dollar-quoted-argument = 146
[in-string]
; backslash in $'...'
back-dollar-quoted-argument = 177
; backslash or $... in "..."
back-or-dollar-double-quoted-argument = 177
[other]
variable = none
assign = none
assign-array-bracket = 63
history-expansion = blue,bold
[math]
mathvar = blue,bold
mathnum = 154
matherr = red
[for-loop]
forvar = none
fornum = 154
; operator
foroper = 146
; separator
forsep = 109
[case]
case-input = 63
case-parentheses = 141
case-condition = bg:19

View File

@ -0,0 +1,29 @@
# vim:ft=zsh:et:sw=4
(( next_word = 2 | 8192 ))
[[ "$__arg_type" = 3 ]] && return 2
local __first_call="$1" __wrd="${2%%=*}" __start_pos="$3" __end_pos="$4"
if (( __first_call )) || [[ "$2" = -* ]]; then
return 1
else
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
elif (( $+aliases[(e)$__wrd] )) || (( ${+galiases[(e)$__wrd]} )); then
(( __start=__start_pos-${#PREBUFFER}, __end=__start_pos+${#__wrd}-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}")
elif (( $+functions[(e)$__wrd] )) || (( $+builtins[(e)$__wrd] )) || (( $+commands[(e)$__wrd] )) || (( $reswords[(Ie)$__wrd] )); then
(( __start=__start_pos-${#PREBUFFER}, __end=__start_pos+${#__wrd}-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
else
return 1
fi
if [[ "$__wrd" != "$2" ]]; then
return 1
fi
fi
(( this_word = next_word ))
_start_pos=$_end_pos
return 0

View File

@ -0,0 +1,104 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Tracks autoload command - highlights function names if they exist somewhere
# in $fpath. Also warns that the autoloaded function is already defined.
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
#
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg; the token can be eg.: "grep"
#
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
#
# $4 - a private copy of $_end_pos from the above scope
#
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style __chars
integer __idx1 __idx2
local -a __results __deserialized __noshsplit
# First call, i.e. command starts, i.e. "grep" token etc.
(( __first_call )) && {
FAST_HIGHLIGHT[chroma-autoload-counter]=0
FAST_HIGHLIGHT[chroma-autoload-counter-all]=1
FAST_HIGHLIGHT[chroma-autoload-message]=""
#FAST_HIGHLIGHT[chroma-autoload-message-shown]=""
[[ -z ${FAST_HIGHLIGHT[chroma-autoload-message-shown-at]} ]] && FAST_HIGHLIGHT[chroma-autoload-message-shown-at]=0
FAST_HIGHLIGHT[chroma-autoload-elements]=""
__style=${FAST_THEME_NAME}command
} || {
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
(( FAST_HIGHLIGHT[chroma-autoload-counter-all] += 1, __idx2 = FAST_HIGHLIGHT[chroma-autoload-counter-all] ))
# Following call, i.e. not the first one.
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if [[ "$__wrd" = [-+]* ]]; then
# Detected option, add style for it.
[[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \
__style=${FAST_THEME_NAME}single-hyphen-option
else
# Count non-option tokens.
(( FAST_HIGHLIGHT[chroma-autoload-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-autoload-counter] ))
if [[ $__wrd != (\$|\"\$)* && $__wrd != (/|\"/|\'/)* && $__wrd != \`* ]]; then
__results=( ${^fpath}/$__wrd(N) )
__deserialized=( "${(Q@)${(z@)FAST_HIGHLIGHT[chroma-fpath_peq-elements]}}" )
__results+=( ${^__deserialized}/$__wrd(N) )
[[ "${#__results}" -gt 0 ]] && {
__style=${FAST_THEME_NAME}correct-subtle
__deserialized=( "${(Q@)${(z@)FAST_HIGHLIGHT[chroma-autoload-elements]}}" )
[[ -z "${__deserialized[1]}" && ${#__deserialized} -eq 1 ]] && __deserialized=()
# Cannot use ${abc:+"$abc"} trick with ${~...}, so handle most
# cases of the possible shwordsplit through an additional array
__noshsplit=( ${~__wrd} )
__deserialized+=( "${(j: :)__noshsplit}" )
FAST_HIGHLIGHT[chroma-autoload-elements]="${(j: :)${(q@)__deserialized}}"
# Make the function defined for big-loop's *main-type mechanism
__fast_highlight_main__command_type_cache[${(j: :)__noshsplit}]="function"
} || __style=${FAST_THEME_NAME}incorrect-subtle
fi
if (( ${+functions[${(Q)__wrd}]} )); then
FAST_HIGHLIGHT[chroma-autoload-message]+="Warning: Function ${(Q)__wrd} already defined (e.g. loaded)"$'\n'
fi
fi
# Display only when processing last autoload argument
if (( ${#${(z)BUFFER}} == FAST_HIGHLIGHT[chroma-autoload-counter-all] )); then
# Display only if already shown message differs or when it timeouts
if [[ ${FAST_HIGHLIGHT[chroma-autoload-message]} != ${FAST_HIGHLIGHT[chroma-autoload-message-shown]} ||
$(( EPOCHSECONDS - FAST_HIGHLIGHT[chroma-autoload-message-shown-at] )) -gt 7
]]; then
FAST_HIGHLIGHT[chroma-autoload-message-shown]=${FAST_HIGHLIGHT[chroma-autoload-message]}
FAST_HIGHLIGHT[chroma-autoload-message-shown-at]=$EPOCHSECONDS
zle -M "${FAST_HIGHLIGHT[chroma-autoload-message]}"
fi
fi
}
# Add region_highlight entry (via `reply' array).
#
# This is a common place of adding such entry, but any above code
# can do it itself and skip setting __style to disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through (no return 1 occured), do obligatory things ourselves.
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,22 @@
# vim:ft=zsh:et:sw=4
(( next_word = 2 | 8192 ))
[[ "$__arg_type" = 3 ]] && return 2
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
if (( __first_call )) || [[ "$__wrd" = -* ]]; then
return 1
else
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
if [[ -d "${XDG_CONFIG_HOME:-$HOME/.config}/autorandr/$__wrd" ]] then
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}")
fi
fi
(( this_word = next_word ))
_start_pos=$_end_pos
return 0

View File

@ -0,0 +1,108 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
#
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg; the token can be eg.: "grep"
#
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
#
# $4 - a private copy of $_end_pos from the above scope
#
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style __chars __val __style2
integer __idx1 __idx2
# First call, i.e. command starts, i.e. "grep" token etc.
(( __first_call )) && {
FAST_HIGHLIGHT[chroma-awk-counter]=0
FAST_HIGHLIGHT[chroma-awk-f-seen]=0
return 1
} || {
# Following call, i.e. not the first one.
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if [[ "$__wrd" = -* ]]; then
# Detected option, add style for it.
[[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \
__style=${FAST_THEME_NAME}single-hyphen-option
[[ "$__wrd" = "-f" ]] && FAST_HIGHLIGHT[chroma-awk-f-seen]=1
else
# Count non-option tokens.
(( FAST_HIGHLIGHT[chroma-awk-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-awk-counter] ))
# First non-option token is the pattern (regex), we will
# highlight it.
if (( FAST_HIGHLIGHT[chroma-awk-counter] == 1 && FAST_HIGHLIGHT[chroma-awk-f-seen] == 0 )); then
if print -r -- "${(Q)__wrd}" | gawk --source 'BEGIN { exit } END { exit 0 }' -f - >/dev/null 2>&1; then
__style2="${FAST_THEME_NAME}subtle-bg"
else
__style2="${FAST_THEME_NAME}incorrect-subtle"
fi
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style2]}")
# Highlight keywords
FSH_LIST=()
: "${__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) ))}";
for __val in "${FSH_LIST[@]}" ; do
[[ ${__wrd[${__val%%;;*}]} = [a-zA-Z0-9_] || ${__wrd[${__val##*;;}+1]} = [a-zA-Z0-9_] ]] && continue
__idx1=$(( __start_pos + ${__val%%;;*} ))
__idx2=__idx1+${__val##*;;}-${__val%%;;*}+1
(( __start=__idx1-${#PREBUFFER}, __end=__idx2-${#PREBUFFER}-1, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}reserved-word]},${FAST_HIGHLIGHT_STYLES[$__style2]}")
done
# Highlight regex characters
__chars="*+\\)(\{\}[]^"
__idx1=__start_pos
__idx2=__start_pos
while [[ "$__wrd" = (#b)[^$__chars]#([\\][\\])#((+|\*|\[|\]|\)|\(|\^|\}|\{)|[\\](+|\*|\[|\]|\)|\(|\^|\{|\}))(*) ]]; do
if [[ -n "${match[3]}" ]]; then
__idx1+=${mbegin[3]}-1
__idx2=__idx1+${mend[3]}-${mbegin[3]}+1
(( __start=__idx1-${#PREBUFFER}, __end=__idx2-${#PREBUFFER}, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}mathnum]},${FAST_HIGHLIGHT_STYLES[$__style2]}")
__idx1=__idx2
else
__idx1+=${mbegin[5]}-1
fi
__wrd="${match[5]}"
done
elif (( FAST_HIGHLIGHT[chroma-awk-counter] >= 2 || FAST_HIGHLIGHT[chroma-awk-f-seen] == 1 )); then
FAST_HIGHLIGHT[chroma-awk-f-seen]=0
# Handle paths, etc. normally - just pass-through to the big
# highlighter (the main FSH highlighter, used before chromas).
return 1
fi
fi
}
# Add region_highlight entry (via `reply' array).
#
# This is a common place of adding such entry, but any above
# code can do it itself (and it does) and skip setting __style
# to disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through (no return 1 occured), do obligatory things ourselves.
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,90 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Chroma function for command `docker'. It verifies command line, by denoting
# wrong and good arguments by color. Currently implemented: verification of
# image IDs passed to: docker image rm <ID>.
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
# $4 - a private copy of $_end_pos from the above scope
#
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style
integer __idx1 __idx2
local -a __lines_list
(( __first_call )) && {
# Called for the first time - new command
# FAST_HIGHLIGHT is used because it survives between calls, and
# allows to use a single global hash only, instead of multiple
# global variables
FAST_HIGHLIGHT[chroma-docker-counter]=0
FAST_HIGHLIGHT[chroma-docker-got-subcommand]=0
FAST_HIGHLIGHT[chroma-docker-subcommand]=""
FAST_HIGHLIGHT[chrome-docker-got-msg1]=0
return 1
} || {
# Following call, i.e. not the first one
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
if [[ "$__wrd" = -* && ${FAST_HIGHLIGHT[chroma-docker-got-subcommand]} -eq 0 ]]; then
__style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option}
else
if (( FAST_HIGHLIGHT[chroma-docker-got-subcommand] == 0 )); then
FAST_HIGHLIGHT[chroma-docker-got-subcommand]=1
FAST_HIGHLIGHT[chroma-docker-subcommand]="$__wrd"
__style=${FAST_THEME_NAME}subcommand
(( FAST_HIGHLIGHT[chroma-docker-counter] += 1 ))
else
__wrd="${__wrd//\`/x}"
__arg="${__arg//\`/x}"
__wrd="${(Q)__wrd}"
if [[ "${FAST_HIGHLIGHT[chroma-docker-subcommand]}" = "image" ]]; then
[[ "$__wrd" != -* ]] && {
(( FAST_HIGHLIGHT[chroma-docker-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-docker-counter] ))
if (( __idx1 == 2 )); then
__style=${FAST_THEME_NAME}subcommand
elif (( __idx1 == 3 )); then
.fast-run-command "docker images -q" chroma-docker-list ""
[[ -n "${__lines_list[(r)$__wrd]}" ]] && {
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}")
} || {
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
}
fi
} || __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option}
else
return 1
fi
fi
fi
}
# Add region_highlight entry (via `reply' array)
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through, do obligatory things ourselves
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,120 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Example chroma function. It colorizes first two arguments as `builtin' style,
# third and following arguments as `globbing' style. First two arguments may
# be "strings", they will be passed through to normal higlighter (by returning 1).
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
#
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg; the token can be eg.: "grep"
#
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
#
# $4 - a private copy of $_end_pos from the above scope
#
#
# Overall functioning is: when command "example" is occured, this function
# is called with $1 == 1, it ("example") is the first token ($2), then for any
# following token, this function is called with $1 == 0, until end of command
# is occured (i.e. till enter is pressed or ";" is put into source, or the
# command line simply ends).
#
# Other tips are:
# - $CURSOR holds cursor position
# - $BUFFER holds whole command line buffer
# - $LBUFFER holds command line buffer that is left from the cursor, i.e. it's a
# BUFFER substring 1 .. $CURSOR
# - $RBUFFER is the same as LBUFFER but holds part of BUFFER right to the cursor
#
# The function receives $BUFFER but via sequence of tokens, which are shell words,
# e.g. "a b c" is a shell word, while a b c are 3 shell words.
#
# FAST_HIGHLIGHT is a friendly hash array which allows to store strings without
# creating global parameters (variables). If you need hash, just use it first
# declaring, under some distinct name like: typeset -gA CHROMA_EXPLE_DICT.
# Remember to reset the hash and others at __first_call == 1, so that you have
# a fresh state for new command.
# Keep chroma-takever state meaning: until ;, handle highlighting via chroma.
# So the below 8192 assignment takes care that next token will be routed to chroma.
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style
integer __idx1 __idx2
(( __first_call )) && {
# Called for the first time - new command.
# FAST_HIGHLIGHT is used because it survives between calls, and
# allows to use a single global hash only, instead of multiple
# global string variables.
FAST_HIGHLIGHT[chroma-example-counter]=0
# Set style for region_highlight entry. It is used below in
# '[[ -n "$__style" ]] ...' line, which adds highlight entry,
# like "10 12 fg=green", through `reply' array.
#
# Could check if command `example' exists and set `unknown-token'
# style instead of `command'
__style=${FAST_THEME_NAME}command
} || {
# Following call, i.e. not the first one
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
if [[ "$__wrd" = -* ]]; then
# Detected option, add style for it.
[[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \
__style=${FAST_THEME_NAME}single-hyphen-option
else
# Count non-option tokens
(( FAST_HIGHLIGHT[chroma-example-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-example-counter] ))
# Colorize 1..2 as builtin, 3.. as glob
if (( FAST_HIGHLIGHT[chroma-example-counter] <= 2 )); then
if [[ "$__wrd" = \"* ]]; then
# Pass through, fsh main code will do the highlight!
return 1
else
__style=${FAST_THEME_NAME}builtin
fi
else
__style=${FAST_THEME_NAME}globbing
fi
fi
}
# Add region_highlight entry (via `reply' array).
# If 1 will be added to __start_pos, this will highlight "oken".
# If 1 will be subtracted from __end_pos, this will highlight "toke".
# $PREBUFFER is for specific situations when users does command \<ENTER>
# i.e. when multi-line command using backslash is entered.
#
# This is a common place of adding such entry, but any above code can do
# it itself (and it does in other chromas) and skip setting __style to
# this way disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through, do obligatory things ourselves.
# _start_pos=$_end_pos advainces pointers in command line buffer.
#
# To pass through means to `return 1'. The highlighting of
# this single token is then done by fast-syntax-highlighting's
# main code and chroma doesn't have to do anything.
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,40 @@
# vim:ft=zsh:et:sw=4
(( next_word = 2 | 8192 ))
[[ "$__arg_type" = 3 ]] && return 2
local __first_call="$1" __wrd="${(Q)2}" __start_pos="$3" __end_pos="$4"
local __style
if (( __first_call )); then
FAST_HIGHLIGHT[chroma-fast-theme-first]=0
return 1
elif (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
elif (( ${FAST_HIGHLIGHT[chroma-fast-theme-first]} )) || [[ $__wrd = -* ]]; then
return 1
else
FAST_HIGHLIGHT[chroma-fast-theme-first]=1
fi
if [[ "$__wrd" = */* || "$__wrd" = (XDG|LOCAL|HOME|OPT):* ]]; then
__wrd="${${__wrd/(#s)XDG:/${${XDG_CONFIG_HOME:-$HOME/.config}%/}/fsh/}%.ini}.ini"
__wrd="${${__wrd/(#s)LOCAL://usr/local/share/fsh/}%.ini}.ini"
__wrd="${${__wrd/(#s)HOME:/$HOME/.fsh/}%.ini}.ini"
__wrd="${${__wrd/(#s)OPT://opt/local/share/fsh/}%.ini}.ini"
__wrd=${~__wrd} # allow user to quote ~
else
__wrd="$FAST_BASE_DIR/themes/$__wrd.ini"
fi
if [[ -f $__wrd ]]; then
__style=${FAST_THEME_NAME}path
else
__style=${FAST_THEME_NAME}incorrect-subtle
fi
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
(( this_word = next_word ))
_start_pos=$_end_pos
return 0

View File

@ -0,0 +1,61 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# This chroma does a narrow, obscure but prestigious parsing of fpath+=( elem1
# elem2 ... ) construct to provide *the* *future* contents of $fpath to
# -autoload.ch, so that it can detect functions in those provided directories
# `elem1', `elem2', etc. and highlight the functions with `correct-subtle'
# instead of `incorrect-subtle'. Basically all thit is for command-lines like:
#
# % fpath+=( `pwd` ); autoload my-fun-from-PWD
# Keep chroma-takever state meaning: until ; or similar (see $__arg_type below)
# The 8192 sum takes care that the next token will be routed to this chroma
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local -a deserialized
(( __first_call )) && {
case $__wrd in
(fpath=\()
FAST_HIGHLIGHT[fpath_peq_mode]=1
;;
(fpath+=\()
FAST_HIGHLIGHT[fpath_peq_mode]=2
;;
(FPATH=)
FAST_HIGHLIGHT[fpath_peq_mode]=4
;;
(FPATH+=)
FAST_HIGHLIGHT[fpath_peq_mode]=8
;;
esac
if (( FAST_HIGHLIGHT[fpath_peq_mode] & 5 )); then
FAST_HIGHLIGHT[chroma-fpath_peq-elements]="! ${FAST_HIGHLIGHT[chroma-fpath_peq-elements]}"
fi
return 1
} || {
# Following call, i.e. not the first one
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
[[ "$__wrd" != ")" ]] && {
deserialized=( "${(Q@)${(z@)FAST_HIGHLIGHT[chroma-fpath_peq-elements]}}" )
[[ -z "${deserialized[1]}" && ${#deserialized} -eq 1 ]] && deserialized=()
# Support ~ and $VAR, for [a-zA-Z_][a-ZA-Z0-9_]# characters in "VAR"
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}}}}" )
FAST_HIGHLIGHT[chroma-fpath_peq-elements]="${(j: :)${(q@)deserialized}}"
}
return 1
}
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,954 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Chroma function for command `git'. It colorizes the part of command
# line that holds `git' invocation.
(( FAST_HIGHLIGHT[-git.ch-chroma-def] )) && return 1
FAST_HIGHLIGHT[-git.ch-chroma-def]=1
typeset -gA fsh__git__chroma__def
fsh__git__chroma__def=(
##
## No subcommand
##
## {{{
subcmd:NULL "NULL_0_opt"
NULL_0_opt "(-C|--exec-path=|--git-dir=|--work-tree=|--namespace=|--super-prefix=)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-ARG-action
|| -c
<<>> __style=\${FAST_THEME_NAME}single-hyphen-option // NO-OP
<<>> __style=\${FAST_THEME_NAME}optarg-string // NO-OP
|| (--version|--help|--html-path|--man-path|--info-path|-p|--paginate|
-P|--no-pager|--no-replace-objects|--bare)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
"subcommands" "::→chroma/-git-get-subcommands" # run a function (the :: causes this) and use `reply'
#"subcommands" "(fetch|pull)" # run a function (the :: causes this) and use `reply'
"subcmd-hook" "→chroma/-git-check-if-alias"
"subcommands-blacklist" "mv,other"
## }}}
##
## `FETCH'
##
## {{{
subcmd:fetch "FETCH_MULTIPLE_0_opt^ // FETCH_ALL_0_opt^ // FETCH_0_opt //
REMOTE_GR_1_arg // REF_#_arg // NO_MATCH_#_opt"
# Special options (^ - has directives, currently - an :add and :del directive)
"FETCH_MULTIPLE_0_opt^" "
--multiple
<<>> __style=\${FAST_THEME_NAME}double-hyphen-option // NO-OP
|| --multiple:add
<<>> REMOTE_GR_#_arg
|| --multiple:del
<<>> REMOTE_GR_1_arg // REF_#_arg" # when --multiple is passed, then
# there is no refspec argument, only remotes-ids
# follow unlimited # of them, hence the # in the
# REMOTE_GR_#_arg
# Special options (^ - has directives - an :del-directive)
"FETCH_ALL_0_opt^" "
--all
<<>> __style=\${FAST_THEME_NAME}double-hyphen-option // NO-OP
|| --all:del
<<>> REMOTE_GR_1_arg // REF_#_arg" # --all can be only followed by options
# FETCH_0_opt. FETCH-options (FETCH is an identifier) at position 0 ->
# -> before any argument
FETCH_0_opt "
(--depth=|--deepen=|--shallow-exclude=|--shallow-since=|--receive-pack=|
--refmap=|--recurse-submodules=|-j|--jobs=|--submodule-prefix=|
--recurse-submodules-default=|-o|--server-option=|--upload-pack|
--negotiation-tip=)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-ARG-action
|| (--help|--all|-a|--append|--unshallow|--update-shallow|--dry-run|-f|--force|
-k|--keep|--multiple|-p|--prune|-n|--no-tags|-t|--tags|--no-recurse-submodules|
-u|--update-head-ok|-q|--quiet|-v|--verbose|--progress|
-4|--ipv4|-6|--ipv6)
<<>> __style=\${FAST_THEME_NAME}single-hyphen-option // NO-OP"
# Above: note the two <<>>-separated blocks for options that have
# some arguments the second pair of action/handler is being
# run when an option argument is occurred (first one: the option
# itself). If there is only one <<>>-separated block, then the option
# is set to be argument-less. The argument is a) -o/--option argument
# and b) -o/--option=argument.
REMOTE_GR_1_arg "NO-OP // ::→chroma/-git-verify-remote-or-group" # This definition is generic, reused later
"REF_#_arg" "NO-OP // ::→chroma/-git-verify-ref" # This too
"REMOTE_GR_#_arg" "NO-OP // ::→chroma/-git-verify-remote-or-group" # and this too
# The hash `#' above denotes: an argument at any position
# It will nicely match any following (above the first explicitly
# numbered ones) arguments passed when using --multiple
# A generic action
NO_MATCH_\#_opt "* <<>> __style=\${FAST_THEME_NAME}incorrect-subtle // NO-OP"
NO_MATCH_\#_arg "__style=\${FAST_THEME_NAME}incorrect-subtle // NO-OP"
## }}}
##
## PUSH
##
## {{{
subcmd:push "PUSH_0_opt // REMOTE_1_arg // REF_#_arg // NO_MATCH_#_opt"
PUSH_0_opt "
(--receive-pack=|--exec=|--repo=|--push-option=|--signed=|
--force-with-lease=|--signed=|--recurse-submodules=)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-ARG-action
|| (--help|--all|--mirror|--tags|--follow-tags|--atomic|-n|--dry-run|
--porcelain|--delete|--tags|--follow-tags|--signed|--no-signed|
--atomic|--no-atomic|-o|--push-option|--force-with-lease|
--no-force-with-lease|-f|--force|-u|--set-upstream|--thin|
--no-thin|-q|--quiet|-v|--verbose|--progress|--no-recurse-submodules|
--verify|--no-verify|-4|--ipv4|-6|--ipv6)
<<>> __style=\${FAST_THEME_NAME}single-hyphen-option // NO-OP"
REMOTE_1_arg "NO-OP // ::→chroma/-git-verify-remote" # This definition is generic, reused later
### }}}
##
## PULL
##
## {{{
subcmd:pull "PULL_0_opt // REMOTE_1_arg // REF_#_arg // NO_MATCH_#_opt"
PULL_0_opt "
(--recurse-submodules=|-S|--gpg-sign=|--log=|-s|--strategy=|-X|
--strategy-option=|--rebase=|--depth=|--deepen=|--shallow-exclude=|
--shallow-since=|--negotiation-tip|--upload-pack|-o|--server-option=|
--no-recurse-submodules=)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-ARG-action
|| (--help|-q|--quiet|-v|--verbose|--progress|--no-recurse-submodules|
--commit|--no-commit|--edit|--no-edit|--ff|--no-ff|--ff-only|
--log|--no-log|--signoff|--no-signoff|--stat|-n|--no-stat|--squash|
--no-squash|--verify-signatures|--no-verify-signatures|--summary|
--no-summary|--allow-unrelated-histories|-r|--rebase|--no-rebase|
--autostash|--no-autostash|--all|-a|--append|--unshallow|
--update-shallow|-f|--force|-k|--keep|--no-tags|-u|--update-head-ok|
--progress|-4|--ipv4|-6|--ipv6|--recurse-submodules)
<<>> __style=\${FAST_THEME_NAME}single-hyphen-option // NO-OP"
## }}}
##
## COMMIT
##
## {{{
subcmd:commit "COMMIT_#_opt // FILE_#_arg // NO_MATCH_#_opt"
"COMMIT_#_opt" "
(-m|--message=|-am)
<<>> NO-OP // ::→chroma/-git-commit-msg-opt-action
<<>> NO-OP // ::→chroma/-git-commit-msg-opt-ARG-action
|| (--help|-a|--all|-p|--patch|--reset-author|--short|--branch|
--porcelain|--long|-z|--null|-s|--signoff|-n|--no-verify|
--allow-empty|--allow-empty-message|-e|--edit|--no-edit|
--amend|--no-post-rewrite|-i|--include|-o|--only|--untracked-files|
-v|--verbose|-q|--quiet|--dry-run|--status|--no-status|--no-gpg-sign)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
|| (-C|--reuse-message=|-c|--reedit-message=|--fixup=|--squash=|
-F|--file=|--author=|--date=|-t|--template=|--cleanup=|
-u|--untracked-files=|-S|--gpg-sign=)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-ARG-action"
# A generic action
"FILE_#_arg" "NO-OP // ::→chroma/-git-verify-file"
## }}}
##
## MERGE
##
## {{{
subcmd:merge "MERGE_0_opt // COMMIT_#_arg"
MERGE_0_opt
"(-m)
<<>> NO-OP // ::→chroma/-git-commit-msg-opt-action
<<>> NO-OP // ::→chroma/-git-commit-msg-opt-ARG-action
(-S|--gpg-sign=|--log=|-e|--strategy=|-X|--strategy-option=|-F|
--file)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-ARG-action
|| (--help|--commit|--no-commit|-e|--edit|--no-edit|--ff|--no-ff|--ff-only|
--log|--no-log|--signoff|--no-signoff|-n|--stat|--no-stat|--squash|
--no-squash|--verify-signatures|--no-verify-signatures|--summary|
--no-summary|-q|--quiet|-v|--verbose|--progress|--no-progress|
--allow-unrelated-histories|--rerere-autoupdate|--no-rerere-autoupdate|
--abort|--continue)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
COMMIT_\#_arg "NO-OP // ::→chroma/-git-verify-commit"
## }}}
##
## RESET
##
## {{{
subcmd:reset "RESET_0_opt^ // RESET_0_opt // RESET_#_arg // NO_MATCH_#_opt"
"RESET_0_opt^" "
(--soft|--mixed|--hard|--merge|--keep)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
|| (--soft|--mixed|--hard|--merge|--keep):del
<<>> RESET_0_opt // RESET_#_arg
|| (--soft|--mixed|--hard|--merge|--keep):add
<<>> RESET_1_arg // NO_MATCH_#_arg
"
RESET_0_opt "
(-q|-p|--patch)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
RESET_1_arg "NO-OP // ::→chroma/-git-verify-commit"
"RESET_#_arg" "NO-OP // ::→chroma/-git-RESET-verify-commit-or-file"
## }}}
##
## REVERT
##
## {{{
subcmd:revert "REVERT_SEQUENCER_0_opt^ // REVERT_0_opt // REVERT_#_arg // NO_MATCH_#_opt"
REVERT_0_opt "
(-m|--mainline|-S|--gpg-sign=|--strategy=|-X|--strategy-option=)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-ARG-action
|| (-e|--edit|--no-edit|-n|--no-commit|-s|--signoff)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
"REVERT_SEQUENCER_0_opt^" "
(--continue|--quit|--abort)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
|| (--continue|--quit|--abort):del
<<>> REVERT_0_opt // REVERT_#_arg
|| (--continue|--quit|--abort):add
<<>> NO_MATCH_#_arg"
"REVERT_#_arg" "NO-OP // ::→chroma/-git-verify-commit"
## }}}
##
## DIFF
##
## TODO: When a second argument is also a path and it points to a directory, then
## git appends the previous file name to it good to implement this too
## {{{
subcmd:diff "DIFF_NO_INDEX_0_opt^ // DIFF_0_opt // COMMIT_FILE_DIR_#_arg // NO_MATCH_#_opt"
"DIFF_NO_INDEX_0_opt^" "
--no-index
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
|| --no-index:del
<<>> COMMIT_FILE_DIR_#_arg
|| --no-index:add
<<>> FILE_1_arg // FILE_2_arg // NO_MATCH_#_arg"
DIFF_0_opt "
(-U|--unified=|--anchored=|--diff-algorithm=|--stat=|--dirstat|
--submodule=|--color=|--color-moved=|--color-moved-ws=|--word-diff=|
--word-diff-regex=|--color-words=|--ws-error-highlight=|--abbrev=|
-B|--break-rewrites=|-M|--find-renames=|-C|--find-copies=|-l|
--diff-filter=|-S|-G|--find-object=|--relative=|-O|--relative=|
--inter-hunk-context=|--ignore-submodules=|--src-prefix=|--dst-prefix=|
--line-prefix=)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-ARG-action
|| (-p|--patch|-u|-s|--no-patch|--raw|--patch-with-raw|--indent-heuristic|
--no-indent-heuristic|--minimal|--patience|--histogram|--stat|
--compact-summary|--numstat|--shortstat|--dirstat|--summary|
--patch-with-stat|-z|--name-only|--name-status|--submodule|--no-color|
--color-moved|--word-diff|--color-words|--no-renames|--check|
--full-index|--binary|--abbrev|--break-rewrites|--find-renames|
--find-copies|--find-copies-harder|-D|--pickaxe-all|--pickaxe-regex|
--irreversible-delete|-R|--relative|-a|--text|--ignore-cr-at-eol|
--ignore-space-at-eol|-b|--ignore-space-change|-w|--ignore-all-space|
--ignore-blank-lines|-W|--function-context|--exit-code|--quiet|
--ext-diff|--no-ext-diff|--textconv|--no-textconv|--ignore-submodules|
--no-prefix|--ita-invisible-in-index|-1|--base|-2|--ours|-3|--theirs|
-0|--cached)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
# A generic action
"COMMIT_FILE_DIR_#_arg" "NO-OP // ::→chroma/-git-verify-commit-or-file-or-dir"
# A generic action
"FILE_1_arg" "NO-OP // ::→chroma/-git-verify-file"
# A generic action
"FILE_2_arg" "NO-OP // ::→chroma/-git-verify-file"
## }}}
##
## ADD
##
## {{{
subcmd:add "ADD_0_opt // FILE_OR_DIR_#_arg // NO_MATCH_#_opt"
ADD_0_opt "
--chmod=
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-ARG-action
|| (-v|--verbose|-f|--force|-i|--interactive|-n|--dry-run|
-p|--patch|-e|--edit|--all|--no-all|-A|--all|--no-all|
--ignore-removal|--no-ignore-removal|-u|--update|-N|
--intent-to-add|--refresh|--ignore-errors|--ignore-missing|
--renormalize|--no-warn-embedded-repo)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
FILE_OR_DIR_#_arg "NO-OP // ::→chroma/-git-verify-file-or-dir"
## }}}
##
## CHECKOUT
##
## {{{
subcmd:checkout "CHECKOUT_BRANCH_0_opt^ //
CHECKOUT_0_opt // FILE_OR_DIR_OR_BRANCH_OR_COMMIT_1_arg // FILE_#_arg //
FILE_#_arg // NO_MATCH_#_opt"
"CHECKOUT_BRANCH_0_opt^" "
(-b|-B|--orphan)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
|| (-b|-B|--orphan):del
<<>> FILE_OR_DIR_OR_BRANCH_OR_COMMIT_1_arg // FILE_#_arg // FILE_#_arg
|| (-b|-B|--orphan):add
<<>> NEW_BRANCH_1_arg // COMMIT_2_arg // NO_MATCH_#_arg"
NEW_BRANCH_1_arg "NO-OP // ::→chroma/-git-verify-correct-branch-name"
COMMIT_2_arg "NO-OP // ::→chroma/-git-verify-commit"
CHECKOUT_0_opt "
--conflict=
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-ARG-action
|| (-q|--quiet|--progress|--no-progress|-f|--force|--ours|--theirs|
-b|-B|-t|--track|--no-track|-l|--detach|--orphan|
--ignore-skip-worktree-bits|-m|--merge|-p|--patch|
--ignore-other-worktrees|--no-ignore-other-worktrees)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
# A generic action
COMMIT_1_arg "NO-OP // ::→chroma/-git-verify-commit"
# Unused
FILE_OR_BRANCH_OR_COMMIT_1_arg "NO-OP // ::→chroma/-git-file-or-ubranch-or-commit-verify"
FILE_OR_DIR_OR_BRANCH_OR_COMMIT_1_arg "NO-OP // ::→chroma/-git-file-or-dir-or-ubranch-or-commit-verify"
## }}}
##
## REMOTE
##
## {{{
subcmd:remote "REMOTE_0_opt // REMOTE_ADD_1_arg // REMOTE_RENAME_1_arg // REMOTE_REMOVE_1_arg //
REMOTE_SET_HEAD_1_arg // REMOTE_SET_BRANCHES_1_arg //
REMOTE_GET_URL_1_arg // REMOTE_SET_URL_1_arg // REMOTE_SHOW_1_arg //
REMOTE_PRUNE_1_arg // REMOTE_UPDATE_1_arg"
REMOTE_0_opt "(-v|--verbose)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
REMOTE_ADD_1_arg "add ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>>
add:REMOTE_ADD_OPTS_1_opt // REMOTE_A_NAME_2_arg //
REMOTE_A_URL_3_arg // NO_MATCH_#_opt // NO_MATCH_#_arg"
REMOTE_RENAME_1_arg "rename ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>>
add:REMOTE_2_arg // REMOTE_A_NAME_3_arg // NO_MATCH_#_opt // NO_MATCH_#_arg"
REMOTE_REMOVE_1_arg "remove ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>>
add:REMOTE_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg"
REMOTE_SET_HEAD_1_arg "set-head ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>>
add:REMOTE_2_arg // BRANCH_3_arg //
REMOTE_SET_HEAD_OPTS_1_opt // REMOTE_SET_HEAD_OPTS_2_opt //
NO_MATCH_#_opt // NO_MATCH_#_arg"
REMOTE_SET_BRANCHES_1_arg "set-branches ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>>
add:REMOTE_SET_BRANCHES_OPTS_1_opt // REMOTE_2_arg //
BRANCH_#_arg // NO_MATCH_#_opt"
REMOTE_GET_URL_1_arg "get-url ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>>
add:REMOTE_GET_URL_OPTS_1_opt // REMOTE_2_arg //
NO_MATCH_#_opt // NO_MATCH_#_arg"
REMOTE_SET_URL_1_arg "set-url ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>>
add:REMOTE_SET_URL_OPTS_1_opt^ //
REMOTE_2_arg // REMOTE_A_URL_3_arg // REMOTE_A_URL_4_arg //
NO_MATCH_#_opt // NO_MATCH_#_arg"
REMOTE_SHOW_1_arg "show ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>>
add:REMOTE_SHOW_OPTS_1_opt // REMOTE_#_arg // NO_MATCH_#_opt"
REMOTE_PRUNE_1_arg "prune ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>>
add:REMOTE_PRUNE_OPTS_1_opt // REMOTE_#_arg // NO_MATCH_#_opt"
REMOTE_UPDATE_1_arg "update ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>>
add:REMOTE_UPDATE_OPTS_1_opt // REMOTE_GR_#_arg // NO_MATCH_#_opt"
REMOTE_ADD_OPTS_1_opt "
(-t|-m|--mirror=)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-ARG-action
|| (-f|--tags|--no-tags)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
REMOTE_SET_HEAD_OPTS_1_opt "
(-a|--auto|-d|--delete)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
REMOTE_SET_HEAD_OPTS_2_opt "
(-a|--auto|-d|--delete)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
REMOTE_SET_BRANCHES_OPTS_1_opt "
--add
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
REMOTE_GET_URL_OPTS_1_opt "
(--push|--all)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
"REMOTE_SET_URL_OPTS_1_opt^" "
--push|--add|--delete
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
|| (--add|--delete):del
<<>> REMOTE_A_URL_4_arg"
REMOTE_SHOW_OPTS_1_opt "
-n
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
REMOTE_PRUNE_OPTS_1_opt "
(-n|--dry-run)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
REMOTE_UPDATE_OPTS_1_opt "
(-p|--prune)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
REMOTE_A_NAME_2_arg "NO-OP // ::→chroma/-git-verify-correct-branch-name"
REMOTE_A_NAME_3_arg "NO-OP // ::→chroma/-git-verify-correct-branch-name"
REMOTE_A_URL_3_arg "NO-OP // ::→chroma/main-chroma-std-verify-url"
REMOTE_A_URL_4_arg "NO-OP // ::→chroma/main-chroma-std-verify-url"
BRANCH_3_arg "NO-OP // ::→chroma/-git-verify-branch"
BRANCH_\#_arg "NO-OP // ::→chroma/-git-verify-branch"
REMOTE_2_arg "NO-OP // ::→chroma/-git-verify-remote"
REMOTE_\#_arg "NO-OP // ::→chroma/-git-verify-remote"
## }}}
##
## LOG
##
subcmd:log "LOG_0_opt // LOG_1_arg // FILE_#_arg // NO_MATCH_#_opt"
LOG_0_opt "
(--decorate=|--decorate-refs=|--decorate-refs-exclude=|-L|-n|--max-count=|
--skip=|--since=|--after=|--until=|--before=|--author=|--committer=|
--grep-reflog=|--grep=|--min-parents=|--max-parents=|--branches=|--tags=|
--remotes=|--glob=|--exclude=|--no-walk=|--pretty=|--format=|--encoding=|
--expand-tabs=|--notes=|--show-notes=|--date=|--show-linear-break=|-U|
--unified=|--anchored=|--diff-algorithm=|--stat=|--dirstat=|--submodule=|
--color=|--color-moved=|--color-moved-ws=|--word-diff=|--word-diff-regex=|
--color-words=|--ws-error-highlight=|--abbrev=|-B|--break-rewrites=|-M|
--find-renames=|-C|--find-copies=|-l|--diff-filter=|-S|-G|--find-object=|
--relative=|-O|--relative=|--inter-hunk-context=|--ignore-submodules=|
--src-prefix=|--dst-prefix=|--line-prefix=)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-ARG-action
|| (--follow|--decorate|--no-decorate|--source|--use-mailmap|--full-diff|
--log-size|--all-match|--invert-grep|-i|--regexp-ignore-case|--basic-regexp|
-E|--extended-regexp|-F|--fixed-strings|-P|--perl-regexp|--remove-empty|
--merges|--no-merges|--no-min-parents|--no-max-parents|--first-parent|
--not|--all|--branches|--tags|--remotes|--reflog|--single-worktree|
--ignore-missing|--bisect|--stdin|--cherry-mark|--cherry-pick|--left-only|
--right-only|--cherry|-g|--walk-reflogs|--merge|--boundary|--simplify-by-decoration|
--full-history|--dense|--sparse|--simplify-merges|--ancestry-path|--date-order|
--author-date-order|--topo-order|--reverse|--no-walk|--do-walk|--pretty|
--abbrev-commit|--no-abbrev-commit|--oneline|--expand-tabs|--no-expand-tabs|
--notes|--no-notes|--show-notes|--no-standard-notes|--show-signature|
--relative-date|--parents|--children|--left-right|--graph|--show-linear-break|
-c|--cc|-m|-r|-t|-p|-u|--patch|-s|--no-patch|--raw|--patch-with-raw|
--indent-heuristic|--no-indent-heuristic|--minimal|--patience|--histogram|
--stat|--compact-summary|--numstat|--shortstat|--dirstat|--summary|
--patch-with-stat|-z|--name-only|--name-status|--submodule|--color|--no-color|
--color-moved|--word-diff|--color-words|--no-renames|--check|--full-index|
--binary|--abbrev|--break-rewrites|--find-renames|
--find-copies|--find-copies-harder|-D|--irreversible-delete|
--pickaxe-all|--pickaxe-regex|-R|--relative|-a|--text|--ignore-cr-at-eol|
--ignore-space-at-eol|-b|--ignore-space-change|-w|--ignore-all-space|
--ignore-blank-lines|-W|--function-context|--ext-diff|--no-ext-diff|
--textconv|--no-textconv|--ignore-submodules|--no-prefix|
--ita-invisible-in-index)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
LOG_1_arg "NO-OP // ::→chroma/-git-verify-rev-range-or-file"
##
## TAG
##
subcmd:tag "TAG_D_0_opt^ // TAG_L_0_opt^ // TAG_V_0_opt^ // TAG_0_opt^"
"TAG_0_opt^" "
(-u|--local-user=|--cleanup=)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-ARG-action
|| -m
<<>> NO-OP // ::→chroma/-git-commit-msg-opt-action
<<>> NO-OP // ::→chroma/-git-commit-msg-opt-ARG-action
|| (-F|--file)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/-git-verify-file
|| (-a|--annotate|-s|--sign|-f|-e|--edit)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
|| (-u|--local-user=|--cleanup=|-m|-F|--file|-a|--annotate|-s|--sign|
-f|-e|--edit):add
<<>> TAG_NEW_1_arg // COMMIT_2_arg // NO_MATCH_#_arg //
NO_MATCH_#_opt"
TAG_NEW_1_arg "NO-OP // ::→chroma/-git-verify-correct-branch-name"
TAG_1_arg "NO-OP // ::→chroma/-git-verify-tag-name"
"TAG_D_0_opt^" "
(-d)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
|| -d:add
<<>> TAG_#_arg // NO_MATCH_#_opt
|| -d:del
<<>> TAG_0_opt // TAG_NEW_1_arg // COMMIT_2_arg"
"TAG_#_arg" "NO-OP // ::→chroma/-git-verify-tag-name"
"TAG_L_0_opt^" "
(-l)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
|| -l:add
<<>> TAG_L_0_opt // TAG_PAT_#_arg // NO_MATCH_#_opt
|| -l:del
<<>> TAG_0_opt // TAG_NEW_1_arg // COMMIT_2_arg"
TAG_L_0_opt "
(-n|--contains|--no-contains|--points-at|--column=|--sort=|--format=|
--color=)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-ARG-action
|| (--column|--no-column|--create-reflog|--merged|--no-merged|--color|-i)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
"TAG_PAT_#_arg" "NO-OP // ::→chroma/main-chroma-std-verify-pattern"
"TAG_V_0_opt^" "
(-v)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
|| -v:add
<<>> TAG_V_0_opt // TAG_#_arg // NO_MATCH_#_opt
|| -v:del
<<>> TAG_0_opt // TAG_NEW_1_arg // COMMIT_2_arg"
TAG_V_0_opt "
--format=
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-ARG-action"
##
## All remaining subcommands
##
## {{{
"subcmd:*" "CATCH_ALL_#_opt"
"CATCH_ALL_#_opt" "* <<>> NO-OP // ::→chroma/main-chroma-std-aopt-SEMI-action"
## }}}
)
# Called after entering just "git" on the command line
→chroma/-git-first-call() {
# Called for the first time - new command
# FAST_HIGHLIGHT is used because it survives between calls, and
# allows to use a single global hash only, instead of multiple
# global variables
FAST_HIGHLIGHT[chroma-git-counter]=0
FAST_HIGHLIGHT[chroma-git-got-subcommand]=0
FAST_HIGHLIGHT[chroma-git-subcommand]=""
FAST_HIGHLIGHT[chrome-git-got-msg1]=0
FAST_HIGHLIGHT[chrome-git-got-anymsg]=0
FAST_HIGHLIGHT[chrome-git-occurred-double-hyphen]=0
FAST_HIGHLIGHT[chroma-git-checkout-new]=0
FAST_HIGHLIGHT[chroma-git-fetch-multiple]=0
FAST_HIGHLIGHT[chroma-git-branch-change]=0
FAST_HIGHLIGHT[chroma-git-option-with-argument-active]=0
FAST_HIGHLIGHT[chroma-git-reset-etc-saw-commit]=0
FAST_HIGHLIGHT[chroma-git-reset-etc-saw-file]=0
return 1
}
→chroma/-git-check-if-alias() {
local _wrd="$1"
local -a _result
typeset -ga fsh__chroma__git__aliases
_result=( ${(M)fsh__chroma__git__aliases[@]:#${_wrd}[[:space:]]##*} )
→chroma/main-chroma-print "Got is-alias-_result: $_result"
[[ -n "$_result" ]] && \
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]="${${${_result#* }## ##}%% *}"
}
# A hook that returns the list of git's
# available subcommands in $reply
→chroma/-git-get-subcommands() {
local __svalue
integer __ivalue
LANG=C .fast-run-command "git help -a" chroma-${FAST_HIGHLIGHT[chroma-current]}-subcmd-list "" $(( 15 * 60 ))
if [[ "${__lines_list[1]}" = See* ]]; then
# (**)
# git >= v2.20, the aliases in the `git help -a' command
__lines_list=( ${${${${(M)__lines_list[@]:#([[:space:]](#c3,3)[a-zA-Z0-9_]*|Command aliases)}##[[:space:]]##}//(#s)Command\ aliases(#e)/Command_aliases}} )
__svalue="+${__lines_list[(I)Command_aliases]}"
__lines_list[1,__svalue-1]=( ${(@)__lines_list[1,__svalue-1]%%[[:space:]]##*} )
else
# (**)
# git < v2.20, add aliases through extra code
__lines_list=( ${(s: :)${(M)__lines_list[@]:# [a-z]*}} )
__svalue=${#__lines_list}
# This allows to check if the command is an alias - we want to
# highlight the aliased command just like the target command of
# the alias
.fast-run-command "+git config --get-regexp 'alias.*'" chroma-${FAST_HIGHLIGHT[chroma-current]}-alias-list "[[:space:]]#alias." $(( 15 * 60 ))
fi
__tmp=${#__lines_list}
typeset -ga fsh__chroma__git__aliases
fsh__chroma__git__aliases=( ${__lines_list[__svalue+1,__tmp]} )
[[ ${__lines_list[__svalue]} != "Command_aliases" ]] && (( ++ __svalue, __ivalue=0, 1 )) || (( __ivalue=1 ))
__lines_list[__svalue,__tmp]=( ${(@)__lines_list[__svalue+__ivalue,__tmp]%%[[:space:]]##*} )
reply=( "${__lines_list[@]}" )
}
# A generic handler
→chroma/-git-verify-remote() {
local _wrd="$4"
.fast-run-git-command "git remote" "chroma-git-remotes-$PWD" "" 10
[[ -n ${__lines_list[(r)$_wrd]} ]] && {
__style=${FAST_THEME_NAME}correct-subtle; return 0
} || {
[[ $_wrd != *:* ]] && { __style=${FAST_THEME_NAME}incorrect-subtle; return 1; }
}
}
# A generic handler - checks if given ref is correct
→chroma/-git-verify-ref() {
local _wrd="$4"
_wrd="${_wrd%%:*}"
.fast-run-git-command "git for-each-ref --format='%(refname:short)' refs/heads" "chroma-git-refs-$PWD" "refs/heads" 10
[[ -n ${__lines_list[(r)$_wrd]} ]] && \
{ __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \
{ __style=${FAST_THEME_NAME}incorrect-subtle; return 1; }
}
# A generic handler - checks if given remote or group is correct
→chroma/-git-verify-remote-or-group() {
→chroma/-git-verify-remote "$@" && return 0
# The check for a group is to follow below
integer _start="$2" _end="$3"
local _scmd="$1" _wrd="$4"
}
# A generic handler - checks whether the file exists
→chroma/-git-verify-file() {
integer _start="$2" _end="$3" __pos __start __end
local _wrd="$4" bg
[[ -f $_wrd ]] && {
(( __start=_start, __end=_end, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}")
bg=${(M)FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]%bg=*}
((1))
} || {
(( __start=_start, __end=_end, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
bg=${(M)FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]%bg=*}
}
[[ -n ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]} && \
${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]} != \
${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]}
]] && \
for (( __pos = 1; __pos <= (_end-_start); __pos++ )) {
[[ ${_wrd[__pos]} == "/" ]] && {
[[ ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]} = *bg=* ]] && {
(( __start=_start+__pos-__PBUFLEN, __start >= 0 )) && \
reply+=("$(( __start - 1 )) $__start ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]}")
((1))
} || {
(( __start=_start+__pos-__PBUFLEN, __start >= 0 )) && \
reply+=("$(( __start - 1 )) $__start ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]}${bg:+,$bg}")
}
}
}
}
# A generic handler - checks whether the file exists
→chroma/-git-verify-file-or-dir() {
integer _start="$2" _end="$3" __pos __start __end retval
local _wrd="$4" bg
__style=
[[ -f $_wrd || -d $_wrd ]] && {
(( __start=_start, __end=_end, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}")
bg=${(M)FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]%bg=*}
((1))
} || {
(( __start=_start, __end=_end, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
bg=${(M)FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]%bg=*}
retval=1
}
[[ -n ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]} && \
${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]} != \
${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]}
]] && \
for (( __pos = 1; __pos <= (_end-_start); __pos++ )) {
[[ ${_wrd[__pos]} == "/" ]] && {
[[ ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]} = *bg=* ]] && {
(( __start=_start+__pos-__PBUFLEN, __start >= 0 )) && \
reply+=("$(( __start - 1 )) $__start ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]}")
((1))
} || {
(( __start=_start+__pos-__PBUFLEN, __start >= 0 )) && \
reply+=("$(( __start - 1 )) $__start ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]}${bg:+,$bg}")
}
}
}
return $retval
}
→chroma/-git-verify-branch() {
local _wrd="$4"
.fast-run-git-command "git for-each-ref --format='%(refname:short)'" "chroma-git-branches-$PWD" "refs/heads" 10
if [[ -n ${__lines_list[(r)$_wrd]} ]] {
__style=${FAST_THEME_NAME}correct-subtle; return 0
} elif [[ -n ${__lines_list[(r)origin/$_wrd]} ]] {
__style=${FAST_THEME_NAME}correct-subtle; return 0
} else {
__style=${FAST_THEME_NAME}incorrect-subtle; return 1
}
}
→chroma/-git-verify-also-unfetched-ref() {
local _wrd="$4"
.fast-run-git-command "git config --get checkout.defaultRemote" \
"chroma-git-defaultRemote-$PWD" "" 10
local remote="${__lines_list[1]:-origin}"
.fast-run-git-command "git rev-list --count --no-walk
--glob=\"refs/remotes/$remote/$_wrd\"" \
"chroma-git-unfetched-ref-$PWD" "" 10
(( __lines_list[1] )) && { __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \
{ __style=${FAST_THEME_NAME}incorrect-subtle; return 1; }
}
# A generic handler
→chroma/-git-file-or-ubranch-or-commit-verify() {
→chroma/-git-verify-commit "$@" && return
→chroma/-git-verify-file "$@" && return
→chroma/-git-verify-branch "$@" && return
→chroma/-git-verify-also-unfetched-ref "$@"
}
# A generic handler
→chroma/-git-file-or-dir-or-ubranch-or-commit-verify() {
→chroma/-git-verify-commit "$@" && return
→chroma/-git-verify-file-or-dir "$@" && return
→chroma/-git-verify-branch "$@" && return
→chroma/-git-verify-also-unfetched-ref "$@"
}
# A generic handler
→chroma/-git-verify-correct-branch-name() {
local _wrd="$4"
→chroma/-git-verify-commit "$@" && \
{ __style=${FAST_THEME_NAME}incorrect-subtle; return 0; }
→chroma/-git-verify-remote "$@" && \
{ __style=${FAST_THEME_NAME}incorrect-subtle; return 0; }
[[ "$_wrd" != ./* && "$_wrd" != *..* && "$_wrd" != *[~\^\ $'\t']* &&
"$_wrd" != */ && "$_wrd" != *.lock && "$_wrd" != *\\* ]] && \
{ __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \
{ __style=${FAST_THEME_NAME}incorrect-subtle; return 1; }
}
# A generic handler that checks if given commit reference is correct
→chroma/-git-verify-commit() {
local _wrd="$4"
__lines_list=()
.fast-run-git-command --status "git rev-parse --verify --quiet \"$_wrd\"" \
"chroma-git-commits-$PWD-$_wrd" "" $(( 1.5 * 60 ))
if (( __lines_list[1] == 0 )); then
__style=${FAST_THEME_NAME}correct-subtle
return 0
fi
__style=${FAST_THEME_NAME}incorrect-subtle
return 1
}
# A generic handler that checks if given commit reference
# is correct or if it's a file that exists
→chroma/-git-verify-commit-or-file() {
→chroma/-git-verify-commit "$@" && return
→chroma/-git-verify-file "$@"
}
# A generic handler that checks if given commit reference
# is correct or if it's a file or directives that exists
→chroma/-git-verify-commit-or-file-or-dir() {
→chroma/-git-verify-commit "$@" && return
→chroma/-git-verify-file-or-dir "$@"
}
# A generic handler that checks if given revision range
# is correct or if a file of that name exists
→chroma/-git-verify-rev-range-or-file() {
local _wrd="$4"
→chroma/-git-verify-commit "$@" && return 0
if [[ "$_wrd" = *..* ]]; then
(( FAST_HIGHLIGHT[chroma-git-reset-etc-saw-file] )) && {
→chroma/-git-verify-file "$@" && return 0
__style=${FAST_THEME_NAME}unknown-token
return 1
}
__style=""
return 0
fi
→chroma/-git-verify-file "$@" && \
{ FAST_HIGHLIGHT[chroma-git-reset-etc-saw-file]=1; return 0; }
__style=""
return 1
}
→chroma/-git-verify-tag-name() {
local _wrd="$4"
.fast-run-git-command "git tag" "chroma-git-tags-$PWD" "" $(( 2*60 ))
[[ -n ${__lines_list[(r)$_wrd]} ]] && \
__style=${FAST_THEME_NAME}correct-subtle || \
__style=${FAST_THEME_NAME}incorrect-subtle
}
# A handler for the commit's -m/--message options.Currently
# does the same what →chroma/main-chroma-std-aopt-action does
→chroma/-git-commit-msg-opt-action() {
→chroma/main-chroma-std-aopt-action "$@"
}
# A handler for the commit's -m/--message options' argument
→chroma/-git-commit-msg-opt-ARG-action() {
integer _start="$2" _end="$3"
local _scmd="$1" _wrd="$4"
(( __start >= 0 )) || return
# Match the message body in case of an --message= option
if [[ "$_wrd" = (#b)(--message=)(*) && -n "${match[2]}" ]]; then
_wrd="${(Q)${match[2]//\`/x}}"
# highlight --message=>>something<<
reply+=("$(( __start+10 )) $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}")
elif [[ "$_wrd" != --message ]]; then
# highlight the message's body
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}")
fi
integer length=${FAST_HIGHLIGHT[git-cmsg-len]:-50}
if (( ${#_wrd} > length )); then
for (( __idx1 = 1, __idx2 = 1; __idx1 <= length; ++ __idx1, ++ __idx2 )); do
# Use __arg from the fast-highlight-process's scope
while [[ "${__arg[__idx2]}" != "${_wrd[__idx1]}" ]]; do
(( ++ __idx2 ))
(( __idx2 > __asize )) && { __idx2=-1; break; }
done
(( __idx2 == -1 )) && break
done
if (( __idx2 != -1 )); then
if [[ -n "${match[1]}" ]]; then
reply+=("$(( __start+__idx2 )) $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
else
reply+=("$(( __start+__idx2-1 )) $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
fi
fi
fi
}
# A RESET handler
# TODO: differentiate tree-ish from commit
→chroma/-git-RESET-verify-commit-or-file() {
→chroma/-git-verify-commit "$@" && {
→chroma/-git-verify-file "$@" && {
# TODO: with -p/--patch, the <paths> are optional,
# and this argument will be taken as a commit in a
# specific circumstances
FAST_HIGHLIGHT[chroma-git-reset-etc-saw-file]=1
return 0
}
(( FAST_HIGHLIGHT[chroma-git-reset-etc-saw-file] ||
FAST_HIGHLIGHT[chroma-git-reset-etc-saw-commit] )) && \
{ __style=${FAST_THEME_NAME}unknown-token; return 1; }
FAST_HIGHLIGHT[chroma-git-reset-etc-saw-commit]=1
__style=${FAST_THEME_NAME}correct-subtle
return 0
}
→chroma/-git-verify-file "$@" && \
{ FAST_HIGHLIGHT[chroma-git-reset-etc-saw-file]=1; return 0; }
return 1
}
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,89 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
#
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg; the token can be eg.: "grep"
#
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
#
# $4 - a private copy of $_end_pos from the above scope
#
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style __chars
integer __idx1 __idx2
# First call, i.e. command starts, i.e. "grep" token etc.
(( __first_call )) && {
FAST_HIGHLIGHT[chroma-grep-counter]=0
return 1
} || {
# Following call, i.e. not the first one.
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if [[ "$__wrd" = -* ]]; then
# Detected option, add style for it.
[[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \
__style=${FAST_THEME_NAME}single-hyphen-option
else
# Count non-option tokens.
(( FAST_HIGHLIGHT[chroma-grep-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-grep-counter] ))
# First non-option token is the pattern (regex), we will
# highlight it.
if (( FAST_HIGHLIGHT[chroma-grep-counter] == 1 )); then
[[ "$__wrd" = \"* ]] && __style=${FAST_THEME_NAME}double-quoted-argument
[[ "$__wrd" = \'* ]] && __style=${FAST_THEME_NAME}single-quoted-argument
[[ "$__wrd" = \$\'* ]] && __style=${FAST_THEME_NAME}dollar-quoted-argument
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
__style=""
__chars="*+\\)([]^\$"
__idx1=__start_pos
__idx2=__start_pos
while [[ "$__wrd" = (#b)[^$__chars]#([\\][\\])#((+|\*|\[|\]|\)|\(|\^|\$)|[\\](+|\*|\[|\]|\)|\(|\^|\$))(*) ]]; do
if [[ -n "${match[3]}" ]]; then
__idx1+=${mbegin[3]}-1
__idx2=__idx1+${mend[3]}-${mbegin[3]}+1
(( __start=__idx1-${#PREBUFFER}, __end=__idx2-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}for-loop-operator]}")
__idx1=__idx2
else
__idx1+=${mbegin[5]}-1
fi
__wrd="${match[5]}"
done
elif (( FAST_HIGHLIGHT[chroma-grep-counter] == 2 )); then
# Handle paths, etc. normally - just pass-through to the big
# highlighter (the main FSH highlighter, used before chromas).
return 1
fi
fi
}
# Add region_highlight entry (via `reply' array).
#
# This is a common place of adding such entry, but any above
# code can do it itself (and it does) and skip setting __style
# to disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through (no return 1 occured), do obligatory things ourselves.
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,51 @@
# vim:ft=zsh:et:sw=4
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
if (( __first_call )); then
chroma/-git.ch $*
return 1
fi
[[ "$__arg_type" = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
if [[ "$__wrd" != -* ]] && (( FAST_HIGHLIGHT[chroma-git-got-subcommand] == 0 )); then
.fast-run-command "git config --get-regexp 'alias.*'" chroma-git-alias-list "" $(( 5 * 60 ))
# Grep for line: alias.{user-entered-subcmd}[[:space:]], and remove alias. prefix
__lines_list=( ${${(M)__lines_list[@]:#alias.${__wrd}[[:space:]]##*}#alias.} )
if (( ${#__lines_list} > 0 )); then
# (*)
# First remove alias name (#*[[:space:]]) and the space after it, then
# remove any leading spaces from what's left (##[[:space:]]##), then
# remove everything except the first word that's in the left line
# (%%[[:space:]]##*, i.e.: "everything from right side up to any space")
FAST_HIGHLIGHT[chroma-git-subcommand]="${${${__lines_list[1]#*[[:space:]]}##[[:space:]]##}%%[[:space:]]##*}"
else
FAST_HIGHLIGHT[chroma-git-subcommand]="$__wrd"
fi
if [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "browse" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "ci-status" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "compare" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "create" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "delete" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "fork" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "issue" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "pr" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "pull-request" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "release" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "sync" ]]; then
FAST_HIGHLIGHT[chroma-git-got-subcommand]=1
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}")
(( FAST_HIGHLIGHT[chroma-git-counter] += 1 ))
(( this_word = next_word ))
_start_pos=$4
return 0
fi
fi
chroma/-git.ch $*

View File

@ -0,0 +1,117 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2018 Sebastian Gniazdowski
# Copyright (C) 2019 by Philippe Troin (F-i-f on GitHub)
# All rights reserved.
#
# The only licensing for this file follows.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
setopt local_options extendedglob warn_create_global typeset_silent
# Keep chroma-takever state meaning: until ;, handle highlighting via chroma.
# So the below 8192 assignment takes care that next token will be routed to chroma.
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style option_start=0 option_end=0 number_start=0 number_end=0
local -a match mbegin mend
(( __first_call )) && {
# Called for the first time - new command.
# FAST_HIGHLIGHT is used because it survives between calls, and
# allows to use a single global hash only, instead of multiple
# global string variables.
FAST_HIGHLIGHT[ionice-option-argument]=0
# Set style for region_highlight entry. It is used below in
# '[[ -n "$__style" ]] ...' line, which adds highlight entry,
# like "10 12 fg=green", through `reply' array.
#
# Could check if command `example' exists and set `unknown-token'
# style instead of `command'
__style=${FAST_THEME_NAME}precommand
} || {
# Following call, i.e. not the first one
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
if (( FAST_HIGHLIGHT[ionice-option-argument] )); then
(( FAST_HIGHLIGHT[ionice-option-argument] = 0 ))
[[ $__wrd == [0-9]# ]] && __style=${FAST_THEME_NAME}mathnum || __style=${FAST_THEME_NAME}incorrect-subtle
else
case $__wrd in
--(class(data|)|(u|p(g|))id))
__style=${FAST_THEME_NAME}double-hyphen-option
FAST_HIGHLIGHT[ionice-option-argument]=1
;;
-[cnpPu])
__style=${FAST_THEME_NAME}single-hyphen-option
FAST_HIGHLIGHT[ionice-option-argument]=1
;;
--*)
__style=${FAST_THEME_NAME}double-hyphen-option
;;
-*)
__style=${FAST_THEME_NAME}single-hyphen-option
;;
*)
this_word=1
next_word=2
return 1
;;
esac
fi
}
# Add region_highlight entry (via `reply' array).
# If 1 will be added to __start_pos, this will highlight "oken".
# If 1 will be subtracted from __end_pos, this will highlight "toke".
# $PREBUFFER is for specific situations when users does command \<ENTER>
# i.e. when multi-line command using backslash is entered.
#
# This is a common place of adding such entry, but any above code can do
# it itself (and it does in other chromas) and skip setting __style to
# this way disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through, do obligatory things ourselves.
# _start_pos=$_end_pos advainces pointers in command line buffer.
#
# To pass through means to `return 1'. The highlighting of
# this single token is then done by fast-syntax-highlighting's
# main code and chroma doesn't have to do anything.
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,59 @@
# vim:ft=zsh:et:sw=4
#
# The `lab' tool after which this chroma is modeled after:
# https://github.com/zaquestion/lab
#
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
if (( __first_call )); then
chroma/-git.ch $*
return 1
fi
[[ "$__arg_type" = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
if [[ "$__wrd" != -* ]] && (( FAST_HIGHLIGHT[chroma-git-got-subcommand] == 0 )); then
.fast-run-command "git config --get-regexp 'alias.*'" chroma-git-alias-list "" $(( 5 * 60 ))
# Grep for line: alias.{user-entered-subcmd}[[:space:]], and remove alias. prefix
__lines_list=( ${${(M)__lines_list[@]:#alias.${__wrd}[[:space:]]##*}#alias.} )
if (( ${#__lines_list} > 0 )); then
# (*)
# First remove alias name (#*[[:space:]]) and the space after it, then
# remove any leading spaces from what's left (##[[:space:]]##), then
# remove everything except the first word that's in the left line
# (%%[[:space:]]##*, i.e.: "everything from right side up to any space")
FAST_HIGHLIGHT[chroma-git-subcommand]="${${${__lines_list[1]#*[[:space:]]}##[[:space:]]##}%%[[:space:]]##*}"
else
FAST_HIGHLIGHT[chroma-git-subcommand]="$__wrd"
fi
if [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "browse" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "ci" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "mr" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "project" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "snippet" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "ci-status" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "compare" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "create" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "delete" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "fork" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "issue" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "pr" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "pull-request" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "release" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "sync" ]]; then
FAST_HIGHLIGHT[chroma-git-got-subcommand]=1
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}")
(( FAST_HIGHLIGHT[chroma-git-counter] += 1 ))
(( this_word = next_word ))
_start_pos=$4
return 0
fi
fi
chroma/-git.ch $*

View File

@ -0,0 +1,105 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Chroma function for command `make'.
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
# $4 - a private copy of $_end_pos from the above scope
#
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style
integer __idx1 __idx2
local -a __lines_list reply2
(( __first_call )) && {
# Called for the first time - new command.
# FAST_HIGHLIGHT is used because it survives between calls, and
# allows to use a single global hash only, instead of multiple
# global variables.
FAST_HIGHLIGHT[chroma-make-counter]=0
FAST_HIGHLIGHT[chroma-make-skip-two]=0
FAST_HIGHLIGHT[chroma-make-custom-dir]="./"
FAST_HIGHLIGHT[chroma-make-custom-file]="Makefile"
FAST_HIGHLIGHT[chroma-make-got-custom-dir-opt]=0
FAST_HIGHLIGHT[chroma-make-got-custom-file-opt]=0
return 1
} || {
# Following call, i.e. not the first one.
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
if [[ "$__wrd" = -* || "$__wrd" = *=* ]]; then
[[ "$__wrd" = *=* ]] && {
__style=${FAST_THEME_NAME}variable
} || {
__style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option}
}
if [[ "$__wrd" = (-I|-o|-W) ]]; then
FAST_HIGHLIGHT[chroma-make-skip-two]=1
elif [[ "$__wrd" = "-C" ]]; then
FAST_HIGHLIGHT[chroma-make-got-custom-dir-opt]=1
elif [[ "$__wrd" = "-f" ]]; then
FAST_HIGHLIGHT[chroma-make-got-custom-file-opt]=1
fi
else
if (( FAST_HIGHLIGHT[chroma-make-skip-two] )); then
FAST_HIGHLIGHT[chroma-make-skip-two]=0
elif (( FAST_HIGHLIGHT[chroma-make-got-custom-dir-opt] )); then
FAST_HIGHLIGHT[chroma-make-got-custom-dir-opt]=0
FAST_HIGHLIGHT[chroma-make-custom-dir]="$__wrd"
elif (( FAST_HIGHLIGHT[chroma-make-got-custom-file-opt] )); then
FAST_HIGHLIGHT[chroma-make-got-custom-file-opt]=0
FAST_HIGHLIGHT[chroma-make-custom-file]="$__wrd"
else
# Count non-option tokens.
(( FAST_HIGHLIGHT[chroma-make-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-make-counter] ))
if (( FAST_HIGHLIGHT[chroma-make-counter] == 1 )); then
__wrd="${__wrd//\`/x}"
__wrd="${(Q)__wrd}"
if [[ -f "${FAST_HIGHLIGHT[chroma-make-custom-dir]%/}/${FAST_HIGHLIGHT[chroma-make-custom-file]}" ]] && \
.fast-make-targets < "${FAST_HIGHLIGHT[chroma-make-custom-dir]%/}/${FAST_HIGHLIGHT[chroma-make-custom-file]}"
then
if [[ "${reply2[(r)$__wrd]}" ]]; then
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}")
else
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
fi
fi
else
# Pass-through to the big-loop outside
return 1
fi
fi
fi
}
# Add region_highlight entry (via `reply' array)
#
# This is a common place of adding such entry, but any above
# code can do it itself (and it does) and skip setting __style
# to disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through, do obligatory things ourselves
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,138 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2018 Sebastian Gniazdowski
# Copyright (C) 2019 by Philippe Troin (F-i-f on GitHub)
# All rights reserved.
#
# The only licensing for this file follows.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
setopt local_options extendedglob warn_create_global typeset_silent
# Keep chroma-takever state meaning: until ;, handle highlighting via chroma.
# So the below 8192 assignment takes care that next token will be routed to chroma.
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style option_start=0 option_end=0 number_start=0 number_end=0
local -a match mbegin mend
(( __first_call )) && {
# Called for the first time - new command.
# FAST_HIGHLIGHT is used because it survives between calls, and
# allows to use a single global hash only, instead of multiple
# global string variables.
FAST_HIGHLIGHT[nice-arg-count]=0
FAST_HIGHLIGHT[nice-increment-argument]=0
# Set style for region_highlight entry. It is used below in
# '[[ -n "$__style" ]] ...' line, which adds highlight entry,
# like "10 12 fg=green", through `reply' array.
#
# Could check if command `example' exists and set `unknown-token'
# style instead of `command'
__style=${FAST_THEME_NAME}precommand
} || {
# Following call, i.e. not the first one
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
if (( FAST_HIGHLIGHT[nice-increment-argument] )); then
(( FAST_HIGHLIGHT[nice-increment-argument] = 0 ))
[[ $__wrd = (-|+|)[0-9]## ]] \
&& __style=${FAST_THEME_NAME}mathnum \
|| __style=${FAST_THEME_NAME}incorrect-subtle
else
case $__wrd in
-(-|+|)[0-9]##)
(( option_start = __start_pos-${#PREBUFFER} ,
option_end = option_start+1 ,
number_start = option_end ,
number_end = __end_pos-${#PREBUFFER} ))
option_style=${FAST_THEME_NAME}single-hyphen-option
;;
(#b)(--adjustment)(=(-|+|)[0-9]#|))
(( option_start = __start_pos-${#PREBUFFER} ,
option_end = option_start+mend[1] ))
option_style=${FAST_THEME_NAME}double-hyphen-option
[[ -z $match[2] ]] \
&& (( FAST_HIGHLIGHT[nice-increment-argument] = 1 )) \
|| (( option_end += 1 ,
number_start = option_start+mbegin[2]-mbegin[1]+1 ,
number_end = __end_pos-${#PREBUFFER} ))
;;
-n)
__style=${FAST_THEME_NAME}double-hyphen-option
FAST_HIGHLIGHT[nice-increment-argument]=1
;;
--*)
__style=${FAST_THEME_NAME}double-hyphen-option
;;
-*)
__style=${FAST_THEME_NAME}single-hyphen-option
;;
*)
this_word=1
next_word=2
return 1
;;
esac
(( option_start > 0 && option_end )) \
&& reply+=("$option_start $option_end ${FAST_HIGHLIGHT_STYLES[$option_style]}")
(( number_start > 0 && number_end )) \
&& reply+=("$number_start $number_end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}mathnum]}")
fi
}
# Add region_highlight entry (via `reply' array).
# If 1 will be added to __start_pos, this will highlight "oken".
# If 1 will be subtracted from __end_pos, this will highlight "toke".
# $PREBUFFER is for specific situations when users does command \<ENTER>
# i.e. when multi-line command using backslash is entered.
#
# This is a common place of adding such entry, but any above code can do
# it itself (and it does in other chromas) and skip setting __style to
# this way disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through, do obligatory things ourselves.
# _start_pos=$_end_pos advainces pointers in command line buffer.
#
# To pass through means to `return 1'. The highlighting of
# this single token is then done by fast-syntax-highlighting's
# main code and chroma doesn't have to do anything.
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,58 @@
# vim:ft=zsh:et:sw=4
(( next_word = 2 | 8192 ))
[[ "$__arg_type" = 3 ]] && return 2
typeset -A subcommands
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" subcommand
subcommands=(
help "_"
general "help status hostname permissions logging _"
networking "help on off connectivity _"
radio "help all wifi wwan _"
connection "help show up down add modify clone edit delete monitor reload load import export _"
device "help status show set connect reapply modify disconnect delete monitor wifi lldp _"
agent "help secret polkit all _"
monitor "help _"
_ "_"
)
if (( __first_call )); then
FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]=""
FAST_HIGHLIGHT[chroma-nmcli-subcommand-b]=""
return 1
elif (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
elif [[ "$2" = -* ]]; then
return 1
elif [[ -z ${FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]} ]]; then
for subcommand in ${(@k)subcommands}; do
[[ $subcommand = $__wrd* ]] && break || subcommand="_"
done
if [[ $subcommand = _ ]]; then
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
else
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}")
fi
FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]="$subcommand"
elif [[ -z ${FAST_HIGHLIGHT[chroma-nmcli-subcommand-b]} ]]; then
for subcommand in ${(s. .)subcommands[${FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]}]}; do
[[ "$subcommand" = $__wrd* ]] && break || subcommand="_"
done
if [[ $subcommand = _ ]]; then
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
else
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}")
fi
FAST_HIGHLIGHT[chroma-nmcli-subcommand-b]="$subcommand"
else
return 1
fi
(( this_word = next_word ))
_start_pos=$_end_pos
return 0

View File

@ -0,0 +1,37 @@
# vim:ft=zsh:et:sw=4
(( next_word = 2 | 8192 ))
[[ "$__arg_type" = 3 ]] && return 2
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style
if (( __first_call )); then
FAST_HIGHLIGHT[chroma-node-file]=1
elif (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
elif [[ "$__wrd" = -- ]]; then
FAST_HIGHLIGHT[chroma-node-file]=2
elif (( FAST_HIGHLIGHT[chroma-node-file] != 2 )) && [[ "$__wrd" = -* ]]; then
if [[ "$__wrd" = -*e* || "$__wrd" = --eval ]]; then
FAST_HIGHLIGHT[chroma-node-file]=0
fi
elif (( FAST_HIGHLIGHT[chroma-node-file] )); then
if [[ "$__wrd" = debug || "$__wrd" = inspect ]]; then
__style=${FAST_THEME_NAME}subcommand
else
FAST_HIGHLIGHT[chroma-node-file]=0
if [[ -f ${~__wrd} || -f ${~__wrd}.js || -f ${~__wrd}/index.js ]]; then
__style=${FAST_THEME_NAME}path
else
__style=${FAST_THEME_NAME}incorrect-subtle
fi
fi
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
fi
return 1

View File

@ -0,0 +1,383 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
# Copyright (c) 2018 plexigras
#
# The old chroma function for command `git'. It colorizes the part of command
# line that holds `git' invocation.
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
# $4 - a private copy of $_end_pos from the above scope
#
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style
integer __idx1 __idx2
local -a __lines_list chroma_git_remote_subcommands
chroma_git_remote_subcommands=(add rename remove set-head set-branches get-url set-url set-url set-url show prune update)
if (( __first_call )); then
# Called for the first time - new command
# FAST_HIGHLIGHT is used because it survives between calls, and
# allows to use a single global hash only, instead of multiple
# global variables
FAST_HIGHLIGHT[chroma-git-counter]=0
FAST_HIGHLIGHT[chroma-git-got-subcommand]=0
FAST_HIGHLIGHT[chroma-git-subcommand]=""
FAST_HIGHLIGHT[chrome-git-got-msg1]=0
FAST_HIGHLIGHT[chrome-git-got-anymsg]=0
FAST_HIGHLIGHT[chrome-git-occurred-double-hyphen]=0
FAST_HIGHLIGHT[chroma-git-checkout-new]=0
FAST_HIGHLIGHT[chroma-git-fetch-multiple]=0
FAST_HIGHLIGHT[chroma-git-branch-change]=0
FAST_HIGHLIGHT[chroma-git-option-with-argument-active]=0
return 1
else
# Following call, i.e. not the first one
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if [[ "$__wrd" = "--" ]]; then
FAST_HIGHLIGHT[chrome-git-occurred-double-hyphen]=1
__style=${FAST_THEME_NAME}double-hyphen-option
elif [[ "$__wrd" = -* && ${FAST_HIGHLIGHT[chroma-git-got-subcommand]} -eq 0 ]]; then
# Options occuring before a subcommand
if (( FAST_HIGHLIGHT[chroma-git-option-with-argument-active] == 0 )); then
if [[ "$__wrd" = -[^[:space:]-]#C ]]; then
FAST_HIGHLIGHT[chroma-git-option-with-argument-active]=2
elif [[ "$__wrd" = -[^[:space:]-]#c ]]; then
FAST_HIGHLIGHT[chroma-git-option-with-argument-active]=1
fi
fi
return 1
else
# If at e.g. '>' or destination/source spec (of the redirection)
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
# If at main git option taking argument in a separate word (-C and -c)
elif (( FAST_HIGHLIGHT[chroma-git-option-with-argument-active] > 0 && \
0 == FAST_HIGHLIGHT[chroma-git-got-subcommand] ))
then
# Remember the value
__idx2=${FAST_HIGHLIGHT[chroma-git-option-with-argument-active]}
# Reset the is-argument mark-field
FAST_HIGHLIGHT[chroma-git-option-with-argument-active]=0
(( __idx2 == 2 )) && return 1
# Other options' args (i.e. arg of -c) aren't routed to the big-loop
# as they aren't paths and aren't handled in any special way there
elif (( FAST_HIGHLIGHT[chroma-git-got-subcommand] == 0 )); then
FAST_HIGHLIGHT[chroma-git-got-subcommand]=1
# Check if the command is an alias - we want to highlight the
# aliased command just like the target command of the alias
.fast-run-command "git config --get-regexp 'alias.*'" chroma-git-alias-list "" $(( 10 * 60 ))
# Grep for line: alias.{user-entered-subcmd}[[:space:]], and remove alias. prefix
__lines_list=( ${${(M)__lines_list[@]:#alias.${__wrd}[[:space:]]##*}#alias.} )
if (( ${#__lines_list} > 0 )); then
# (*)
# First remove alias name (#*[[:space:]]) and the space after it, then
# remove any leading spaces from what's left (##[[:space:]]##), then
# remove everything except the first word that's in the left line
# (%%[[:space:]]##*, i.e.: "everything from right side up to any space")
FAST_HIGHLIGHT[chroma-git-subcommand]="${${${__lines_list[1]#*[[:space:]]}##[[:space:]]##}%%[[:space:]]##*}"
else
FAST_HIGHLIGHT[chroma-git-subcommand]="$__wrd"
fi
if (( __start_pos >= 0 )); then
# if subcommand exists
LANG=C .fast-run-command "git help -a" chroma-git-subcmd-list "" $(( 10 * 60 ))
# (s: :) will split on every space, but because the expression
# isn't double-quoted, the empty elements will be eradicated
# Some further knowledge-base: s-flag is special, it skips
# empty elements and creates an array (not a concatenated
# string) even when double-quoted. The normally needed @-flag
# that logically breaks the concaetnated string back into array
# in case of double-quoting has additional effect for s-flag:
# it finally blocks empty-elements eradication.
if [[ "${__lines_list[1]}" = See* ]]; then
# (**)
# git >= v2.20
__lines_list=( ${(M)${${${(M)__lines_list[@]:# [[:blank:]]#[a-z]*}##[[:blank:]]##}%%[[:blank:]]##*}:#${FAST_HIGHLIGHT[chroma-git-subcommand]}} )
else
# (**)
# git < v2.20
__lines_list=( ${(M)${(s: :)${(M)__lines_list[@]:# [a-z]*}}:#${FAST_HIGHLIGHT[chroma-git-subcommand]}} )
fi
# Above we've checked:
# 1) If given subcommand is an alias (*)
# 2) If the command, or command pointed by the alias, exists (**)
# 3) There's little problem, git v2.20 outputs aliases in git help -a,
# which means that alias will be recognized as correct if it will
# point at another alias or on itself. That's a minor problem, a
# TODO for future planned optimization for v2.20 Git
# 4) Notice that the above situation is better than the previous - the
# alias is being verified to point to a valid git subcommand
# That's all that's needed to decide on the correctnes:
if (( ${#__lines_list} > 0 )); then
__style=${FAST_THEME_NAME}subcommand
else
__style=${FAST_THEME_NAME}incorrect-subtle
fi
fi
# The counter includes the subcommand itself
(( FAST_HIGHLIGHT[chroma-git-counter] += 1 ))
else
__wrd="${__wrd//\`/x}"
__arg="${__arg//\`/x}"
__wrd="${(Q)__wrd}"
if [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "push" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "pull" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "fetch" ]] \
&& (( ${FAST_HIGHLIGHT[chroma-git-fetch-multiple]} == 0 )); then
# if not option
if [[ "$__wrd" != -* || "${FAST_HIGHLIGHT[chrome-git-occurred-double-hyphen]}" -eq 1 ]]; then
(( FAST_HIGHLIGHT[chroma-git-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-git-counter] ))
if (( __idx1 == 2 )); then
.fast-run-git-command "git remote" "chroma-git-remotes" ""
else
__wrd="${__wrd%%:*}"
.fast-run-git-command "git for-each-ref --format='%(refname:short)' refs/heads" "chroma-git-branches" "refs/heads"
fi
# if remote/ref exists
if [[ -n ${__lines_list[(r)$__wrd]} ]]; then
(( __start=__start_pos-${#PREBUFFER}, __end=__start_pos+${#__wrd}-${#PREBUFFER}, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}")
# if ref (__idx1 == 3) does not exist and subcommand is push
elif (( __idx1 != 2 )) && [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "push" ]]; then
(( __start=__start_pos-${#PREBUFFER}, __end=__start_pos+${#__wrd}-${#PREBUFFER}, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
# if not existing remote name, because not an URL (i.e. no colon)
elif [[ $__idx1 -eq 2 && $__wrd != *:* ]]; then
(( __start=__start_pos-${#PREBUFFER}, __end=__start_pos+${#__wrd}-${#PREBUFFER}, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
fi
# if option
else
if [[ "$__wrd" = "--multiple" && "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "fetch" ]]; then
FAST_HIGHLIGHT[chroma-git-fetch-multiple]=1
__style=${FAST_THEME_NAME}double-hyphen-option
else
return 1
fi
fi
elif (( ${FAST_HIGHLIGHT[chroma-git-fetch-multiple]} )) \
&& [[ "$__wrd" != -* || "${FAST_HIGHLIGHT[chrome-git-occurred-double-hyphen]}" -eq 1 ]]; then
.fast-run-git-command "git remote" "chroma-git-remotes" ""
if [[ -n ${__lines_list[(r)$__wrd]} ]]; then
__style=${FAST_THEME_NAME}correct-subtle
fi
elif [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "commit" ]]; then
match[1]=""
match[2]=""
# if previous argument is -m or current argument is --message=something
if (( FAST_HIGHLIGHT[chrome-git-got-msg1] == 1 && ! FAST_HIGHLIGHT[chrome-git-got-anymsg] )) \
|| [[ "$__wrd" = (#b)(--message=)(*) && "${FAST_HIGHLIGHT[chrome-git-occurred-double-hyphen]}" = 0 ]]; then
FAST_HIGHLIGHT[chrome-git-got-msg1]=0
FAST_HIGHLIGHT[chrome-git-got-anymsg]=1
if [[ -n "${match[1]}" ]]; then
__wrd="${(Q)${match[2]//\`/x}}"
# highlight (--message=)something
(( __start=__start_pos-${#PREBUFFER}, __end=__start_pos-${#PREBUFFER}+10, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-hyphen-option]}")
# highlight --message=(something)
(( __start=__start_pos-${#PREBUFFER}+10, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}")
else
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}")
fi
local __firstline=${__wrd%%$'\n'*}
if (( ${#__firstline} > 50 )); then
for (( __idx1 = 1, __idx2 = 1; __idx1 <= 50; ++ __idx1, ++ __idx2 )); do
while [[ "${__arg[__idx2]}" != "${__firstline[__idx1]}" ]]; do
(( ++ __idx2 ))
(( __idx2 > __asize )) && { __idx2=-1; break; }
done
(( __idx2 == -1 )) && break
done
if (( __idx2 != -1 )); then
if [[ -n "${match[1]}" ]]; then
(( __start=__start_pos-${#PREBUFFER}+__idx2, __end=__end_pos-${#PREBUFFER}-$#__wrd+$#__firstline-1, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
else
(( __start=__start_pos-${#PREBUFFER}+__idx2-1, __end=__end_pos-${#PREBUFFER}-$#__wrd+$#__firstline-1, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
fi
fi
fi
# if before --
elif [[ "${FAST_HIGHLIGHT[chrome-git-occurred-double-hyphen]}" = 0 ]]; then
if [[ "$__wrd" = -[^[:space:]-]#m ]]; then
FAST_HIGHLIGHT[chrome-git-got-msg1]=1
__style=${FAST_THEME_NAME}single-hyphen-option
else
return 1
fi
# if after -- is file
elif [[ -e "$__wrd" ]]; then
__style=${FAST_THEME_NAME}path
else
__style=${FAST_THEME_NAME}incorrect-subtle
fi
elif [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "checkout" ]] \
|| [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "revert" ]] \
|| [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "merge" ]] \
|| [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "diff" ]] \
|| [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "reset" ]] \
|| [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "rebase" ]]; then
# if doing `git checkout -b ...'
if [[ "$__wrd" = -[^[:space:]-]#b && "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "checkout" ]]; then
FAST_HIGHLIGHT[chroma-git-checkout-new]=1
__style=${FAST_THEME_NAME}single-hyphen-option
# if command is not checkout -b something
elif [[ "${FAST_HIGHLIGHT[chroma-git-checkout-new]}" = 0 ]]; then
# if not option
if [[ "$__wrd" != -* || "${FAST_HIGHLIGHT[chrome-git-occurred-double-hyphen]}" = 1 ]]; then
(( FAST_HIGHLIGHT[chroma-git-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-git-counter] ))
if (( __idx1 == 2 )) || \
[[ "$__idx1" = 3 && "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "diff" ]]; then
# if is ref
if command git rev-parse --verify --quiet "$__wrd" >/dev/null 2>&1; then
__style=${FAST_THEME_NAME}correct-subtle
# if is file and subcommand is checkout or diff
elif [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "checkout" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "reset" \
|| "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "diff" ]] && [[ -e ${~__wrd} ]]; then
__style=${FAST_THEME_NAME}path
elif [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "checkout" && \
"1" = "$(command git rev-list --count --no-walk --glob="refs/remotes/${$(git \
config --get checkout.defaultRemote):-*}/$__wrd")" ]]
then
__style=${FAST_THEME_NAME}correct-subtle
else
__style=${FAST_THEME_NAME}incorrect-subtle
fi
fi
# if option
else
return 1
fi
# if option
elif [[ "${FAST_HIGHLIGHT[chrome-git-occurred-double-hyphen]}" = 0 && "$__wrd" = -* ]]; then
return 1
fi
elif [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "remote" && "$__wrd" != -* ]]; then
(( FAST_HIGHLIGHT[chroma-git-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-git-counter] ))
if [[ "$__idx1" = 2 ]]; then
if (( ${chroma_git_remote_subcommands[(I)$__wrd]} )); then
FAST_HIGHLIGHT[chroma-git-remote-subcommand]="$__wrd"
__style=${FAST_THEME_NAME}subcommand
else
__style=${FAST_THEME_NAME}incorrect-subtle
fi
elif [[ "$__idx1" = 3 && "$FAST_HIGHLIGHT[chroma-git-remote-subcommand]" = "add" ]]; then
.fast-run-git-command "git remote" "chroma-git-remotes" ""
if [[ -n ${__lines_list[(r)$__wrd]} ]]; then
__style=${FAST_THEME_NAME}incorrect-subtle
fi
elif [[ "$__idx1" = 3 && -n "$FAST_HIGHLIGHT[chroma-git-remote-subcommand]" ]]; then
.fast-run-git-command "git remote" "chroma-git-remotes" ""
if [[ -n ${__lines_list[(r)$__wrd]} ]]; then
__style=${FAST_THEME_NAME}correct-subtle
else
__style=${FAST_THEME_NAME}incorrect-subtle
fi
fi
elif [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "branch" ]]; then
if [[ "$__wrd" = --delete \
|| "$__wrd" = --edit-description \
|| "$__wrd" = --set-upstream-to=* \
|| "$__wrd" = --unset-upstream \
|| "$__wrd" = -[^[:space:]-]#d \
|| "$__wrd" = -[^[:space:]-]#D ]]; then
FAST_HIGHLIGHT[chroma-git-branch-change]=1
return 1
elif [[ "$__wrd" != -* ]]; then
.fast-run-git-command "git for-each-ref --format='%(refname:short)' refs/heads" "chroma-git-branches" "refs/heads"
if [[ -n ${__lines_list[(r)$__wrd]} ]]; then
__style=${FAST_THEME_NAME}correct-subtle
elif (( FAST_HIGHLIGHT[chroma-git-branch-change] )); then
__style=${FAST_THEME_NAME}incorrect-subtle
fi
else
return 1
fi
elif [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "tag" ]]; then
if [[ "${FAST_HIGHLIGHT[chroma-git-option-with-argument-active]}" -le 0 ]]; then
if [[ "$__wrd" = -[^[:space:]-]#(u|m) ]]; then
FAST_HIGHLIGHT[chroma-git-option-with-argument-active]=1
elif [[ "$__wrd" = -[^[:space:]-]#F ]]; then
FAST_HIGHLIGHT[chroma-git-option-with-argument-active]=2
elif [[ "$__wrd" = -[^[:space:]-]#d ]]; then
FAST_HIGHLIGHT[chroma-git-option-with-argument-active]=3
elif [[ "$__wrd" = (--contains|--no-contains|--points-at|--merged|--no-merged) ]]; then
FAST_HIGHLIGHT[chroma-git-option-with-argument-active]=4
fi
if [[ "$__wrd" != -* ]]; then
(( FAST_HIGHLIGHT[chroma-git-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-git-counter] ))
if [[ ${FAST_HIGHLIGHT[chroma-git-counter]} -eq 2 ]]; then
.fast-run-git-command "git for-each-ref --format='%(refname:short)' refs/heads" "chroma-git-branches" "refs/heads"
.fast-run-git-command "+git tag" "chroma-git-tags" ""
[[ -n ${__lines_list[(r)$__wrd]} ]] && __style=${FAST_THEME_NAME}incorrect-subtle
elif [[ ${FAST_HIGHLIGHT[chroma-git-counter]} -eq 3 ]]; then
fi
else
return 1
fi
else
case "${FAST_HIGHLIGHT[chroma-git-option-with-argument-active]}" in
(1)
__style=${FAST_THEME_NAME}optarg-string
;;
(2)
FAST_HIGHLIGHT[chroma-git-option-with-argument-active]=0
return 1;
;;
(3)
.fast-run-git-command "git tag" "chroma-git-tags" ""
[[ -n ${__lines_list[(r)$__wrd]} ]] && \
__style=${FAST_THEME_NAME}correct-subtle || \
__style=${FAST_THEME_NAME}incorrect-subtle
;;
(4)
if git rev-parse --verify --quiet "$__wrd" >/dev/null 2>&1; then
__style=${FAST_THEME_NAME}correct-subtle
else
__style=${FAST_THEME_NAME}incorrect-subtle
fi
;;
esac
FAST_HIGHLIGHT[chroma-git-option-with-argument-active]=0
fi
else
return 1
fi
fi
fi
fi
# Add region_highlight entry (via `reply' array)
if [[ -n "$__style" ]]; then
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
fi
# We aren't passing-through, do obligatory things ourselves
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,80 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Chroma function for command `perl'. It highlights code passed to perl
# with -e option - does syntax check by calling `perl -ce', then highlights
# as correct or incorrect code.
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
# $4 - a private copy of $_end_pos from the above scope
#
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style
integer __idx1 __idx2
(( __first_call )) && {
# Called for the first time - new command.
# FAST_HIGHLIGHT is used because it survives between calls, and
# allows to use a single global hash only, instead of multiple
# global variables.
FAST_HIGHLIGHT[chrome-perl-got-eswitch]=0
return 1
} || {
# Following call, i.e. not the first one.
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
if [[ "$__wrd" = -* && ${FAST_HIGHLIGHT[chroma-perl-got-subcommand]} -eq 0 ]]; then
__style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option}
if [[ "$__wrd" = "-e" || ("$__wrd" = -*e* && "$__wrd" != --*) ]]; then
FAST_HIGHLIGHT[chrome-perl-got-eswitch]=1
fi
else
__wrd="${__wrd//\`/x}"
__arg="${__arg//\`/x}"
__wrd="${(Q)__wrd}"
if (( FAST_HIGHLIGHT[chrome-perl-got-eswitch] == 1 )); then
FAST_HIGHLIGHT[chrome-perl-got-eswitch]=0
if perl -ce "$__wrd" >/dev/null 2>&1; then
# Add correct-subtle style
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}")
else
# Add incorrect-subtle style
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
fi
else
# Pass-through to the big-loop outside
return 1
fi
fi
}
# Add region_highlight entry (via `reply' array)
#
# This is a common place of adding such entry, but any above
# code can do it itself (and it does) and skip setting __style
# to disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through, do obligatory things ourselves
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,17 @@
# vim:ft=zsh:et:sw=4
local __first_call="$1" __start_pos="$3" __end_pos="$4"
[[ "$__arg_type" = 3 ]] && return 2
(( __first_call )) && {
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}precommand]}")
(( next_word = (next_word & ~2) | 4 | 1 ))
} || {
return 1
}
(( this_word = next_word ))
_start_pos=$_end_pos
return 0

View File

@ -0,0 +1,86 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Highlights the special sequences like "%s" in string passed to `printf'.
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
#
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg; the token can be eg.: "grep"
#
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
#
# $4 - a private copy of $_end_pos from the above scope
#
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style __val
integer __idx1 __idx2
# First call, i.e. command starts, i.e. "grep" token etc.
(( __first_call )) && {
FAST_HIGHLIGHT[chroma-printf-counter]=0
FAST_HIGHLIGHT[chroma-printf-counter-all]=1
FAST_HIGHLIGHT[chroma-printf-message]=""
FAST_HIGHLIGHT[chroma-printf-skip-two]=0
return 1
# Following call (not first one).
} || {
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
(( FAST_HIGHLIGHT[chroma-printf-counter-all] += 1, __idx2 = FAST_HIGHLIGHT[chroma-printf-counter-all] ))
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if [[ "$__wrd" = -* ]]; then
if [[ "$__wrd" = "-v" ]]; then
FAST_HIGHLIGHT[chroma-printf-skip-two]=1
fi
return 1
else
# Count non-option tokens.
if (( FAST_HIGHLIGHT[chroma-printf-skip-two] )); then
FAST_HIGHLIGHT[chroma-printf-skip-two]=0
return 1
else
(( FAST_HIGHLIGHT[chroma-printf-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-printf-counter] ))
if [[ "$__idx1" -eq 1 ]]; then
[[ "$__wrd" = \"* ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}")
[[ "$__wrd" = \'* ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}single-quoted-argument]}")
FSH_LIST=() # use fsh_sy_h_append function to write to FSH_LIST
: "${__wrd//(#m)\%[\#\+\ 0-]#[0-9]#([.][0-9]#)(#c0,1)[diouxXfFeEgGaAcsb]/$(( fsh_sy_h_append($MBEGIN, $MEND) ))}";
for __val in "${FSH_LIST[@]}" ; do
__idx1=$(( __start_pos + ${__val%%;;*} ))
__idx2=__idx1+${__val##*;;}-${__val%%;;*}+1
(( __start=__idx1-${#PREBUFFER}, __end=__idx2-${#PREBUFFER}-1, __start >= 0 )) && \
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}mathnum]}")
done
else
return 1
fi
fi
fi
}
# Add region_highlight entry (via `reply' array).
#
# This is a common place of adding such entry, but any above code
# can do it itself and skip setting __style to disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through (no return 1 occured), do obligatory things ourselves.
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,81 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Chroma function for command `ruby'. It highlights code passed to ruby
# with -e option - does syntax check by calling `ruby -ce', then highlights
# as correct or incorrect code.
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
# $4 - a private copy of $_end_pos from the above scope
#
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style
integer __idx1 __idx2
(( __first_call )) && {
# Called for the first time - new command.
# FAST_HIGHLIGHT is used because it survives between calls, and
# allows to use a single global hash only, instead of multiple
# global variables.
FAST_HIGHLIGHT[chrome-ruby-got-eswitch]=0
return 1
} || {
# Following call, i.e. not the first one.
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
if [[ "$__wrd" = -* && ${FAST_HIGHLIGHT[chroma-ruby-got-subcommand]} -eq 0 ]]; then
__style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option}
if [[ "$__wrd" = "-e" || ("$__wrd" = -*e* && "$__wrd" != --*) ]]; then
FAST_HIGHLIGHT[chrome-ruby-got-eswitch]=1
fi
else
__wrd="${__wrd//\`/x}"
__arg="${__arg//\`/x}"
__wrd="${(Q)__wrd}"
if (( FAST_HIGHLIGHT[chrome-ruby-got-eswitch] == 1 )); then
FAST_HIGHLIGHT[chrome-ruby-got-eswitch]=0
if ruby -ce "$__wrd" >/dev/null 2>&1; then
# Add correct-subtle style
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}")
else
# Add incorrect-subtle style
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
fi
else
# Pass-through to the big-loop outside
return 1
fi
FAST_HIGHLIGHT[chrome-ruby-got-eswitch]=0
fi
}
# Add region_highlight entry (via `reply' array)
#
# This is a common place of adding such entry, but any above
# code can do it itself (and it does) and skip setting __style
# to disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through, do obligatory things ourselves
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,87 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Tracks scp command and emits message when one tries to pass port to hostspec.
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
#
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg; the token can be eg.: "grep"
#
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
#
# $4 - a private copy of $_end_pos from the above scope
#
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style __chars
integer __idx1 __idx2
local -a __results
# First call, i.e. command starts, i.e. "grep" token etc.
(( __first_call )) && {
FAST_HIGHLIGHT[chroma-scp-counter]=0
FAST_HIGHLIGHT[chroma-scp-counter-all]=1
FAST_HIGHLIGHT[chroma-scp-message]=""
FAST_HIGHLIGHT[chroma-scp-skip-two]=0
return 1
} || {
(( FAST_HIGHLIGHT[chroma-scp-counter-all] += 1, __idx2 = FAST_HIGHLIGHT[chroma-scp-counter-all] ))
# Following call, i.e. not the first one.
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
if [[ "$__wrd" = -* ]]; then
# Detected option, add style for it.
[[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \
__style=${FAST_THEME_NAME}single-hyphen-option
if [[ "$__wrd" = (-c|-F|-i|-l|-o|-P|-S) ]]; then
FAST_HIGHLIGHT[chroma-scp-skip-two]=1
fi
else
# Count non-option tokens.
if (( FAST_HIGHLIGHT[chroma-scp-skip-two] )); then
FAST_HIGHLIGHT[chroma-scp-skip-two]=0
else
(( FAST_HIGHLIGHT[chroma-scp-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-scp-counter] ))
if [[ "${FAST_HIGHLIGHT[chroma-scp-counter]}" -eq 1 ]]; then
if [[ "$__arg" = [^:]##:[0-9]## ]]; then
FAST_HIGHLIGHT[chroma-scp-message]+="Format of hostname incorrect, use -P to pass port number"
else
return 1
fi
else
return 1
fi
fi
fi
if (( ${#${(z)BUFFER}} <= FAST_HIGHLIGHT[chroma-scp-counter-all] )); then
[[ -n "${FAST_HIGHLIGHT[chroma-scp-message]}" ]] && zle -M "${FAST_HIGHLIGHT[chroma-scp-message]}"
fi
}
# Add region_highlight entry (via `reply' array).
#
# This is a common place of adding such entry, but any above code
# can do it itself and skip setting __style to disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through (no return 1 occured), do obligatory things ourselves.
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,72 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Chroma function for `sh' shell. It colorizes string passed with -c option.
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
# $4 - a private copy of $_end_pos from the above scope
#
(( next_word = 2 | 8192 ))
local __first_call=$1 __wrd=$2 __start_pos=$3 __end_pos=$4
local __style
integer __idx1 __idx2
local -a __lines_list
(( __first_call )) && {
# Called for the first time - new command
FAST_HIGHLIGHT[chrome-git-got-c]=0
return 1
} || {
# Following call, i.e. not the first one
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ $__arg_type = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
__wrd=${${${(Q)__wrd}#[\"\']}%[\"\']}
if [[ $__wrd = -* && $__wrd != -*c* ]]; then
__style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option}
else
if (( FAST_HIGHLIGHT[chrome-git-got-c] == 1 )); then
for (( __idx1 = 1, __idx2 = 1; __idx2 <= __asize; ++ __idx1 )); do
[[ ${__arg[__idx2]} = ${__wrd[__idx1]} ]] && break
while [[ ${__arg[__idx2]} != ${__wrd[__idx1]} ]]; do
(( ++ __idx2 ))
(( __idx2 > __asize )) && { __idx2=0; break; }
done
(( __idx2 == 0 )) && break
[[ ${__arg[__idx2]} = ${__wrd[__idx1]} ]] && break
done
FAST_HIGHLIGHT[chrome-git-got-c]=0
(( _start_pos-__PBUFLEN >= 0 )) && \
-fast-highlight-process "$PREBUFFER" "${__wrd}" "$(( __start_pos + __idx2 - 1 ))"
elif [[ $__wrd = -*c* ]]; then
FAST_HIGHLIGHT[chrome-git-got-c]=1
else
return 1
fi
fi
}
# Add region_highlight entry (via `reply' array)
[[ -n $__style ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through, do obligatory things ourselves
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,75 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Chroma for `source' builtin - verifies if file to be sourced compiles
# correctly.
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
#
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg; the token can be eg.: "grep"
#
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
#
# $4 - a private copy of $_end_pos from the above scope
#
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style __chars __home=${XDG_CACHE_HOME:-$HOME/.cache}/fsh
integer __idx1 __idx2
# First call, i.e. command starts, i.e. "grep" token etc.
(( __first_call )) && {
FAST_HIGHLIGHT[chroma-src-counter]=0
__style=${FAST_THEME_NAME}builtin
} || {
# Following call, i.e. not the first one.
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
if [[ "$__wrd" = -* ]]; then
# Detected option, add style for it.
[[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \
__style=${FAST_THEME_NAME}single-hyphen-option
else
# Count non-option tokens.
(( FAST_HIGHLIGHT[chroma-src-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-src-counter] ))
if (( FAST_HIGHLIGHT[chroma-src-counter] == 1 )); then
command mkdir -p "$__home"
command cp -f "${__wrd}" "$__home" 2>/dev/null && {
zcompile "$__home"/"${__wrd:t}" 2>/dev/null 1>&2 && __style=${FAST_THEME_NAME}correct-subtle || __style=${FAST_THEME_NAME}incorrect-subtle
}
elif (( FAST_HIGHLIGHT[chroma-src-counter] == 2 )); then
# Handle paths, etc. normally - just pass-through to the big
# highlighter (the main FSH highlighter, used before chromas).
return 1
fi
fi
}
# Add region_highlight entry (via `reply' array).
#
# This is a common place of adding such entry, but any above
# code can do it itself (and it does) and skip setting __style
# to disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through (no return 1 occured), do obligatory things ourselves.
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,156 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
# Copyright (C) 2019 by Philippe Troin (F-i-f on GitHub)
#
# Tracks ssh command and emits message when one tries to pass port to hostspec.
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
#
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg; the token can be eg.: "grep"
#
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
#
# $4 - a private copy of $_end_pos from the above scope
#
emulate -LR zsh
setopt extended_glob warn_create_global typeset_silent
# This chroma guards that port number isn't passed in hostname (no :{port} occurs).
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style check_port=0 host_start_offset host_style user_style possible_host
local -a match mbegin mend completions_user completions_host
# First call, i.e. command starts, i.e. "grep" token etc.
(( __first_call )) && {
FAST_HIGHLIGHT[chroma-ssh-counter]=0
FAST_HIGHLIGHT[chroma-ssh-counter-all]=1
FAST_HIGHLIGHT[chroma-ssh-message]=""
FAST_HIGHLIGHT[chroma-ssh-skip-two]=0
return 1
} || {
# Following call, i.e. not the first one.
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
(( FAST_HIGHLIGHT[chroma-ssh-counter-all] += 1 ))
if [[ "$__wrd" = -* ]]; then
# Detected option, add style for it.
[[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \
__style=${FAST_THEME_NAME}single-hyphen-option
if [[ "$__wrd" = (-b|-c|-D|-E|-e|-F|-I|-i|-J|-L|-l|-m|-O|-o|-p|Q|R|-S|-W|-w) ]]; then
FAST_HIGHLIGHT[chroma-ssh-skip-two]=1
fi
else
if (( FAST_HIGHLIGHT[chroma-ssh-skip-two] )); then
FAST_HIGHLIGHT[chroma-ssh-skip-two]=0
else
# Count non-option tokens.
(( FAST_HIGHLIGHT[chroma-ssh-counter] += 1 ))
if [[ "${FAST_HIGHLIGHT[chroma-ssh-counter]}" -eq 1 ]]; then
if [[ $__arg = (#b)(([^@]#)(@)|)(*) ]]
then
[[ -n $match[2] ]] \
&& {
user_style=
() {
# Zstyle clobbers reply for sure
zstyle -a ":completion:*:users" users completions_users
}
(( ! $#completions_users )) && completions_users=(${(k)userdirs})
if (( $#completions_users )); then
[[ $match[2] = ${~${:-(${(j:|:)completions_users})}} ]] \
&& user_style=${FAST_THEME_NAME}correct-subtle \
|| user_style=${FAST_THEME_NAME}incorrect-subtle
fi
[[ -n $user_style ]] \
&& (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}-(mend[5]-mend[2]), __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$user_style]}")
}
[[ -n $match[3] ]] \
&& (( __start=__start_pos-${#PREBUFFER}+(mbegin[3]-mbegin[1]), __end=__end_pos-${#PREBUFFER}-(mend[5]-mend[3]), __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subtle-separator]}")
host_style=
case $match[4] in
(<->|<0-255>.<0-255>.<0-255>.<0-255>)
host_style=${FAST_THEME_NAME}mathnum
check_port=1
;;
(([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])
host_style=${FAST_THEME_NAME}mathnum
;;
(*)
check_port=1
;;
esac
possible_host=$match[4]
(( host_start_offset = mbegin[4] - mbegin[1], host_end_offset = 0 ))
if (( check_port )) && [[ $possible_host = (#b)(*)(:[0-9]##) ]]; then
(( __start=__start_pos-${#PREBUFFER}+(host_start_offset+mbegin[2]-mbegin[1]), __end=__end_pos-host_end_offset-${#PREBUFFER}, __start >= 0,
host_end_offset+=mend[2]-mend[1] )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") \
&& possible_host=$match[1] \
&& FAST_HIGHLIGHT[chroma-ssh-message]+="Format of hostname incorrect, use -p to pass port number"
fi
if [[ -z $host_style ]]; then
() {
# Zstyle clobbers reply for sure
local mbegin mend match reply
zstyle -a ":completion:*:hosts" hosts completions_host
}
(( ! $#completions_host && $+_cache_hosts )) && completions_host=($_cache_hosts[*])
if (( $#completions_host )); then
[[ $possible_host = ${~${:-(${(j:|:)completions_host})}} ]] \
&& host_style=${FAST_THEME_NAME}correct-subtle \
|| host_style=${FAST_THEME_NAME}incorrect-subtle
fi
fi
[[ -n $host_style ]] \
&& (( __start=__start_pos-${#PREBUFFER}+host_start_offset, __end=__end_pos-${#PREBUFFER}-host_end_offset, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$host_style]}")
else
__style=${FAST_THEME_NAME}incorrect-subtle
fi
(( next_word = 1 ))
fi
fi
fi
if (( ${#${(z)BUFFER}} <= FAST_HIGHLIGHT[chroma-ssh-counter-all] )); then
[[ -n "${FAST_HIGHLIGHT[chroma-ssh-message]}" ]] && zle -M "${FAST_HIGHLIGHT[chroma-ssh-message]}"
fi
}
# Add region_highlight entry (via `reply' array).
#
# This is a common place of adding such entry, but any above code
# can do it itself and skip setting __style to disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through (no return 1 occured), do obligatory things ourselves.
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,25 @@
# vim:ft=zsh:et:sw=4
(( next_word = 2 | 8192 ))
[[ "$__arg_type" = 3 ]] && return 2
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
if (( __first_call )); then
FAST_HIGHLIGHT[chroma-subcommand]=""
return 1
elif (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
elif [[ "$2" = -* ]]; then
return 1
elif [[ -z "${FAST_HIGHLIGHT[chroma-subcommand]}" ]]; then
FAST_HIGHLIGHT[chroma-subcommand]="$__wrd"
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}")
else
return 1
fi
(( this_word = next_word ))
_start_pos=$_end_pos
return 0

View File

@ -0,0 +1,250 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2018 Sebastian Gniazdowski
# Copyright (C) 2019 by Philippe Troin (F-i-f on GitHub)
# All rights reserved.
#
# The only licensing for this file follows.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
→chroma/-subversion.ch/parse-revision() {
setopt local_options extendedglob warn_create_global typeset_silent
local __wrd="$1" __start_pos="$2" __end_pos="$3" __style __start __end
case $__wrd in
(r|)[0-9]##) __style=${FAST_THEME_NAME}mathnum ;;
(HEAD|BASE|COMITTED|PREV)) __style=${FAST_THEME_NAME}correct-subtle ;;
'{'[^}]##'}') __style=${FAST_THEME_NAME}subtle-bg ;;
*) __style=${FAST_THEME_NAME}incorrect-subtle ;;
esac
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
}
→chroma/-subversion.ch/parse-target() {
setopt local_options extendedglob warn_create_global typeset_silent
local __wrd="$1" __start_pos="$2" __end_pos="$3" __style __start __end
if [[ $__wrd == *@[^/]# ]]
then
local place=${__wrd%@[^/]#}
local rev=$__wrd[$(($#place+2)),$#__wrd]
if [[ -e $place ]]; then
local __style
[[ -d $place ]] && __style="${FAST_THEME_NAME}path-to-dir" || __style="${FAST_THEME_NAME}path"
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}-$#rev-1, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
fi
(( __start=__start_pos-${#PREBUFFER}+$#place, __end=__end_pos-${#PREBUFFER}-$#rev, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}for-loop-separator]}")
→chroma/-subversion.ch/parse-revision $rev $((__start_pos+$#place+1)) $__end_pos
else
return 1
fi
}
setopt local_options extendedglob warn_create_global
# Keep chroma-takever state meaning: until ;, handle highlighting via chroma.
# So the below 8192 assignment takes care that next token will be routed to chroma.
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style
integer __idx1 __idx2
(( __first_call )) && {
# Called for the first time - new command.
# FAST_HIGHLIGHT is used because it survives between calls, and
# allows to use a single global hash only, instead of multiple
# global string variables.
FAST_HIGHLIGHT[subversion-command]=$__wrd
FAST_HIGHLIGHT[subversion-option-argument]=
FAST_HIGHLIGHT[subversion-subcommand]=
FAST_HIGHLIGHT[subversion-subcommand-arguments]=0
# Set style for region_highlight entry. It is used below in
# '[[ -n "$__style" ]] ...' line, which adds highlight entry,
# like "10 12 fg=green", through `reply' array.
#
# Could check if command `example' exists and set `unknown-token'
# style instead of `command'
__style=${FAST_THEME_NAME}command
} || {
# Following call, i.e. not the first one
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
if [[ "$__wrd" = -* ]]; then
# Detected option, add style for it.
[[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \
__style=${FAST_THEME_NAME}single-hyphen-option
case $FAST_HIGHLIGHT[subversion-command]/$FAST_HIGHLIGHT[subversion-subcommand] in
svn/)
case $__wrd in
--username|-u) FAST_HIGHLIGHT[subversion-option-argument]=any;;
--password|-p) FAST_HIGHLIGHT[subversion-option-argument]=any;;
--config-(dir|option)) FAST_HIGHLIGHT[subversion-option-argument]=any;;
esac
;;
svn/?*)
case $__wrd in
--accept) FAST_HIGHLIGHT[subversion-option-argument]=accept;;
--change|-c) FAST_HIGHLIGHT[subversion-option-argument]=revision;;
--changelist|--cl) FAST_HIGHLIGHT[subversion-option-argument]=any;;
--(set-|)depth) FAST_HIGHLIGHT[subversion-option-argument]=depth;;
--diff(3|)-cmd) FAST_HIGHLIGHT[subversion-option-argument]=cmd;;
--editor-cmd) FAST_HIGHLIGHT[subversion-option-argument]=cmd;;
--encoding) FAST_HIGHLIGHT[subversion-option-argument]=any;;
--file) FAST_HIGHLIGHT[subversion-option-argument]=any;;
--limit|-l) FAST_HIGHLIGHT[subversion-option-argument]=number;;
--message|-m) FAST_HIGHLIGHT[subversion-option-argument]=any;;
--native-eol) FAST_HIGHLIGHT[subversion-option-argument]=eol;;
--new|--old) FAST_HIGHLIGHT[subversion-option-argument]=target;;
--revision|-r) FAST_HIGHLIGHT[subversion-option-argument]=revision-pair;;
--show-revs) FAST_HIGHLIGHT[subversion-option-argument]=show-revs;;
--strip) FAST_HIGHLIGHT[subversion-option-argument]=number;;
--with-revprop) FAST_HIGHLIGHT[subversion-option-argument]=revprop;;
esac
;;
svnadmin/*)
case $__wrd in
--config-dir) FAST_HIGHLIGHT[subversion-option-argument]=any;;
--fs-type) FAST_HIGHLIGHT[subversion-option-argument]=any;;
--memory-cache-size|-M) FAST_HIGHLIGHT[subversion-option-argument]=number;;
--parent-dir) FAST_HIGHLIGHT[subversion-option-argument]=any;;
--revision|-r) FAST_HIGHLIGHT[subversion-option-argument]=revision-pair;;
esac
;;
svndumpfilter/*)
case $__wrd in
--targets) FAST_HIGHLIGHT[subversion-option-argument]=any;;
esac
;;
esac
elif [[ -n $FAST_HIGHLIGHT[subversion-option-argument] ]]; then
case $FAST_HIGHLIGHT[subversion-option-argument] in
any)
FAST_HIGHLIGHT[subversion-option-argument]=
return 1
;;
accept)
[[ $__wrd = (p(|ostpone)|e(|dit)|l(|aunch)|base|working|recommended|[mt][cf]|(mine|theirs)-(conflict|full)) ]] \
&& __style=${FAST_THEME_NAME}correct-subtle \
|| __style=${FAST_THEME_NAME}incorrect-subtle
;;
depth)
[[ $__wrd = (empty|files|immediates|infinity) ]] \
&& __style=${FAST_THEME_NAME}correct-subtle \
|| __style=${FAST_THEME_NAME}incorrect-subtle
;;
number)
[[ $__wrd = [0-9]## ]] \
&& __style=${FAST_THEME_NAME}mathnum \
|| __style=${FAST_THEME_NAME}incorrect-subtle
;;
eol)
[[ $__wrd = (CR(|LF)|LF) ]] \
&& __style=${FAST_THEME_NAME}correct-subtle \
|| __style=${FAST_THEME_NAME}incorrect-subtle
;;
show-revs)
[[ $__wrd = (merged|eligible) ]] \
&& __style=${FAST_THEME_NAME}correct-subtle \
|| __style=${FAST_THEME_NAME}incorrect-subtle
;;
revision)
→chroma/-subversion.ch/parse-revision $__wrd $__start_pos $__end_pos
;;
revision-pair)
local -a match mbegin mend
if [[ $__wrd = (#b)(\{[^}]##\}|[^:]##)(:)(*) ]]; then
→chroma/-subversion.ch/parse-revision $match[1] $__start_pos $(( __end_pos - ( mend[3]-mend[2] ) - 1 ))
→chroma/-subversion.ch/parse-revision $match[3] $(( __start_pos + ( mbegin[3]-mbegin[1] ) )) $__end_pos
(( __start=__start_pos-${#PREBUFFER}+(mbegin[2]-mbegin[1]), __end=__end_pos-${#PREBUFFER}-(mend[3]-mend[2]), __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}for-loop-separator]}")
else
→chroma/-subversion.ch/parse-revision $__wrd $__start_pos $__end_pos
fi
;;
target)
→chroma/-subversion.ch/parse-target $__wrd $__start_pos $__end_pos || return $?
;;
cmd)
this_word=1
return 1
;;
esac
FAST_HIGHLIGHT[subversion-option-argument]=
elif [[ -z $FAST_HIGHLIGHT[subversion-subcommand] ]]
then
FAST_HIGHLIGHT[subversion-subcommand]=$__wrd
local subcmds
case $FAST_HIGHLIGHT[subversion-command] in
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)' ;;
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)";;
svndumpfilter) subcmds='(include|exclude|help|\?)';;
esac
[[ $FAST_HIGHLIGHT[subversion-subcommand] = $~subcmds ]] \
&& __style=${FAST_THEME_NAME}subcommand \
|| __style=${FAST_THEME_NAME}incorrect-subtle
FAST_HIGHLIGHT[subversion-subcommand-arguments]=0
else
(( FAST_HIGHLIGHT[subversion-subcommand-arguments]+=1 ))
if [[ ( $FAST_HIGHLIGHT[subversion-subcommand] == (checkout|co|export|log|merge|switch|sw) && $FAST_HIGHLIGHT[subversion-subcommand-arguments] -eq 1 ) \
|| $FAST_HIGHLIGHT[subversion-subcommand] == (blame|praise|annotate|ann|cat|copy|cp|diff|info|list|ls|mergeinfo) ]]; then
→chroma/-subversion.ch/parse-target $__wrd $__start_pos $__end_pos || return $?
else
return 1
fi
fi
}
# Add region_highlight entry (via `reply' array).
# If 1 will be added to __start_pos, this will highlight "oken".
# If 1 will be subtracted from __end_pos, this will highlight "toke".
# $PREBUFFER is for specific situations when users does command \<ENTER>
# i.e. when multi-line command using backslash is entered.
#
# This is a common place of adding such entry, but any above code can do
# it itself (and it does in other chromas) and skip setting __style to
# this way disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through, do obligatory things ourselves.
# _start_pos=$_end_pos advainces pointers in command line buffer.
#
# To pass through means to `return 1'. The highlighting of
# this single token is then done by fast-syntax-highlighting's
# main code and chroma doesn't have to do anything.
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,51 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Chroma for vim, shows last opened files under prompt.
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
#
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg; the token can be eg.: "grep"
#
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
#
# $4 - a private copy of $_end_pos from the above scope
#
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style __chars
integer __idx1 __idx2
local -a __viminfo
# First call, i.e. command starts, i.e. "grep" token etc.
(( __first_call )) && {
(( ${+commands[vim]} )) && __style=${FAST_THEME_NAME}command || __style=${FAST_THEME_NAME}unknown-token
{ __viminfo=( ${(f)"$(<$HOME/.viminfo)"} ); } >> /dev/null
__viminfo=( "${${(M)__viminfo[@]:#>*}[@]:t}" )
__viminfo=( "${__viminfo[@]:#COMMIT_EDITMSG}" )
zle -M "Last opened:"$'\n'"${(F)__viminfo[1,5]}"
} || {
# Pass almost everything to big loop
return 1
}
# Add region_highlight entry (via `reply' array).
#
# This is a common place of adding such entry, but any above
# code can do it itself (and it does, see other chromas) and
# skip setting __style to disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through (no return 1 occured), do obligatory things ourselves.
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,138 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018-2019 Sebastian Gniazdowski
(( next_word = 2 | 8192 ))
local THEFD check __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style
(( ! ${+FAST_HIGHLIGHT[whatis_chroma_callback_was_ran]} )) && \
FAST_HIGHLIGHT[whatis_chroma_callback_was_ran]=0
(( ! ${+FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]} )) && {
is-at-least 5.0.6 && local __res=1 || local __res=0
FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]="$__res"
}
-fast-whatis-chroma-callback() {
emulate -L zsh
setopt extendedglob warncreateglobal typesetsilent
local THEFD="$1" input check=2 nl=$'\n' __wrd __style
.fast-zts-read-all "$THEFD" input
zle -F "$THEFD"
exec {THEFD}<&-
__wrd="${${input#[^$nl]#$nl}%%$nl*}"
if [[ "$input" = test* ]]; then
if [[ "${input%$nl}" = *[^0-9]'0' ]]; then
if [[ "${input#test$nl}" = *nothing\ appropriate* ]]; then
FAST_HIGHLIGHT[whatis_chroma_type]=2
else
FAST_HIGHLIGHT[whatis_chroma_type]=0
fi
else
FAST_HIGHLIGHT[whatis_chroma_type]=1
fi
elif [[ "$input" = type2* ]]; then
[[ "$input" != *nothing\ appropriate* ]] && check=1 || check=0
elif [[ "$input" = type1* ]]; then
[[ "${input%$nl}" = *0 ]] && check=1 || check=0
fi
if (( check != 2 )); then
FAST_HIGHLIGHT[whatis-cache-$__wrd]=$check
if (( check )) then
__style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}
elif [[ ${~__wrd} = */* && -e ${~__wrd} ]] then
__style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]}
else
__style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}
fi
local -a start_end
start_end=( ${(s:/:)${${(M)${${input#type?${nl}[^$nl]#$nl}}#*$nl}%$nl}} )
(( start_end[1] >= 0 )) && region_highlight+=("$start_end[1] $start_end[2] $__style")
zle -R
fi
FAST_HIGHLIGHT[whatis_chroma_callback_was_ran]=1
return 0
}
zle -N -- -fast-whatis-chroma-callback
if (( __first_call )) && [[ -z "${FAST_HIGHLIGHT[whatis_chroma_type]}" ]] ;then
if ! command -v whatis > /dev/null; then
FAST_HIGHLIGHT[whatis_chroma_type]=0
return 1
fi
exec {THEFD}< <(
print "test"
LANG=C whatis "osx whatis fallback check"
print "$?"
)
command true # a workaround of Zsh bug
zle -F ${${FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]:#0}:+-w} "$THEFD" -fast-whatis-chroma-callback
fi
[[ "$__arg_type" = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
if (( __first_call )) || [[ "$__wrd" = -* ]]; then
return 1
elif (( ! FAST_HIGHLIGHT[whatis_chroma_type] )); then
# Return 1 (i.e. treat the argument as a path) only if the callback have
# had a chance to establish the whatis_chroma_type field
(( FAST_HIGHLIGHT[whatis_chroma_callback_was_ran] )) && return 1
else
if [[ -z "${FAST_HIGHLIGHT[whatis-cache-$__wrd]}" ]]; then
if (( FAST_HIGHLIGHT[whatis_chroma_type] == 2 )); then
exec {THEFD}< <(
print "type2"
print "$__wrd"
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER} ))
print "$__start/$__end"
LANG=C whatis "$__wrd" 2>/dev/null
)
command true # see above
zle -F ${${FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]:#0}:+-w} "$THEFD" -fast-whatis-chroma-callback
else
exec {THEFD}< <(
print "type1"
print "$__wrd"
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER} ))
print "$__start/$__end"
LANG=C whatis "$__wrd" &> /dev/null
print "$?"
)
command true
zle -F ${${FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]:#0}:+-w} "$THEFD" -fast-whatis-chroma-callback
fi
__style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \
reply+=("$__start $__end $__style")
else
check=${FAST_HIGHLIGHT[whatis-cache-$__wrd]}
if (( check )) then
__style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}
elif [[ ${~__wrd} = */* && -e ${~__wrd} ]] then
__style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]}
elif (( FAST_HIGHLIGHT[whatis_chroma_type] )); then
__style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}
fi
[[ -n "$__style" ]] && \
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \
reply+=("$__start $__end $__style")
fi
fi
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4:sts=4

View File

@ -0,0 +1,96 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Outputs (under prompt) result of query done with `which', `type -w',
# `whence -v', `whereis', `whatis'.
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
#
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg; the token can be eg.: "grep"
#
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
#
# $4 - a private copy of $_end_pos from the above scope
#
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style __output __chars
integer __idx1 __idx2
local -a __results
# First call, i.e. command starts, i.e. "grep" token etc.
(( __first_call )) && {
FAST_HIGHLIGHT[chroma-which-counter]=0
FAST_HIGHLIGHT[chroma-which-counter-all]=1
FAST_HIGHLIGHT[chroma-which-message]=""
FAST_HIGHLIGHT[chroma-which-skip-two]=0
__style=${FAST_THEME_NAME}command
__output=""
# Following call (not first one).
} || {
(( FAST_HIGHLIGHT[chroma-which-counter-all] += 1, __idx2 = FAST_HIGHLIGHT[chroma-which-counter-all] ))
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
fi
if [[ "$__wrd" = -* ]]; then
# Detected option, add style for it.
[[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \
__style=${FAST_THEME_NAME}single-hyphen-option
if [[ "$__wrd" = "-x" ]]; then
FAST_HIGHLIGHT[chroma-which-skip-two]=1
fi
else
# Count non-option tokens.
if (( FAST_HIGHLIGHT[chroma-which-skip-two] )); then
FAST_HIGHLIGHT[chroma-which-skip-two]=0
else
(( FAST_HIGHLIGHT[chroma-which-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-which-counter] ))
if [[ "$__idx1" -eq 1 ]]; then
__chars="{"
__output="$(command which "$__wrd" 2>/dev/null)"
FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"command which: $__output"
__output="$(builtin which "$__wrd" 2>/dev/null)"
FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"builtin which: ${${${${__output[1,100]}//$'\n'/;}//$'\t'/ }//$__chars;/$__chars}${__output[101,101]:+...}"
__output="$(builtin type -w "$__wrd" 2>/dev/null)"
FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"type -w: $__output"
__output="$(builtin whence -v "$__wrd" 2>/dev/null)"
FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"whence -v: $__output"
__output="$(command whereis "$__wrd" 2>/dev/null)"
FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"whereis: $__output"
__output="$(command whatis "$__wrd" 2>/dev/null)"
__output="${${__output%%$'\n'*}//[[:blank:]]##/ }"
FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"whatis: $__output"
fi
fi
fi
if (( ${#${(z)BUFFER}} <= FAST_HIGHLIGHT[chroma-which-counter-all] )); then
[[ -n "${FAST_HIGHLIGHT[chroma-which-message]}" ]] && zle -M "${FAST_HIGHLIGHT[chroma-which-message]#$'\n'}"
fi
}
# Add region_highlight entry (via `reply' array).
#
# This is a common place of adding such entry, but any above code
# can do it itself and skip setting __style to disable this code.
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
# We aren't passing-through (no return 1 occured), do obligatory things ourselves.
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,378 @@
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2018-2019 Sebastian Gniazdowski
#
# Chroma function for command `git'. It colorizes the part of command
# line that holds `git' invocation.
(( FAST_HIGHLIGHT[-zinit.ch-chroma-def] )) && return 1
FAST_HIGHLIGHT[-zinit.ch-chroma-def]=1
typeset -gA fsh__zinit__chroma__def
fsh__zinit__chroma__def=(
##
## No subcommand
##
## {{{
subcmd:NULL "NULL_0_opt"
NULL_0_opt "(-help|--help|-h)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
"subcommands" "(help|man|self-update|cd|times|zstatus|load|light|unload|snippet|ls|ice|<ice|specification>|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)"
## }}}
# Generic actions
NO_MATCH_\#_opt "* <<>> __style=\${FAST_THEME_NAME}incorrect-subtle // NO-OP"
NO_MATCH_\#_arg "__style=\${FAST_THEME_NAME}incorrect-subtle // NO-OP"
##
## `ice'
##
## {{{
subcmd:ice "ICE_#_arg // NO_MATCH_#_opt"
"ICE_#_arg" "NO-OP // ::→chroma/-zinit-check-ice-mod"
## }}}
##
## `snippet'
##
## {{{
subcmd:snippet "SNIPPET_0_opt // SNIPPET_1_arg // NO_MATCH_#_opt //
NO_MATCH_#_arg"
SNIPPET_0_opt "(-f|--command)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
SNIPPET_1_arg "NO-OP // ::→chroma/-zinit-verify-snippet"
## }}}
##
## `load'
##
## {{{
"subcmd:load"
"LOAD_1_arg // LOAD_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg"
LOAD_1_arg "NO-OP // ::→chroma/-zinit-verify-plugin"
LOAD_2_arg "NO-OP // ::→chroma/-zinit-verify-plugin"
## }}}
##
## `compile|uncompile|stress|edit|glance|recall|status|cd|changes`
##
## {{{
"subcmd:(compile|uncompile|stress|edit|glance|recall|status|cd|changes)"
"PLGSNP_1_arg // PLGSNP_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg"
PLGSNP_1_arg "NO-OP // ::→chroma/-zinit-verify-plugin-or-snippet"
PLGSNP_2_arg "NO-OP // ::→chroma/-zinit-verify-plugin-or-snippet"
## }}}
##
## `update'
##
## {{{
subcmd:update "UPDATE_0_opt // PLGSNP_1_arg // PLGSNP_2_arg //
NO_MATCH_#_opt // NO_MATCH_#_arg"
UPDATE_0_opt "
(--all|-r|--reset|-q|--quiet|-p|--parallel)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
## }}}
##
## `light'
##
## {{{
subcmd:light "LIGHT_0_opt // LOAD_1_arg // LOAD_2_arg // NO_MATCH_#_opt //
NO_MATCH_#_arg"
LIGHT_0_opt "-b
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
## }}}
##
## `unload'
##
## {{{
subcmd:unload "UNLOAD_0_opt // UNLOAD_1_arg // UNLOAD_2_arg // NO_MATCH_#_opt //
NO_MATCH_#_arg"
UNLOAD_0_opt "-q
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
UNLOAD_1_arg "NO-OP // ::→chroma/-zinit-verify-loaded-plugin"
UNLOAD_2_arg "NO-OP // ::→chroma/-zinit-verify-loaded-plugin"
## }}}
##
## `report'
##
## {{{
subcmd:report "REPORT_0_opt // UNLOAD_1_arg // UNLOAD_2_arg // NO_MATCH_#_opt //
NO_MATCH_#_arg"
REPORT_0_opt "--all
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
## }}}
##
## `delete'
##
## {{{
"subcmd:delete"
"DELETE_0_opt // PLGSNP_1_arg // PLGSNP_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg"
DELETE_0_opt "
(--all|--clean|-y|--yes|-q|--quiet)
<<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
## }}}
##
## `cenable'
##
## {{{
subcmd:cenable "COMPLETION_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg"
COMPLETION_1_arg "NO-OP // ::→chroma/-zinit-verify-disabled-completion"
## }}}
##
## `cdisable'
##
## {{{
subcmd:cdisable "DISCOMPLETION_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg"
DISCOMPLETION_1_arg "NO-OP // ::→chroma/-zinit-verify-completion"
## }}}
##
## `light'
##
## {{{
subcmd:uncompile "UNCOMPILE_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg"
UNCOMPILE_1_arg "NO-OP // ::→chroma/-zinit-verify-compiled-plugin"
## }}}
##
## `*'
##
## {{{
"subcmd:*" "CATCH_ALL_#_opt"
"CATCH_ALL_#_opt" "* <<>> NO-OP // ::→chroma/main-chroma-std-aopt-SEMI-action"
## }}}
)
#→chroma/-zinit-first-call() {
# This is being done in the proper place - in -fast-highlight-process
#FAST_HIGHLIGHT[chroma-zinit-ice-elements-svn]=0
#}
→chroma/-zinit-verify-plugin() {
local _scmd="$1" _wrd="$4"
[[ -d "$_wrd" ]] && \
{ __style=${FAST_THEME_NAME}correct-subtle; return 0; }
typeset -a plugins
plugins=( "${ZINIT[PLUGINS_DIR]}"/*(N:t) )
plugins=( "${plugins[@]//---//}" )
plugins=( "${plugins[@]:#_local/zinit}" )
plugins=( "${plugins[@]:#custom}" )
[[ -n "${plugins[(r)$_wrd]}" ]] && \
__style=${FAST_THEME_NAME}correct-subtle || \
return 1
#__style=${FAST_THEME_NAME}incorrect-subtle
return 0
}
→chroma/-zinit-verify-plugin-or-snippet() {
→chroma/-zinit-verify-plugin "$1" "" "" "$4" || \
→chroma/-zinit-verify-snippet "$1" "" "" "$4"
return $?
}
→chroma/-zinit-verify-loaded-plugin() {
local _scmd="$1" _wrd="$4"
typeset -a plugins absolute1 absolute2 absolute3 normal
plugins=( "${ZINIT_REGISTERED_PLUGINS[@]:#_local/zinit}" )
normal=( "${plugins[@]:#%*}" )
absolute1=( "${(M)plugins[@]:#%*}" )
absolute1=( "${absolute1[@]/\%\/\//%/}" )
local hm="${HOME%/}"
absolute2=( "${absolute1[@]/$hm/HOME}" )
absolute3=( "${absolute1[@]/\%/}" )
plugins=( $absolute1 $absolute2 $absolute3 $normal )
[[ -n "${plugins[(r)$_wrd]}" ]] && \
__style=${FAST_THEME_NAME}correct-subtle || \
return 1
#__style=${FAST_THEME_NAME}incorrect-subtle
return 0
}
→chroma/-zinit-verify-completion() {
local _scmd="$1" _wrd="$4"
# Find enabled completions
typeset -a completions
completions=( "${ZINIT[COMPLETIONS_DIR]}"/_*(N:t) )
completions=( "${completions[@]#_}" )
[[ -n "${completions[(r)${_wrd#_}]}" ]] && \
__style=${FAST_THEME_NAME}correct-subtle || \
return 1
return 0
}
→chroma/-zinit-verify-disabled-completion() {
local _scmd="$1" _wrd="$4"
# Find enabled completions
typeset -a completions
completions=( "${ZINIT[COMPLETIONS_DIR]}"/[^_]*(N:t) )
[[ -n "${completions[(r)${_wrd#_}]}" ]] && \
__style=${FAST_THEME_NAME}correct-subtle || \
return 1
return 0
}
→chroma/-zinit-verify-compiled-plugin() {
local _scmd="$1" _wrd="$4"
typeset -a plugins
plugins=( "${ZINIT[PLUGINS_DIR]}"/*(N) )
typeset -a show_plugins p matches
for p in "${plugins[@]}"; do
matches=( $p/*.zwc(N) )
if [ "$#matches" -ne "0" ]; then
p="${p:t}"
[[ "$p" = (_local---zinit|custom) ]] && continue
p="${p//---//}"
show_plugins+=( "$p" )
fi
done
[[ -n "${show_plugins[(r)$_wrd]}" ]] && \
{ __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \
return 1
}
→chroma/-zinit-verify-snippet() {
local _scmd="$1" url="$4" dirname local_dir
url="${${url#"${url%%[! $'\t']*}"}%/}"
id_as="${FAST_HIGHLIGHT[chroma-zinit-ice-elements-id-as]:-${ZINIT_ICE[id-as]:-$url}}"
filename="${${id_as%%\?*}:t}"
dirname="${${id_as%%\?*}:t}"
local_dir="${${${id_as%%\?*}:h}/:\/\//--}"
[[ "$local_dir" = "." ]] && local_dir="" || local_dir="${${${${${local_dir#/}//\//--}//=/--EQ--}//\?/--QM--}//\&/--AMP--}"
local_dir="${ZINIT[SNIPPETS_DIR]}${local_dir:+/$local_dir}"
(( ${+ZINIT_ICE[svn]} || ${FAST_HIGHLIGHT[chroma-zinit-ice-elements-svn]} )) && {
# TODO: handle the SVN path's specifics
[[ -d "$local_dir/$dirname" ]] && \
{ __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \
return 1
} || {
# TODO: handle the non-SVN path's specifics
[[ -d "$local_dir/$dirname" ]] && \
{ __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \
return 1
}
}
→chroma/-zinit-check-ice-mod() {
local _scmd="$1" _wrd="$4"
[[ "$_wrd" = (svn(\'|\")*|svn) ]] && \
FAST_HIGHLIGHT[chroma-zinit-ice-elements-svn]=1
[[ "$_wrd" = (#b)(id-as(:|)(\'|\")(*)(\'|\")|id-as:(*)|id-as(*)) ]] && \
FAST_HIGHLIGHT[chroma-zinit-ice-elements-id-as]="${match[4]}${match[6]}${match[7]}"
# Copy from zinit-autoload.zsh / -zplg-recall
local -a ice_order nval_ices ext_val_ices
ext_val_ices=( ${(@)${(@Ms.|.)ZINIT_EXTS[ice-mods]:#*\'\'*}//\'\'/} )
ice_order=(
svn proto from teleid bindmap cloneopts id-as depth if wait load
unload blockf pick bpick src as ver silent lucid notify mv cp
atinit atclone atload atpull nocd run-atpull has cloneonly make
service trackbinds multisrc compile nocompile nocompletions
reset-prompt wrap-track reset sh \!sh bash \!bash ksh \!ksh csh
\!csh aliases countdown ps-on-unload ps-on-update trigger-load
light-mode is-snippet atdelete pack git verbose on-update-of
subscribe param extract
# Include all additional ices after
# stripping them from the possible: ''
${(@s.|.)${ZINIT_EXTS[ice-mods]//\'\'/}}
)
nval_ices=(
blockf silent lucid trackbinds cloneonly nocd run-atpull
nocompletions sh \!sh bash \!bash ksh \!ksh csh \!csh
aliases countdown light-mode is-snippet git verbose
# Include only those additional ices,
# don't have the '' in their name, i.e.
# aren't designed to hold value
${(@)${(@s.|.)ZINIT_EXTS[ice-mods]}:#*\'\'*}
# Must be last
svn
)
if [[ "$_wrd" = (#b)(${(~j:|:)${ice_order[@]:#(${(~j:|:)nval_ices[@]:#(${(~j:|:)ext_val_ices[@]})})}})(*) ]]; then
reply+=("$(( __start )) $(( __start+${mend[1]} )) ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-hyphen-option]}")
reply+=("$(( __start+${mbegin[2]} )) $(( __end )) ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}optarg-string]}")
-fast-highlight-string
return 0
elif [[ "$_wrd" = (#b)(${(~j:|:)nval_ices[@]}) ]]; then
__style=${FAST_THEME_NAME}single-hyphen-option
return 0
else
__style=${FAST_THEME_NAME}incorrect-subtle
return 1
fi
}
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,460 @@
# Copyright (c) 2018 Sebastian Gniazdowski
#
# Main chroma function. It allows to create the command-dedicated chromas
# (like -git.ch) through a definition provided by `chroma_def' array (read
# from the upper scope).
#
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
# $2 - the current token, also accessible by $__arg from the above scope -
# basically a private copy of $__arg
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
# command line buffer, used to add region_highlight entry (see man),
# because Zsh colorizes by *ranges* in command line buffer
# $4 - a private copy of $_end_pos from the above scope
#
(( next_word = 2 | 8192 ))
→chroma/main-chroma-print() {
(( FAST_HIGHLIGHT[DEBUG] )) && print "$@" >> /tmp/fsh-dbg
}
local __chroma_name="${1#\%}" __first_call="$2" __wrd="$3" __start_pos="$4" __end_pos="$5"
# Not a well formed chroma name
[[ -z "$__chroma_name" ]] && return 1
# Load the fsh_{name-of-the-chroma}_chroma_def array
(( !FAST_HIGHLIGHT[-${__chroma_name}.ch-chroma-def] )) && →chroma/-${__chroma_name}.ch
→chroma/main-chroma-print -r -- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
→chroma/main-chroma-print -r -- @@@@@@@ local __chroma_name="${1#\%}" __first_call="$2" __wrd="$3" __start_pos="$4" __end_pos="$5" @@@@@@@
local __style __entry __value __action __handler __tmp __svalue __hspaces=$'\t ' __nl=$'\n' __ch_def_name
integer __idx1 __idx2 __start __end __ivalue __have_value=0
local -a __lines_list __avalue
local -A map
map=( "#" "_H" "^" "_D" "*" "_S" )
(( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN ))
# Handler that highlights the options
→chroma/main-chroma-std-aopt-action() {
integer _start="$2" _end="$3"
local _scmd="$1" _wrd="$4"
[[ "$_wrd" = (#b)(--[a-zA-Z0-9_-]##)=(*) ]] && {
reply+=("$_start $(( _end - mend[2] + mbegin[2] - 1 )) ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-hyphen-option]}")
} || {
[[ "$_wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \
__style=${FAST_THEME_NAME}single-hyphen-option
}
}
# Handler that highlights the options' arguments
→chroma/main-chroma-std-aopt-ARG-action() {
integer _start="$2" _end="$3"
local _scmd="$1" _wrd="$4"
[[ "$_wrd" = (#b)(--[a-zA-Z0-9_-]##)=(*) ]] && {
reply+=("$(( _start + 1 + mend[1] )) $_end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}optarg-${${${(M)match[2]:#<->}:+number}:-string}]}")
} || __style=${FAST_THEME_NAME}optarg-${${${(M)_wrd:#(-|)<->}:+number}:-string}
}
# This handler also highlights explicit arguments, i.e. --opt=the-explicit-arg
→chroma/main-chroma-std-aopt-SEMI-action() {
integer _start="$2" _end="$3"
local _scmd="$1" _wrd="$4"
[[ "$_wrd" = (#b)(--[a-zA-Z0-9_-]##)=(*) ]] && {
reply+=("$_start $(( _end - mend[2] + mbegin[2] - 1 )) ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-hyphen-option]}")
reply+=("$(( _start + 1 + mend[1] )) $_end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}optarg-${${${(M)match[2]:#<->}:+number}:-string}]}")
} || {
[[ "$_wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \
__style=${FAST_THEME_NAME}single-hyphen-option
}
}
# A handler which verifies the token as an GIT url
→chroma/main-chroma-std-verify-url() {
setopt localoptions extendedglob
local _wrd="$4"
integer url_correct=0
# Correct matches
# Correct matches
if [[ "$_wrd" = (#b)(git|http|https|ftp|ftps|file)://([a-zA-Z0-9._~-]##)(:[0-9]##)(#c0,1)(/([a-zA-Z0-9./_~:-]##))(#c0,1) ]]; then
url_correct=1
elif [[ "$_wrd" = (#b)rsync://([a-zA-Z0-9._~-]##)(/([a-zA-Z0-9./_~:-]##))(#c0,1) ]]; then
url_correct=1
elif [[ "$_wrd" = (#b)ssh://([a-zA-Z0-9._~-]##@)(#c0,1)([a-zA-Z0-9._~-]##)(:[0-9]##)(#c0,1)(/([a-zA-Z0-9./_~:-]##))(#c0,1) ]]; then
url_correct=1
elif [[ "$_wrd" = (#b)([a-zA-Z0-9._~-]##@)(#c0,1)([a-zA-Z0-9._~-]##):([a-zA-Z0-9./_~:-](#c0,1)[a-zA-Z0-9._~:-][a-zA-Z0-9./_~:-]#)(#c0,1) ]]; then
url_correct=1
elif [[ "$_wrd" = (#b)[[:alnum:]/_~:.-]## ]]; then
url_correct=1
fi
(( url_correct )) && \
{ __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \
{ __style=${FAST_THEME_NAME}incorrect-subtle; return 1; }
}
# A handler which verifies the token as a shell wildcard
→chroma/main-chroma-std-verify-pattern() {
setopt localoptions extendedglob
local _wrd="$4"
__style=${FAST_THEME_NAME}globbing-ext
}
# Creates a hash table for given option set (an *_opt field in the chroma def.)
→chroma/main-create-OPTION-hash.ch() {
local __subcmd="$1" __option_set_id="$2" __the_hash_name="$3" __ __e __el __the_hash_name __var_name
local -a __split __sp __s
→chroma/main-chroma-print -rl "======================" " **## STARTING ##** →chroma/main-##CREATE##-option-HASH.ch // subcmd:$__subcmd // option_set_id:$__option_set_id // h-nam:$__the_hash_name"
→chroma/main-chroma-print "[D] Got option-set: ${(j:,:)__option_set_id}"
typeset -gA "$__the_hash_name"
→chroma/main-chroma-print "[E] __the_hash_name ${__the_hash_name}:[$__option_set_id]"
# Split on ||
__ch_def_name="fsh__${__chroma_name}__chroma__def[${__option_set_id}]"
__split=( "${(P@s:||:)__ch_def_name}" )
[[ ${#__split} -eq 1 && -z "${__split[1]}" ]] && __split=()
# Remove only leading and trailing whitespace
__split=( "${__split[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
→chroma/main-chroma-print -rl "[F] Got ||-__split: _________" ${${(@)${${__split[@]##[[:space:]]##}[@]//[${__hspaces}]##/ }[@]//[${__nl}]##/$__nl}[@]//(#s)/:::} "_________"
for __el in $__split; do
__sp=( "${(@s:<<>>:)__el}" )
[[ ${#__sp} -eq 1 && -z "${__sp[1]}" ]] && __sp=()
__sp=( "${__sp[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
→chroma/main-chroma-print -l -- "Processing an ||-part - got <<>>-split: _________" "${${__sp[@]}[@]/(#s)/-\\t}" "_________"
__e="${__sp[1]}"
local __e1=${${__e#\(}%\)(:add|:del|)}
local __e2=${(M)__e##\(*\)(:add|:del)}
# Split on | with the ( and ) and :add/:del stripped and then append
# the :add or :del depending on what's on the input line
__s=()
for __ in ${(@s:|:)__e1}; do
__s+=( $__${__e2:+${(M)__e%(:add|:del)}} )
done
[[ ${#__s} -eq 1 && -z "${__s[1]}" ]] && __s=()
__s=( "${__s[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
shift __sp
for __ in $__s; do
__=${__%\^}
[[ "$__" = -*:(add|del) ]] && __var_name="${__the_hash_name}[${__}-directive]" || __var_name="${__the_hash_name}[${__}-opt-action]"
→chroma/main-chroma-print "${(r:70:: :):-${__var_name}} := >>${__sp[1]}${${${#__sp}:#(0|1)}:+ +}<<"
: ${(P)__var_name::=${__sp[1]}${${${#__sp}:#(0|1)}:+ +}}
if (( ${#__sp} >= 2 )); then
__var_name="${__the_hash_name}[${__}-opt-arg-action]"
→chroma/main-chroma-print "${(r:70:: :):-${__var_name}} := >>${__sp[2]}<<}"
: ${(P)__var_name::=$__sp[2]}
fi
done
done
}
# Processes given token
→chroma/main-process-token.ch() {
local __subcmd="$1" __wrd="$2" __val __var_name __main_hash_name __the_hash_name __i __size
local -a __splitted __split __added
→chroma/main-chroma-print "\n******************* Starting →chroma/main-process-token <<$__wrd>>// subcmd:${(qq)__subcmd}"
__main_hash_name="fsh__chroma__main__${${FAST_HIGHLIGHT[chroma-current]//[^a-zA-Z0-9_]/_}//(#b)([\#\^\*])/${map[${match[1]}]}}"
__var_name="${__main_hash_name}[subcmd:$__subcmd]"
__splitted=( "${(@s://:P)__var_name}" )
[[ ${#__splitted} -eq 1 && -z "${__splitted[1]}" ]] && __splitted=()
__splitted=( "${__splitted[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
→chroma/main-chroma-print -rl -- "[B] MAIN-PROCESS-TOKEN: got [OPTION/ARG-**S-E-T-S**] //-splitted from subcmd:$__subcmd: ${${(j:, :)__splitted}:-EMPTY-SET!}" "----- __splitted\\Deleted: -----" ${${(j:, :)${__splitted[@]:#(${(~j:|:)${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}})}}:-EMPTY-SET (deleted)!} "----- Added\\Deleted: -----" ${${(j:, :)${${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]}:#(${(~j:|:)${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}})}}:-EMPTY-SET (added)!} -----\ Deleted:\ ----- ${(j:, :)${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}} >> /tmp/reply
(( ! ${#__splitted} )) && {
__var_name="${__main_hash_name}[subcmd:*]"
__splitted=( "${(@s://:P)__var_name}" )
[[ ${#__splitted} -eq 1 && -z "${__splitted[1]}" ]] && __splitted=()
__splitted=( "${__splitted[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
(( ! ${#__splitted} )) && return 1
}
→chroma/main-chroma-print -rl -- "---NO-HASH-CREATE-FROM-NOW-ON---"
if [[ -z "${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]}" ]]; then
→chroma/main-chroma-print -rl -- "-z OPT-WITH-ARG-ACTIVE == true"
if [[ "$__wrd" = -* ]]; then
→chroma/main-chroma-print "1st-PATH (-z opt-with-arg-active, non-opt-arg branch, i.e. OPTION BRANCH) [#${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}]"
for __val in ${__splitted[@]:#(${(~j:|:)${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}})} ${${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]}:#(${(~j:|:)${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}})}; do
[[ "${__val}" != "${__val%%_([0-9]##|\#)##*}"_${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}_opt(\*|\^|) && "${__val}" != "${__val%%_([0-9]##|\#)*}"_"#"_opt(\*|\^|) ]] && { →chroma/main-chroma-print "DIDN'T MATCH $__val / arg counter:${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}" ; continue; } || →chroma/main-chroma-print "Got candidate: $__val"
# Create the hash cache-parameter if needed
__the_hash_name="fsh__chroma__${FAST_HIGHLIGHT[chroma-current]//[^a-zA-Z0-9_]/_}__${__subcmd//[^a-zA-Z0-9_]/_}__${${__val//(#b)([\#\^\*])/${map[${match[1]}]}}//[^a-zA-Z0-9_]/_}"
[[ "$__val" = *_opt(\*|\^|) && "${(P)+__the_hash_name}" -eq 0 ]] && →chroma/main-create-OPTION-hash.ch "$__subcmd" "$__val" "$__the_hash_name" || →chroma/main-chroma-print "Not creating, the hash already exists..."
# Try dedicated-entry for the option
__var_name="${__the_hash_name}[${${${${(M)__wrd#?*=}:+${__wrd%=*}=}:-$__wrd}}-opt-action]"
__split=( "${(@s://:P)__var_name}" )
[[ ${#__split} -eq 1 && -z "${__split[1]}" ]] && __split=()
# If no result, then try with catch-all entry
(( ! ${#__split} )) && {
→chroma/main-chroma-print "% no ${(q-)${${${(M)__wrd#?*=}:+${__wrd%=*}=}:-$__wrd}}-opt-action, retrying with *-opt-action" "|__var_name|:$__var_name"
__var_name="${__the_hash_name}[*-opt-action]"
__split=( "${(@s://:P)__var_name}" )
[[ ${#__split} -eq 1 && -z "${__split[1]}" ]] && __split=()
}
__svalue="$__var_name"
# Remove whitespace
__split=( "${__split[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
→chroma/main-chroma-print -l -- "\`$__val' // ${#__split} // $__wrd: (ch.run #${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-call-nr]}), deref. of \`$__var_name'"
if (( ${#__split} )); then
→chroma/main-chroma-print -l -- "Got split of {\$#__split:$#__split} ${__wrd}-opt-action or *-opt-action" "${${(q-)__split[@]}[@]/(#s)/->\\t}"
if [[ "${__split[2]}" = *[[:blank:]]+ ]]; then
→chroma/main-chroma-print "YES handling the value (the OPT.ARGUMENT)! [${__split[2]}]"
if [[ "$__wrd" = *=* ]]; then
→chroma/main-chroma-print "The-immediate Arg-Acquiring, of option"
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]="${__svalue%-opt-action\]}-opt-arg-action]"
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-arg]="${__wrd#*=}"
__have_value=2
else
→chroma/main-chroma-print "Enable Arg-Awaiting, of option"
→chroma/main-chroma-print "FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]=\"${__svalue%-opt-action\]}-opt-arg-action]\""
__have_value=0
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]="${__svalue%-opt-action\]}-opt-arg-action]"
fi
fi
__action="${__split[1]}"
__handler="${__split[2]%[[:blank:]]+}"
# Check for directives (like :add)
if [[ "$__val" = *_opt\^ ]]; then
__var_name="${__the_hash_name}[${${${${(M)__wrd#?*=}:+${__wrd%=*}=}:-$__wrd}}:add-directive]"
(( ${(P)+__var_name} )) && __split=( "${(@s://:P)__var_name}" ) || __split=()
[[ ${#__split} -eq 1 && -z "${__split[1]}" ]] && __split[1]=()
__ivalue=${#__split}
__var_name="${__var_name%:add-*}:del-directive]"
(( ${(P)+__var_name} )) && __split+=( "${(@s://:P)__var_name}" )
[[ ${#__split} -eq $(( __ivalue + 1 )) && -z "${__split[__ivalue+1]}" ]] && __split[__ivalue+1]=()
__split=( "${__split[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
__tmp=${#__split}
# First: del-directive
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]+="${(j: :)__split[__ivalue+1,__tmp]} "
→chroma/main-chroma-print -rl ":add / :del directives: __ivalue:$__ivalue, THE __SPLIT[#$__tmp]: " "${__split[@]}" "//" "The FAST_HIGHLIGHT[chroma-*deleted-nodes]: " ${=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]} >> /tmp/reply
# Second: add-directive
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]+="${(j: :)__split[1,__ivalue]} "
fi
[[ "$__handler" = ::[^[:space:]]* ]] && __handler="${__handler#::}" || __handler=""
[[ -n "$__handler" && "$__handler" != "NO-OP" ]] && { →chroma/main-chroma-print -rl -- "Running handler(1): $__handler" ; "$__handler" "${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]:-NULL}" "$__start" "$__end" "$__wrd"; }
[[ "$__have_value" -ne 2 && -n "$__action" && "$__action" != "NO-OP" ]] && { →chroma/main-chroma-print -rl "Running action (1): $__action" ; eval "() { $__action; }"; }
[[ "$__val" != *\* ]] && break
else
→chroma/main-chroma-print -rl -- "NO-MATCH ROUTE TAKEN"
fi
done
else
→chroma/main-chroma-print "1st-PATH-B (-z opt-with-arg-active, non-opt-arg branch, ARGUMENT BRANCH [#${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}]) //// added-nodes: ${=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]}"
for __val in ${__splitted[@]:#(${(~j:|:)${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}})} ${${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]}:#(${(~j:|:)${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}})}; do
[[ "${__val}" != "${__val%%_([0-9]##|\#)*}"_"${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}"_arg(\*|\^|) && "${__val}" != "${__val%%_([0-9]##|\#)*}"_"#"_arg(\*|\^|) ]] && { →chroma/main-chroma-print "Continuing for $__val / arg counter ${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}" ; continue }
# Create the hash cache-parameter if needed
__the_hash_name="fsh__chroma__${FAST_HIGHLIGHT[chroma-current]//[^a-zA-Z0-9_]/_}__${__subcmd//[^a-zA-Z0-9_]/_}__${${__val//\#/H}//[^a-zA-Z0-9_]/_}"
__action="" __handler=""
→chroma/main-chroma-print "A hit, chosen __val:$__val!"
__ch_def_name="fsh__${__chroma_name}__chroma__def[$__val]"
__split=( "${(P@s:<<>>:)__ch_def_name}" )
__split=( "${__split[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
__sp=( "${(@s://:)__split[1]}" )
__sp=( "${__sp[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
__action="${__sp[1]#*::::: ##}"
# Verify if it's the expected argument
[[ "${__sp[1]}" = *:::::* && "$__wrd" != ${~${__sp[1]%% ##:::::*}} ]] && \
{ →chroma/main-chroma-print -r "mismatch ${__sp[1]%% ##:::::*} != $__wrd, continuing" ; continue; }
→chroma/main-chroma-print -l -- "Got action record for $__val, i.e. the split:" "${__sp[@]//(#s)/-\t}" "_________"
[[ "${__sp[2]}" = ::[^[:space:]]* ]] && __handler="${__sp[2]#::}" || { [[ -n "$__handler" && "$__handler" != "NO-OP" ]] && →chroma/main-chroma-print "=== Error === In chroma definition: a handler entry ${(q)__sp[2]} without leading \`::'" ; }
[[ -n "$__handler" && "$__handler" != "NO-OP" ]] && { →chroma/main-chroma-print -rl -- "Running handler(3): $__handler" ; "$__handler" "${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]:-NULL}" "$__start" "$__end" "$__wrd"; }
[[ -n "$__action" && "$__action" != "NO-OP" ]] && { →chroma/main-chroma-print -rl -- "Running action(3): $__action" ; eval "() { $__action; } \"${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]:-NULL}\" \"$__start\" \"$__end\" \"$__wrd\""; }
# Check for argument directives (like :add)
if (( ${#__split} >= 2 )); then
for __ in "${(@)__split[2,-1]}"; do
__splitted=( "${(@s://:)__}" )
if [[ "${__splitted[1]}" = add:* ]]; then
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]+="${__splitted[1]#add:} ${(j: :)__splitted[2,-1]} "
elif [[ "${__splitted[1]}" = del:* ]]; then
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]+="${__splitted[1]#del:} ${(j: :)__splitted[2,-1]} "
fi
done
→chroma/main-chroma-print -l "ARGUMENT :add / :del directives: THE __SPLIT[#${#__split}]: " "${__split[@]//(#s)/-\\t}" "//" "The FAST_HIGHLIGHT[chroma-*deleted-nodes]: " ${(@)${=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}//(#s)/-\\t} "The FAST_HIGHLIGHT[chroma-*added-nodes]: " ${(@)${=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]}//(#s)/-\\t}
fi
[[ "$__val" != *\* ]] && break
done
fi
else
→chroma/main-chroma-print -- "2nd-PATH (-n opt-with-arg-active) NON-EMPTY arg-active:\nThe actual opt-val <<< \$__wrd:$__wrd >>> store (after the \`Arg-Awaiting' in the chroma-run: #$(( FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-call-nr]-1 )) [current: #$(( FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-call-nr] ))])"
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-arg]="$__wrd"
__have_value=1
fi
# Execute the action if not during simulated opt-argument (--opt=...)
→chroma/main-chroma-print "** BEFORE: \`if (( __have_value ))'"
if (( __have_value )); then
→chroma/main-chroma-print "In the \`if (( __have_value ))' [have_value: $__have_value]"
# Split
__var_name="${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]}"
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]=""
__split=( "${(@s://:P)__var_name}" )
[[ ${#__split} -eq 1 && -z "${__split[1]}" ]] && { →chroma/main-chroma-print -rl "NULL at __var_name:$__var_name" ; __split=(); }
__split=( "${__split[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
# Remember 1st level action
(( __have_value == 2 )) && __value="$__action" || __value=""
if (( ${#__split} )); then
→chroma/main-chroma-print -l -- "Got //-split (3, for opt-ARG-action, from [$__var_name]):" "${${(q-)__split[@]}[@]/(#s)/+\\t}"
__action="${__split[1]}"
__handler="${__split[2]}"
[[ "$__handler" = ::[^[:space:]]* ]] && __handler="${__handler#::}"
[[ -n "$__handler" && "$__handler" != "NO-OP" ]] && { →chroma/main-chroma-print -rl -- "Running handler(2): $__handler" ; "$__handler" "${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]:-NULL}" "$__start" "$__end" "$__wrd"; }
[[ -n "$__action" && "$__action" != "NO-OP" ]] && { →chroma/main-chroma-print -rl -- "Running action(2): $__action" ; eval "$__action"; }
→chroma/main-chroma-print -rl -- "The __action value: [$__value]"
[[ "$__have_value" -eq 2 && -n "$__value" && "$__value" != "NO-OP" ]] && { →chroma/main-chroma-print -rl "Running action (of 1, at 2): $__value" ; eval "$__value"; }
fi
fi
→chroma/main-chroma-print -- "_________ Exiting →chroma/main-process-token.ch $__subcmd / $__wrd _________"
}
# Iterates over the chroma def. fields and creates initial
# fields in the fsh__${__chroma_name}__chroma__def hash
→chroma/-pre_process_chroma_def.ch() {
local __key __value __ke _val __the_hash_name="$1" __var_name
local -a __split
→chroma/main-chroma-print -rl -- "Starting PRE_PROCESS for __the_hash_name:$__the_hash_name"
__ch_def_name="fsh__${__chroma_name}__chroma__def[subcommands]"
local __subcmds="${(P)__ch_def_name}"
if [[ "$__subcmds" = "::"* ]]; then
${__subcmds#::}
__var_name="${__the_hash_name}[subcommands]"
: ${(P)__var_name::=(${(j:|:)reply})}
else
__var_name="${__the_hash_name}[subcommands]"
: ${(P)__var_name::=$__subcmds}
fi
→chroma/main-chroma-print "Got SUBCOMMANDS: ${(P)__var_name}"
__ch_def_name="fsh__${__chroma_name}__chroma__def[subcmd-hook]"
local __subcmd_hook="${(P)__ch_def_name}"
if [[ -n "$__subcmd_hook" ]]; then
__var_name="${__the_hash_name}[subcmd-hook]"
: ${(P)__var_name::=$__subcmd_hook}
fi
__ch_def_name="fsh__${__chroma_name}__chroma__def[(I)subcmd:*]"
for __key in "${(P@)__ch_def_name}"; do
__split=( "${(@s:|:)${${__key##subcmd:\((#c0,1)}%\)}}" )
[[ ${#__split} -eq 1 && -z "${__split[1]}" ]] && __split=()
__split=( "${__split[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
for __ke in "${__split[@]}"; do
__var_name="${__the_hash_name}[subcmd:$__ke]"
__ch_def_name="fsh__${__chroma_name}__chroma__def[$__key]"
: ${(P)__var_name::=${(P)__ch_def_name}}
→chroma/main-chroma-print -rl -- "Storred ${__var_name}=chroma_def[$__key], i.e. = ${(P)__ch_def_name}"
done
done
}
if (( __first_call )); then
→chroma/-${__chroma_name}-first-call
FAST_HIGHLIGHT[chroma-current]="$__wrd"
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]=0
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-got-subcommand]=0
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]=""
FAST_HIGHLIGHT[chrome-${FAST_HIGHLIGHT[chroma-current]}-occurred-double-hyphen]=0
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]=""
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-arg]=""
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-call-nr]=1
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]=""
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]=""
__the_hash_name="fsh__chroma__main__${${FAST_HIGHLIGHT[chroma-current]//[^a-zA-Z0-9_]/_}//(#b)([\#\^])/${map[${match[1]}]}}"
(( 0 == ${(P)+__the_hash_name} )) && {
typeset -gA "$__the_hash_name"
→chroma/-pre_process_chroma_def.ch "$__the_hash_name"
} || →chroma/main-chroma-print "...No... [\${+$__the_hash_name} ${(P)+__the_hash_name}]"
return 1
else
(( ++ FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-call-nr] ))
# Following call, i.e. not the first one
# Check if chroma should end test if token is of type
# "starts new command", if so pass-through chroma ends
[[ "$__arg_type" = 3 ]] && return 2
→chroma/main-chroma-print "== @@ Starting @@ #${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-call-nr]} Main-Chroma-call == // << __WORD:$__wrd >> ## Subcommand: ${${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]}:-NULL} //@@// -n option-with-arg-active:${(q-)FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]}"
if [[ "$__wrd" = -* || -n "${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]}"
]]; then
→chroma/main-chroma-print "## The \`if -*' i.e. \`IF OPTION' MAIN branch"
→chroma/main-process-token.ch "${${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]}:-NULL}" "$__wrd"
else
# If at e.g. '>' or destination/source spec (of the redirection)
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
return 1
elif (( FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-got-subcommand] == 0 )) {
__the_hash_name="fsh__chroma__main__${${FAST_HIGHLIGHT[chroma-current]//[^a-zA-Z0-9_]/_}//(#b)([\#\^])/${map[${match[1]}]}}"
__var_name="${__the_hash_name}[subcommands]"
if [[ "$__wrd" = ${(P)~__var_name} ]]; then
→chroma/main-chroma-print "GOT-SUBCOMMAND := $__wrd, subcmd verification / OK"
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-got-subcommand]=1
FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]="$__wrd"
__var_name="${__the_hash_name}[subcmd-hook]"
(( ${(P)+__var_name} )) && { →chroma/main-chroma-print -r -- "Running subcmd-hook: ${(P)__var_name}" ; "${(P)__var_name}" "$__wrd"; }
__style="${FAST_THEME_NAME}subcommand"
else
→chroma/main-chroma-print "subcmd verif / NOT OK; Incrementing the COUNTER-ARG ${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]} -> $(( FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg] + 1 ))" >> /tmp/fsh-dbg
(( FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg] += 1 ))
→chroma/main-chroma-print "UNRECOGNIZED ARGUMENT ${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}"
→chroma/main-process-token.ch "${${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]}:-NULL}" "$__wrd"
fi
} else {
__wrd="${__wrd//\`/x}"
__arg="${__arg//\`/x}"
__wrd="${(Q)__wrd}"
local __tmp_def_name="fsh__${__chroma_name}__chroma__def[subcommands-blacklist]"
if [[ ${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]} = \
(${(~j:|:)${(@s:,:)${(PA)__tmp_def_name}}})
]] {
return 1
}
→chroma/main-chroma-print "Incrementing the COUNTER-ARG ${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]} -> $(( FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg] + 1 ))"
(( FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg] += 1 ))
→chroma/main-chroma-print "ARGUMENT ${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}"
→chroma/main-chroma-print "ELSE *-got-subcommand == 1 is TRUE"
→chroma/main-process-token.ch "${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]}" "$__wrd"
}
fi
fi
# Add region_highlight entry (via `reply' array)
if [[ -n "$__style" ]]; then
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \
&& reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
fi
# We aren't passing-through, do obligatory things ourselves
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
# vim:ft=zsh:et:sw=4

View File

@ -0,0 +1,15 @@
version: 2
jobs:
build:
parallelism: 4
shell: /bin/bash --login
docker:
- image: ericfreese/zsh-autosuggestions-test:latest
steps:
- checkout
- run:
name: Running tests
command: |
for v in $(grep "^[^#]" ZSH_VERSIONS | awk "(NR + $CIRCLE_NODE_INDEX) % $CIRCLE_NODE_TOTAL == 0"); do
TEST_ZSH_BIN=zsh-$v make test || exit 1
done

View File

@ -0,0 +1,18 @@
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4
[*.md]
indent_style = space
[*.rb]
indent_style = space
indent_size = 2
[*.yml]
indent_style = space
indent_size = 2

View File

@ -0,0 +1,36 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''
---
### Describe the bug
<!-- A clear and concise description of what the bug is. -->
### To Reproduce
Steps to reproduce the behavior:
<!-- If you are not able to reproduce it by running `zsh -df` and sourcing the plugin manually, it means there that the issue is caused by something in your local config file(s). Temporarily comment out or remove sections of your config and restart `zsh` until you narrow down exactly what is causing the issue. -->
```sh
% zsh -df
% source path/to/zsh-autosuggestions.zsh
% ... # what do you do to reproduce?
```
### Expected behavior
<!-- A clear and concise description of what you expected to happen. -->
### Screenshots
<!-- If applicable, add screenshots to help explain your problem. -->
### Desktop
- OS + distribution: <!-- e.g. Arch Linux 2019.07.01 -->
- Zsh version: <!-- `echo $ZSH_VERSION` -->
- Plugin version: <!-- or git commit hash if installed via git -->
### Additional context
<!-- Add any other context about the problem here. -->

View File

@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''
---
### Is your feature request related to a problem? Please describe.
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
### Describe the solution you'd like
<!-- A clear and concise description of what you want to happen. -->
### Describe alternatives you've considered
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
### Additional context
<!-- Add any other context or screenshots about the feature request here. -->

View File

@ -0,0 +1,3 @@
--color
--require spec_helper
--format documentation

View File

@ -0,0 +1,30 @@
# Rails:
# Enabled: true
AllCops:
TargetRubyVersion: 2.3
Include:
- '**/Rakefile'
- '**/config.ru'
- '**/Gemfile'
Metrics/LineLength:
Max: 120
Style/Documentation:
Enabled: false
Style/DotPosition:
EnforcedStyle: trailing
Style/FrozenStringLiteralComment:
Enabled: false
Style/Lambda:
Enabled: false
Style/MultilineMethodCallIndentation:
EnforcedStyle: indented
Style/TrailingUnderscoreVariable:
Enabled: false

View File

@ -0,0 +1 @@
2.5.3

View File

@ -0,0 +1,117 @@
# Changelog
## v0.7.0
- Enable asynchronous mode by default (#498)
- No longer wrap user widgets starting with `autosuggest-` prefix (#496)
- Fix a bug wrapping widgets that modify the buffer (#541)
## v0.6.4
- Fix `vi-forward-char` triggering a bell when using it to accept a suggestion (#488)
- New configuration option to skip completion suggestions when buffer matches a pattern (#487)
- New configuration option to ignore history entries matching a pattern (#456)
## v0.6.3
- Fixed bug moving cursor to end of buffer after accepting suggestion (#453)
## v0.6.2
- Fixed bug deleting the last character in the buffer in vi mode (#450)
- Degrade gracefully when user doesn't have `zsh/system` module installed (#447)
## v0.6.1
- Fixed bug occurring when `_complete` had been aliased (#443)
## v0.6.0
- Added `completion` suggestion strategy powered by completion system (#111)
- Allow setting `ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE` to an empty string (#422)
- Don't fetch suggestions after copy-earlier-word (#439)
- Allow users to unignore zle-\* widgets (e.g. zle-line-init) (#432)
## v0.5.2
- Allow disabling automatic widget re-binding for better performance (#418)
- Fix async suggestions when `SH_WORD_SPLIT` is set
- Refactor async mode to use process substitution instead of zpty (#417)
## v0.5.1
- Speed up widget rebinding (#413)
- Clean up global variable creations (#403)
- Respect user's set options when running original widget (#402)
## v0.5.0
- Don't overwrite config with default values (#335)
- Support fallback strategies by supplying array to suggestion config var
- Rename "default" suggestion strategy to "history" to name it based on what it actually does
- Reset opts in some functions affected by `GLOB_SUBST` (#334)
- Support widgets starting with dashes (ex: `-a-widget`) (#337)
- Skip async tests in zsh versions less than 5.0.8 because of reliability issues
- Fix handling of newline + carriage return in async pty (#333)
## v0.4.3
- Avoid bell when accepting suggestions with `autosuggest-accept` (#228)
- Don't fetch suggestions after [up,down]-line-or-beginning-search (#227, #241)
- We are now running CI against new 5.5.1 version
- Fix partial-accept in vi mode (#188)
- Fix suggestion disappearing on fast movement after switching to `vicmd` mode (#290)
- Fix issue rotating through kill ring with `yank-pop` (#301)
- Fix issue creating new pty for async mode when previous pty is not properly cleaned up (#249)
## v0.4.2
- Fix bug in zsh versions older than 5.0.8 (#296)
- Officially support back to zsh v4.3.11
## v0.4.1
- Switch to [[ and (( conditionals instead of [ (#257)
- Avoid warnnestedvar warnings with `typeset -g` (#275)
- Replace tabs with spaces in yaml (#268)
- Clean up and fix escaping of special characters (#267)
- Add `emacs-forward-word` to default list of partial accept widgets (#246)
## v0.4.0
- High-level integration tests using RSpec and tmux
- Add continuous integration with Circle CI
- Experimental support for asynchronous suggestions (#170)
- Fix problems with multi-line suggestions (#225)
- Optimize case where manually typing in suggestion
- Avoid wrapping any zle-\* widgets (#206)
- Remove support for deprecated options from v0.0.x
- Handle history entries that begin with dashes
- Gracefully handle being sourced multiple times (#126)
- Add enable/disable/toggle widgets to disable/enable suggestions (#219)
## v0.3.3
- Switch from $history array to fc builtin for better performance with large HISTFILEs (#164)
- Fix tilde handling when extended_glob is set (#168)
- Add config option for maximum buffer length to fetch suggestions for (#178)
- Add config option for list of widgets to ignore (#184)
- Don't fetch a new suggestion unless a modification widget actually modifies the buffer (#183)
## v0.3.2
- Test runner now supports running specific tests and choosing zsh binary
- Return code from original widget is now correctly passed through (#135)
- Add `vi-add-eol` to list of accept widgets (#143)
- Escapes widget names within evals to fix problems with irregular widget names (#152)
- Plugin now clears suggestion while within a completion menu (#149)
- .plugin file no longer relies on symbolic link support, fixing issues on Windows (#156)
## v0.3.1
- Fixes issue with `vi-next-char` not accepting suggestion (#137).
- Fixes global variable warning when WARN_CREATE_GLOBAL option enabled (#133).
- Split out a separate test file for each widget.
## v0.3.0
- Adds `autosuggest-execute` widget (PR #124).
- Adds concept of suggestion "strategies" for different ways of fetching suggestions.
- Adds "match_prev_cmd" strategy (PR #131).
- Uses git submodules for testing dependencies.
- Lots of test cleanup.
- Various bug fixes for zsh 5.0.x and `sh_word_split` option.
## v0.2.17
Start of changelog.

View File

@ -0,0 +1 @@
Fish-like fast/unobtrusive autosuggestions for zsh.

View File

@ -0,0 +1,20 @@
FROM ruby:2.5.3-alpine
RUN apk add --no-cache autoconf
RUN apk add --no-cache libtool
RUN apk add --no-cache libcap-dev
RUN apk add --no-cache pcre-dev
RUN apk add --no-cache curl
RUN apk add --no-cache build-base
RUN apk add --no-cache ncurses-dev
RUN apk add --no-cache tmux
WORKDIR /zsh-autosuggestions
ADD ZSH_VERSIONS /zsh-autosuggestions/ZSH_VERSIONS
ADD install_test_zsh.sh /zsh-autosuggestions/install_test_zsh.sh
RUN ./install_test_zsh.sh
ADD Gemfile /zsh-autosuggestions/Gemfile
ADD Gemfile.lock /zsh-autosuggestions/Gemfile.lock
RUN bundle install

View File

@ -0,0 +1,5 @@
source 'https://rubygems.org'
gem 'rspec'
gem 'rspec-wait'
gem 'pry-byebug'

View File

@ -0,0 +1,41 @@
GEM
remote: https://rubygems.org/
specs:
byebug (9.0.5)
coderay (1.1.1)
diff-lcs (1.3)
method_source (0.8.2)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-byebug (3.4.0)
byebug (~> 9.0)
pry (~> 0.10)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
rspec-wait (0.0.9)
rspec (>= 3, < 4)
slop (3.6.0)
PLATFORMS
ruby
DEPENDENCIES
pry-byebug
rspec
rspec-wait
BUNDLED WITH
1.13.6

View File

@ -0,0 +1,64 @@
# Installation
* [Packages](#packages)
* [Antigen](#antigen)
* [Oh My Zsh](#oh-my-zsh)
* [Manual](#manual-git-clone)
## Packages
| System | Package |
| ------------- | ------------- |
| Debian / Ubuntu | [zsh-autosuggestions OBS repository](https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-autosuggestions&package=zsh-autosuggestions) |
| Fedora / CentOS / RHEL / Scientific Linux | [zsh-autosuggestions OBS repository](https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-autosuggestions&package=zsh-autosuggestions) |
| OpenSUSE / SLE | [zsh-autosuggestions OBS repository](https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-autosuggestions&package=zsh-autosuggestions) |
| Arch Linux / Manjaro / Antergos / Hyperbola | [zsh-autosuggestions](https://www.archlinux.org/packages/zsh-autosuggestions), [zsh-autosuggestions-git](https://aur.archlinux.org/packages/zsh-autosuggestions-git) |
| NixOS | [zsh-autosuggestions](https://github.com/NixOS/nixpkgs/blob/master/pkgs/shells/zsh/zsh-autosuggestions/default.nix) |
| Void Linux | [zsh-autosuggestions](https://github.com/void-linux/void-packages/blob/master/srcpkgs/zsh-autosuggestions/template) |
| Mac OS | [homebrew](https://github.com/Homebrew/homebrew-core/blob/master/Formula/zsh-autosuggestions.rb) |
| NetBSD | [pkgsrc](http://ftp.netbsd.org/pub/pkgsrc/current/pkgsrc/shells/zsh-autosuggestions/README.html) |
## Antigen
1. Add the following to your `.zshrc`:
```sh
antigen bundle zsh-users/zsh-autosuggestions
```
2. Start a new terminal session.
## Oh My Zsh
1. Clone this repository into `$ZSH_CUSTOM/plugins` (by default `~/.oh-my-zsh/custom/plugins`)
```sh
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
```
2. Add the plugin to the list of plugins for Oh My Zsh to load (inside `~/.zshrc`):
```sh
plugins=(
# other plugins...
zsh-autosuggestions
)
```
3. Start a new terminal session.
## Manual (Git Clone)
1. Clone this repository somewhere on your machine. This guide will assume `~/.zsh/zsh-autosuggestions`.
```sh
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
```
2. Add the following to your `.zshrc`:
```sh
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
```
3. Start a new terminal session.

View File

@ -0,0 +1,23 @@
Copyright (c) 2013 Thiago de Arruda
Copyright (c) 2016-2021 Eric Freese
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,35 @@
SRC_DIR := ./src
SRC_FILES := \
$(SRC_DIR)/config.zsh \
$(SRC_DIR)/util.zsh \
$(SRC_DIR)/bind.zsh \
$(SRC_DIR)/highlight.zsh \
$(SRC_DIR)/widgets.zsh \
$(SRC_DIR)/strategies/*.zsh \
$(SRC_DIR)/fetch.zsh \
$(SRC_DIR)/async.zsh \
$(SRC_DIR)/start.zsh
HEADER_FILES := \
DESCRIPTION \
URL \
VERSION \
LICENSE
PLUGIN_TARGET := zsh-autosuggestions.zsh
all: $(PLUGIN_TARGET)
$(PLUGIN_TARGET): $(HEADER_FILES) $(SRC_FILES)
cat $(HEADER_FILES) | sed -e 's/^/# /g' > $@
cat $(SRC_FILES) >> $@
.PHONY: clean
clean:
rm $(PLUGIN_TARGET)
.PHONY: test
test: all
@test -n "$$TEST_ZSH_BIN" && echo "Testing zsh binary: $(TEST_ZSH_BIN)" || true
bundle exec rspec $(TESTS)

View File

@ -0,0 +1,191 @@
# zsh-autosuggestions
_[Fish](http://fishshell.com/)-like fast/unobtrusive autosuggestions for zsh._
It suggests commands as you type based on history and completions.
Requirements: Zsh v4.3.11 or later
[![CircleCI](https://img.shields.io/circleci/build/github/zsh-users/zsh-autosuggestions.svg)](https://circleci.com/gh/zsh-users/zsh-autosuggestions)
[![Chat on Gitter](https://img.shields.io/gitter/room/zsh-users/zsh-autosuggestions.svg)](https://gitter.im/zsh-users/zsh-autosuggestions)
<a href="https://asciinema.org/a/37390" target="_blank"><img src="https://asciinema.org/a/37390.png" width="400" /></a>
## Installation
See [INSTALL.md](INSTALL.md).
## Usage
As you type commands, you will see a completion offered after the cursor in a muted gray color. This color can be changed by setting the `ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE` variable. See [configuration](#configuration).
If you press the <kbd></kbd> key (`forward-char` widget) or <kbd>End</kbd> (`end-of-line` widget) with the cursor at the end of the buffer, it will accept the suggestion, replacing the contents of the command line buffer with the suggestion.
If you invoke the `forward-word` widget, it will partially accept the suggestion up to the point that the cursor moves to.
## Configuration
You may want to override the default global config variables. Default values of these variables can be found [here](src/config.zsh).
**Note:** If you are using Oh My Zsh, you can put this configuration in a file in the `$ZSH_CUSTOM` directory. See their comments on [overriding internals](https://github.com/robbyrussell/oh-my-zsh/wiki/Customization#overriding-internals).
### Suggestion Highlight Style
Set `ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE` to configure the style that the suggestion is shown with. The default is `fg=8`, which will set the foreground color to color 8 from the [256-color palette](https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg). If your terminal only supports 8 colors, you will need to use a number between 0 and 7.
Background color can also be set, and the suggestion can be styled bold, underlined, or standout. For example, this would show suggestions with bold, underlined, pink text on a cyan background:
```sh
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff00ff,bg=cyan,bold,underline"
```
For more info, read the Character Highlighting section of the zsh manual: `man zshzle` or [online](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting).
**Note:** Some iTerm2 users have reported [not being able to see the suggestions](https://github.com/zsh-users/zsh-autosuggestions/issues/416#issuecomment-486516333). If this affects you, the problem is likely caused by incorrect color settings. In order to correct this, go into iTerm2's setting, navigate to profile > colors and make sure that the colors for Basic Colors > Background and ANSI Colors > Bright Black are **different**.
### Suggestion Strategy
`ZSH_AUTOSUGGEST_STRATEGY` is an array that specifies how suggestions should be generated. The strategies in the array are tried successively until a suggestion is found. There are currently three built-in strategies to choose from:
- `history`: Chooses the most recent match from history.
- `completion`: Chooses a suggestion based on what tab-completion would suggest. (requires `zpty` module)
- `match_prev_cmd`: Like `history`, but chooses the most recent match whose preceding history item matches the most recently executed command ([more info](src/strategies/match_prev_cmd.zsh)). Note that this strategy won't work as expected with ZSH options that don't preserve the history order such as `HIST_IGNORE_ALL_DUPS` or `HIST_EXPIRE_DUPS_FIRST`.
For example, setting `ZSH_AUTOSUGGEST_STRATEGY=(history completion)` will first try to find a suggestion from your history, but, if it can't find a match, will find a suggestion from the completion engine.
### Widget Mapping
This plugin works by triggering custom behavior when certain [zle widgets](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Widgets) are invoked. You can add and remove widgets from these arrays to change the behavior of this plugin:
- `ZSH_AUTOSUGGEST_CLEAR_WIDGETS`: Widgets in this array will clear the suggestion when invoked.
- `ZSH_AUTOSUGGEST_ACCEPT_WIDGETS`: Widgets in this array will accept the suggestion when invoked.
- `ZSH_AUTOSUGGEST_EXECUTE_WIDGETS`: Widgets in this array will execute the suggestion when invoked.
- `ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS`: Widgets in this array will partially accept the suggestion when invoked.
- `ZSH_AUTOSUGGEST_IGNORE_WIDGETS`: Widgets in this array will not trigger any custom behavior.
Widgets that modify the buffer and are not found in any of these arrays will fetch a new suggestion after they are invoked.
**Note:** A widget shouldn't belong to more than one of the above arrays.
### Disabling suggestion for large buffers
Set `ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE` to an integer value to disable autosuggestion for large buffers. The default is unset, which means that autosuggestion will be tried for any buffer size. Recommended value is 20.
This can be useful when pasting large amount of text in the terminal, to avoid triggering autosuggestion for strings that are too long.
### Asynchronous Mode
Suggestions are fetched asynchronously by default in zsh versions 5.0.8 and greater. To disable asynchronous suggestions and fetch them synchronously instead, `unset ZSH_AUTOSUGGEST_USE_ASYNC` after sourcing the plugin.
Alternatively, if you are using a version of zsh older than 5.0.8 and want to enable asynchronous mode, set the `ZSH_AUTOSUGGEST_USE_ASYNC` variable after sourcing the plugin (it can be set to anything). Note that there is [a bug](https://github.com/zsh-users/zsh-autosuggestions/issues/364#issuecomment-481423232) in versions of zsh older than 5.0.8 where <kbd>ctrl</kbd> + <kbd>c</kbd> will fail to reset the prompt immediately after fetching a suggestion asynchronously.
### Disabling automatic widget re-binding
Set `ZSH_AUTOSUGGEST_MANUAL_REBIND` (it can be set to anything) to disable automatic widget re-binding on each precmd. This can be a big boost to performance, but you'll need to handle re-binding yourself if any of the widget lists change or if you or another plugin wrap any of the autosuggest widgets. To re-bind widgets, run `_zsh_autosuggest_bind_widgets`.
### Ignoring history suggestions that match a pattern
Set `ZSH_AUTOSUGGEST_HISTORY_IGNORE` to a [glob pattern](http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Operators) to prevent offering suggestions for history entries that match the pattern. For example, set it to `"cd *"` to never suggest any `cd` commands from history. Or set to `"?(#c50,)"` to never suggest anything 50 characters or longer.
**Note:** This only affects the `history` and `match_prev_cmd` suggestion strategies.
### Skipping completion suggestions for certain cases
Set `ZSH_AUTOSUGGEST_COMPLETION_IGNORE` to a [glob pattern](http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Operators) to prevent offering completion suggestions when the buffer matches that pattern. For example, set it to `"git *"` to disable completion suggestions for git subcommands.
**Note:** This only affects the `completion` suggestion strategy.
### Key Bindings
This plugin provides a few widgets that you can use with `bindkey`:
1. `autosuggest-accept`: Accepts the current suggestion.
2. `autosuggest-execute`: Accepts and executes the current suggestion.
3. `autosuggest-clear`: Clears the current suggestion.
4. `autosuggest-fetch`: Fetches a suggestion (works even when suggestions are disabled).
5. `autosuggest-disable`: Disables suggestions.
6. `autosuggest-enable`: Re-enables suggestions.
7. `autosuggest-toggle`: Toggles between enabled/disabled suggestions.
For example, this would bind <kbd>ctrl</kbd> + <kbd>space</kbd> to accept the current suggestion.
```sh
bindkey '^ ' autosuggest-accept
```
## Troubleshooting
If you have a problem, please search through [the list of issues on GitHub](https://github.com/zsh-users/zsh-autosuggestions/issues?q=) to see if someone else has already reported it.
### Reporting an Issue
Before reporting an issue, please try temporarily disabling sections of your configuration and other plugins that may be conflicting with this plugin to isolate the problem.
When reporting an issue, please include:
- The smallest, simplest `.zshrc` configuration that will reproduce the problem. See [this comment](https://github.com/zsh-users/zsh-autosuggestions/issues/102#issuecomment-180944764) for a good example of what this means.
- The version of zsh you're using (`zsh --version`)
- Which operating system you're running
## Uninstallation
1. Remove the code referencing this plugin from `~/.zshrc`.
2. Remove the git repository from your hard drive
```sh
rm -rf ~/.zsh/zsh-autosuggestions # Or wherever you installed
```
## Development
### Build Process
Edit the source files in `src/`. Run `make` to build `zsh-autosuggestions.zsh` from those source files.
### Pull Requests
Pull requests are welcome! If you send a pull request, please:
- Request to merge into the `develop` branch (*NOT* `master`)
- Match the existing coding conventions.
- Include helpful comments to keep the barrier-to-entry low for people new to the project.
- Write tests that cover your code as much as possible.
### Testing
Tests are written in ruby using the [`rspec`](http://rspec.info/) framework. They use [`tmux`](https://tmux.github.io/) to drive a pseudoterminal, sending simulated keystrokes and making assertions on the terminal content.
Test files live in `spec/`. To run the tests, run `make test`. To run a specific test, run `TESTS=spec/some_spec.rb make test`. You can also specify a `zsh` binary to use by setting the `TEST_ZSH_BIN` environment variable (ex: `TEST_ZSH_BIN=/bin/zsh make test`).
A docker image for testing is available [on docker hub](https://hub.docker.com/r/ericfreese/zsh-autosuggestions-test). It comes with ruby, the bundler dependencies, and all supported versions of zsh installed.
Pull the docker image with:
```sh
docker pull ericfreese/zsh-autosuggestions-test
```
To run the tests for a specific version of zsh (where `<version>` below is substituted with the contents of a line from the [`ZSH_VERSIONS`](ZSH_VERSIONS) file):
```sh
docker run -it -e TEST_ZSH_BIN=zsh-<version> -v $PWD:/zsh-autosuggestions zsh-autosuggestions-test make test
```
## License
This project is licensed under [MIT license](http://opensource.org/licenses/MIT).
For the full text of the license, see the [LICENSE](LICENSE) file.

View File

@ -0,0 +1 @@
https://github.com/zsh-users/zsh-autosuggestions

View File

@ -0,0 +1 @@
v0.7.0

View File

@ -0,0 +1,17 @@
# Zsh releases to run tests against
# See https://github.com/zsh-users/zsh/releases
#
# When modifying this file, rebuild and push docker image:
# $ docker build -t ericfreese/zsh-autosuggestions-test .
# $ docker push ericfreese/zsh-autosuggestions-test
4.3.11
5.0.2
5.0.8
5.1.1
5.2
5.3.1
5.4.2
5.5.1
5.6.2
5.7.1
5.8

View File

@ -0,0 +1,26 @@
#!/bin/sh
set -ex
for v in $(grep "^[^#]" ZSH_VERSIONS); do
mkdir zsh-$v
cd zsh-$v
curl -L https://api.github.com/repos/zsh-users/zsh/tarball/zsh-$v | tar xz --strip=1
./Util/preconfig
./configure --enable-pcre \
--enable-cap \
--enable-multibyte \
--with-term-lib='ncursesw tinfo' \
--with-tcsetpgrp \
--program-suffix="-$v"
make install.bin
make install.modules
make install.fns
cd ..
rm -rf zsh-$v
done

View File

@ -0,0 +1,70 @@
context 'with asynchronous suggestions enabled' do
let(:options) { ["ZSH_AUTOSUGGEST_USE_ASYNC="] }
describe '`up-line-or-beginning-search`' do
let(:before_sourcing) do
-> do
session.
run_command('autoload -U up-line-or-beginning-search').
run_command('zle -N up-line-or-beginning-search').
send_string('bindkey "').
send_keys('C-v').send_keys('up').
send_string('" up-line-or-beginning-search').
send_keys('enter')
end
end
it 'should show previous history entries' do
with_history(
'echo foo',
'echo bar',
'echo baz'
) do
session.clear_screen
3.times { session.send_keys('up') }
wait_for { session.content }.to eq("echo foo")
end
end
end
describe '`copy-earlier-word`' do
let(:before_sourcing) do
-> do
session.
run_command('autoload -Uz copy-earlier-word').
run_command('zle -N copy-earlier-word').
run_command('bindkey "^N" copy-earlier-word')
end
end
it 'should cycle through previous words in the buffer' do
session.clear_screen
session.send_string('foo bar baz')
sleep 0.5
session.send_keys('C-n')
wait_for { session.content }.to eq('foo bar bazbaz')
session.send_keys('C-n')
wait_for { session.content }.to eq('foo bar bazbar')
session.send_keys('C-n')
wait_for { session.content }.to eq('foo bar bazfoo')
end
end
describe 'pressing ^C after fetching a suggestion' do
before do
skip 'Workaround does not work below v5.0.8' if session.zsh_version < Gem::Version.new('5.0.8')
end
it 'terminates the prompt and begins a new one' do
session.send_keys('e')
sleep 0.5
session.send_keys('C-c')
sleep 0.5
session.send_keys('echo')
wait_for { session.content }.to eq("e\necho")
end
end
end

View File

@ -0,0 +1,14 @@
describe 'with `AUTO_CD` option set' do
let(:after_sourcing) do
-> {
session.run_command('setopt AUTO_CD')
session.run_command('autoload compinit && compinit')
}
end
it 'directory names are still completed' do
session.send_string('sr')
session.send_keys('C-i')
wait_for { session.content }.to eq('src/')
end
end

View File

@ -0,0 +1,43 @@
describe 'pasting using bracketed-paste-magic' do
let(:before_sourcing) do
-> do
session.
run_command('autoload -Uz bracketed-paste-magic').
run_command('zle -N bracketed-paste bracketed-paste-magic')
end
end
context 'with suggestions disabled while pasting' do
before do
session.
run_command('bpm_init() { zle autosuggest-disable }').
run_command('bpm_finish() { zle autosuggest-enable }').
run_command('zstyle :bracketed-paste-magic paste-init bpm_init').
run_command('zstyle :bracketed-paste-magic paste-finish bpm_finish')
end
it 'does not show an incorrect suggestion' do
with_history('echo hello') do
session.paste_string("echo #{'a' * 60}")
sleep 1
expect(session.content).to eq("echo #{'a' * 60}")
end
end
end
context 'with `bracketed-paste` added to the list of widgets that clear the suggestion' do
let(:options) { ['ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste)'] }
it 'does not retain an old suggestion' do
with_history ('echo foo') do
session.send_string('echo ')
wait_for { session.content }.to eq('echo foo')
session.paste_string('bar')
wait_for { session.content }.to eq('echo bar')
session.send_keys('C-a') # Any cursor movement works
sleep 1
expect(session.content).to eq('echo bar')
end
end
end
end

View File

@ -0,0 +1,14 @@
describe 'a running zpty command' do
let(:before_sourcing) { -> { session.run_command('zmodload zsh/zpty && zpty -b kitty cat') } }
context 'when using `completion` strategy' do
let(:options) { ["ZSH_AUTOSUGGEST_STRATEGY=completion"] }
it 'is not affected' do
session.send_keys('a').send_keys('C-h')
session.run_command('zpty -t kitty; echo $?')
wait_for { session.content }.to end_with("\n0")
end
end
end

View File

@ -0,0 +1,12 @@
describe 'with `GLOB_SUBST` option set' do
let(:after_sourcing) do
-> {
session.run_command('setopt GLOB_SUBST')
}
end
it 'error messages are not printed' do
session.send_string('[[')
wait_for { session.content }.to eq('[[')
end
end

View File

@ -0,0 +1,13 @@
describe 'rebinding [' do
context 'initialized before sourcing the plugin' do
before do
session.run_command("function [ { $commands[\\[] \"$@\" }")
session.clear_screen
end
it 'executes the custom behavior and the built-in behavior' do
session.send_string('asdf')
wait_for { session.content }.to eq('asdf')
end
end
end

View File

@ -0,0 +1,80 @@
describe 'when using vi mode' do
let(:before_sourcing) do
-> do
session.run_command('bindkey -v')
end
end
describe 'moving the cursor after exiting insert mode' do
it 'should not clear the current suggestion' do
with_history('foobar foo') do
session.
send_string('foo').
send_keys('escape').
send_keys('h')
wait_for { session.content }.to eq('foobar foo')
end
end
end
describe '`vi-forward-word-end`' do
it 'should accept through the end of the current word' do
with_history('foobar foo') do
session.
send_string('foo').
send_keys('escape').
send_keys('e'). # vi-forward-word-end
send_keys('a'). # vi-add-next
send_string('baz')
wait_for { session.content }.to eq('foobarbaz')
end
end
end
describe '`vi-forward-word`' do
it 'should accept through the first character of the next word' do
with_history('foobar foo') do
session.
send_string('foo').
send_keys('escape').
send_keys('w'). # vi-forward-word
send_keys('a'). # vi-add-next
send_string('az')
wait_for { session.content }.to eq('foobar faz')
end
end
end
describe '`vi-find-next-char`' do
it 'should accept through the next occurrence of the character' do
with_history('foobar foo') do
session.
send_string('foo').
send_keys('escape').
send_keys('f'). # vi-find-next-char
send_keys('o').
send_keys('a'). # vi-add-next
send_string('b')
wait_for { session.content }.to eq('foobar fob')
end
end
end
describe '`vi-delete`' do
it 'should be able to remove the last character in the buffer' do
skip 'deleting last char did not work below zsh version 5.0.8' if session.zsh_version < Gem::Version.new('5.0.8')
session.
send_string('echo foo').
send_keys('escape').
send_keys('d').
send_keys('l')
wait_for { session.content }.to eq('echo fo')
end
end
end

View File

@ -0,0 +1,39 @@
describe 'a wrapped widget' do
let(:widget) { 'backward-delete-char' }
context 'initialized before sourcing the plugin' do
let(:before_sourcing) do
-> do
session.
run_command("_orig_#{widget}() { zle .#{widget} }").
run_command("zle -N orig-#{widget} _orig_#{widget}").
run_command("#{widget}-magic() { zle orig-#{widget}; BUFFER+=b }").
run_command("zle -N #{widget} #{widget}-magic")
end
end
it 'executes the custom behavior and the built-in behavior' do
with_history('foobar', 'foodar') do
session.send_string('food').send_keys('C-h')
wait_for { session.content }.to eq('foobar')
end
end
end
context 'initialized after sourcing the plugin' do
before do
session.
run_command("zle -N orig-#{widget} ${widgets[#{widget}]#*:}").
run_command("#{widget}-magic() { zle orig-#{widget}; BUFFER+=b }").
run_command("zle -N #{widget} #{widget}-magic").
clear_screen
end
it 'executes the custom behavior and the built-in behavior' do
with_history('foobar', 'foodar') do
session.send_string('food').send_keys('C-h')
wait_for { session.content }.to eq('foobar')
end
end
end
end

View File

@ -0,0 +1,24 @@
describe 'using `zle -U`' do
let(:before_sourcing) do
-> do
session.
run_command('_zsh_autosuggest_strategy_test() { sleep 1; _zsh_autosuggest_strategy_history "$1" }').
run_command('foo() { zle -U - "echo hello" }; zle -N foo; bindkey ^B foo')
end
end
let(:options) { ['unset ZSH_AUTOSUGGEST_USE_ASYNC', 'ZSH_AUTOSUGGEST_STRATEGY=test'] }
# TODO: This is only possible with the $KEYS_QUEUED_COUNT widget parameter, coming soon...
xit 'does not fetch a suggestion for every inserted character' do
session.send_keys('C-b')
wait_for { session.content }.to eq('echo hello')
end
it 'shows a suggestion when the widget completes' do
with_history('echo hello world') do
session.send_keys('C-b')
wait_for { session.content(esc_seqs: true) }.to match(/\Aecho hello\e\[[0-9]+m world/)
end
end
end

View File

@ -0,0 +1,23 @@
context 'with some items in the kill ring' do
before do
session.
send_string('echo foo').
send_keys('C-u').
send_string('echo bar').
send_keys('C-u')
end
describe '`yank-pop`' do
it 'should cycle through all items in the kill ring' do
session.send_keys('C-y')
wait_for { session.content }.to eq('echo bar')
session.send_keys('escape').send_keys('y')
wait_for { session.content }.to eq('echo foo')
session.send_keys('escape').send_keys('y')
wait_for { session.content }.to eq('echo bar')
end
end
end

View File

@ -0,0 +1,17 @@
context 'with zle-line-init unignored' do
let(:after_sourcing) do
-> do
session.
run_command('setopt extendedglob').
run_command('ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(${(@)ZSH_AUTOSUGGEST_IGNORE_WIDGETS:#zle-\*} zle-\^line-init)').
run_command('zle-line-init() { BUFFER="echo" }')
end
end
it 'should fetch a suggestion on each line initialization' do
with_history('echo foo') do
session.run_command('zle -N zle-line-init')
wait_for { session.content }.to end_with('echo foo')
end
end
end

View File

@ -0,0 +1,8 @@
describe 'a multi-line suggestion' do
it 'should be displayed on multiple lines' do
with_history("echo \"\n\"") do
session.send_keys('e')
wait_for { session.content }.to eq("echo \"\n\"")
end
end
end

View File

@ -0,0 +1,30 @@
describe 'a suggestion' do
let(:term_opts) { { width: 200 } }
let(:long_command) { "echo #{'a' * 100}" }
around do |example|
with_history(long_command) { example.run }
end
it 'is provided for any buffer length' do
session.send_string(long_command[0...-1])
wait_for { session.content }.to eq(long_command)
end
context 'when ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE is specified' do
let(:buffer_max_size) { 10 }
let(:options) { ["ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=#{buffer_max_size}"] }
it 'is provided when the buffer is shorter than the specified length' do
session.send_string(long_command[0...(buffer_max_size - 1)])
wait_for { session.content }.to eq(long_command)
end
it 'is provided when the buffer is equal to the specified length' do
session.send_string(long_command[0...(buffer_max_size)])
wait_for { session.content }.to eq(long_command)
end
it 'is not provided when the buffer is longer than the specified length'
end
end

View File

@ -0,0 +1,7 @@
describe 'a displayed suggestion' do
it 'is shown in the default style'
describe 'when ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE is set to a zle_highlight string' do
it 'is shown in the specified style'
end
end

View File

@ -0,0 +1,7 @@
describe 'an original zle widget' do
context 'is accessible with the default prefix'
context 'when ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX is set' do
it 'is accessible with the specified prefix'
end
end

View File

@ -0,0 +1,55 @@
describe 'a suggestion for a given prefix' do
let(:history_strategy) { '_zsh_autosuggest_strategy_history() { suggestion="history" }' }
let(:foobar_strategy) { '_zsh_autosuggest_strategy_foobar() { [[ "foobar baz" = $1* ]] && suggestion="foobar baz" }' }
let(:foobaz_strategy) { '_zsh_autosuggest_strategy_foobaz() { [[ "foobaz bar" = $1* ]] && suggestion="foobaz bar" }' }
let(:after_sourcing) do
-> do
session.run_command(history_strategy)
end
end
it 'by default is determined by calling the `history` strategy function' do
session.send_string('h')
wait_for { session.content }.to eq('history')
end
context 'when ZSH_AUTOSUGGEST_STRATEGY is set to an array' do
let(:after_sourcing) do
-> do
session.
run_command(foobar_strategy).
run_command(foobaz_strategy).
run_command('ZSH_AUTOSUGGEST_STRATEGY=(foobar foobaz)')
end
end
it 'is determined by the first strategy function to return a suggestion' do
session.send_string('foo')
wait_for { session.content }.to eq('foobar baz')
session.send_string('baz')
wait_for { session.content }.to eq('foobaz bar')
end
end
context 'when ZSH_AUTOSUGGEST_STRATEGY is set to a string' do
let(:after_sourcing) do
-> do
session.
run_command(foobar_strategy).
run_command(foobaz_strategy).
run_command('ZSH_AUTOSUGGEST_STRATEGY="foobar foobaz"')
end
end
it 'is determined by the first strategy function to return a suggestion' do
session.send_string('foo')
wait_for { session.content }.to eq('foobar baz')
session.send_string('baz')
wait_for { session.content }.to eq('foobaz bar')
end
end
end

View File

@ -0,0 +1,121 @@
describe 'a zle widget' do
let(:widget) { 'my-widget' }
let(:before_sourcing) { -> { session.run_command("#{widget}() {}; zle -N #{widget}; bindkey ^B #{widget}") } }
context 'when added to ZSH_AUTOSUGGEST_ACCEPT_WIDGETS' do
let(:options) { ["ZSH_AUTOSUGGEST_ACCEPT_WIDGETS+=(#{widget})"] }
it 'accepts the suggestion and moves the cursor to the end of the buffer when invoked' do
with_history('echo hello') do
session.send_string('e')
wait_for { session.content }.to eq('echo hello')
session.send_keys('C-b')
wait_for { session.content(esc_seqs: true) }.to eq('echo hello')
wait_for { session.cursor }.to eq([10, 0])
end
end
end
context 'when added to ZSH_AUTOSUGGEST_CLEAR_WIDGETS' do
let(:options) { ["ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(#{widget})"] }
it 'clears the suggestion when invoked' do
with_history('echo hello') do
session.send_string('e')
wait_for { session.content }.to eq('echo hello')
session.send_keys('C-b')
wait_for { session.content }.to eq('e')
end
end
end
context 'when added to ZSH_AUTOSUGGEST_EXECUTE_WIDGETS' do
let(:options) { ["ZSH_AUTOSUGGEST_EXECUTE_WIDGETS+=(#{widget})"] }
it 'executes the suggestion when invoked' do
with_history('echo hello') do
session.send_string('e')
wait_for { session.content }.to eq('echo hello')
session.send_keys('C-b')
wait_for { session.content }.to end_with("\nhello")
end
end
end
context 'when added to ZSH_AUTOSUGGEST_IGNORE_WIDGETS' do
let(:options) { ["ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(#{widget})"] }
it 'should not be wrapped with an autosuggest widget' do
session.run_command("echo $widgets[#{widget}]")
wait_for { session.content }.to end_with("\nuser:#{widget}")
end
end
context 'that moves the cursor forward' do
before { session.run_command("#{widget}() { zle forward-char }") }
context 'when added to ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS' do
let(:options) { ["ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(#{widget})"] }
it 'accepts the suggestion as far as the cursor is moved when invoked' do
with_history('echo hello') do
session.send_string('e')
wait_for { session.content }.to start_with('echo hello')
session.send_keys('C-b')
wait_for { session.content(esc_seqs: true) }.to match(/\Aec\e\[[0-9]+mho hello/)
end
end
end
end
context 'that modifies the buffer' do
before { session.run_command("#{widget}() { BUFFER=\"foo\" }") }
context 'when not added to any of the widget lists' do
it 'modifies the buffer and fetches a new suggestion' do
with_history('foobar') do
session.send_keys('C-b')
wait_for { session.content }.to eq('foobar')
end
end
end
end
end
describe 'a modification to the widget lists' do
let(:widget) { 'my-widget' }
let(:before_sourcing) { -> { session.run_command("#{widget}() {}; zle -N #{widget}; bindkey ^B #{widget}") } }
before { session.run_command("ZSH_AUTOSUGGEST_ACCEPT_WIDGETS+=(#{widget})") }
it 'takes effect on the next cmd line' do
with_history('echo hello') do
session.send_string('e')
wait_for { session.content }.to eq('echo hello')
session.send_keys('C-b')
wait_for { session.content(esc_seqs: true) }.to eq('echo hello')
end
end
context 'when manual rebind is enabled' do
let(:options) { ["ZSH_AUTOSUGGEST_MANUAL_REBIND=true"] }
it 'does not take effect until bind command is re-run' do
with_history('echo hello') do
session.send_string('e')
wait_for { session.content }.to eq('echo hello')
session.send_keys('C-b')
sleep 1
expect(session.content(esc_seqs: true)).not_to eq('echo hello')
session.send_keys('C-c')
session.run_command('_zsh_autosuggest_bind_widgets').clear_screen
wait_for { session.content }.to eq('')
session.send_string('e')
wait_for { session.content }.to eq('echo hello')
session.send_keys('C-b')
wait_for { session.content(esc_seqs: true) }.to eq('echo hello')
end
end
end
end

Some files were not shown because too many files have changed in this diff Show More