├── docs ├── images │ ├── math.gif │ ├── theme.png │ ├── zcalc.png │ ├── 203654.gif │ ├── assign.png │ ├── brackets.gif │ ├── cmdsubst.png │ ├── eval_cmp.png │ ├── execfd.png │ ├── for-loop.png │ ├── function.png │ ├── heredoc.png │ ├── typeset.png │ ├── cplx_cond.png │ ├── execfd_cmp.png │ ├── git_chroma.png │ ├── herestring.png │ ├── in_string.png │ ├── parameter.png │ ├── array-assign.png │ ├── for-loop-cmp.png │ ├── global-alias.png │ ├── ideal-string.png │ ├── highlight-less.png │ └── highlight-much.png ├── THEME_GUIDE.md ├── CHANGELOG.md └── CHROMA_GUIDE.adoc ├── .zunit.yml ├── .github ├── dependabot.yml ├── workflows │ ├── sync-labels.yml │ ├── labeler.yml │ ├── assign.yml │ ├── trunk-check.yml │ ├── zsh-n.yml │ └── zunit.yml ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── 03_codebase_improvement.yml │ ├── 02_feature_request.yml │ ├── 04_documentation.yml │ └── 01_bug_report.yml ├── labeler.yml └── PULL_REQUEST_TEMPLATE.md ├── .vscode └── settings.json ├── .trunk ├── configs │ ├── .shellcheckrc │ └── .markdownlint.yaml └── trunk.yaml ├── chroma ├── -precommand.ch ├── -autorandr.ch ├── -subcommand.ch ├── -alias.ch ├── -node.ch ├── -fast-theme.ch ├── -vim.ch ├── -fpath_peq.ch ├── -nmcli.ch ├── -hub.ch ├── -sh.ch ├── -source.ch ├── -lab.ch ├── -perl.ch ├── -ruby.ch ├── -scp.ch ├── -printf.ch ├── -grep.ch ├── -docker.ch ├── -which.ch ├── -awk.ch ├── -make.ch ├── -autoload.ch ├── -example.ch ├── -whatis.ch ├── -ionice.ch ├── -nice.ch ├── -ssh.ch └── -zi.ch ├── functions ├── .fast-zts-read-all ├── .fast-read-ini-file ├── .fast-run-command ├── _fast-theme ├── .fast-run-git-command ├── .fast-make-targets └── fast-string-highlight ├── LICENSE ├── themes ├── base16.ini ├── z-shell.ini ├── zdharma.ini ├── forest.ini ├── clean.ini ├── free.ini ├── spa.ini ├── safari.ini ├── default.ini ├── sv-plant.ini ├── sv-orple.ini └── q-jmnemonic.ini ├── .editorconfig ├── share ├── free_theme.zsh └── parse │ └── parse.zsh └── tests └── main.zunit /docs/images/math.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/math.gif -------------------------------------------------------------------------------- /docs/images/theme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/theme.png -------------------------------------------------------------------------------- /docs/images/zcalc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/zcalc.png -------------------------------------------------------------------------------- /docs/images/203654.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/203654.gif -------------------------------------------------------------------------------- /docs/images/assign.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/assign.png -------------------------------------------------------------------------------- /docs/images/brackets.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/brackets.gif -------------------------------------------------------------------------------- /docs/images/cmdsubst.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/cmdsubst.png -------------------------------------------------------------------------------- /docs/images/eval_cmp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/eval_cmp.png -------------------------------------------------------------------------------- /docs/images/execfd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/execfd.png -------------------------------------------------------------------------------- /docs/images/for-loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/for-loop.png -------------------------------------------------------------------------------- /docs/images/function.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/function.png -------------------------------------------------------------------------------- /docs/images/heredoc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/heredoc.png -------------------------------------------------------------------------------- /docs/images/typeset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/typeset.png -------------------------------------------------------------------------------- /docs/images/cplx_cond.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/cplx_cond.png -------------------------------------------------------------------------------- /docs/images/execfd_cmp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/execfd_cmp.png -------------------------------------------------------------------------------- /docs/images/git_chroma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/git_chroma.png -------------------------------------------------------------------------------- /docs/images/herestring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/herestring.png -------------------------------------------------------------------------------- /docs/images/in_string.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/in_string.png -------------------------------------------------------------------------------- /docs/images/parameter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/parameter.png -------------------------------------------------------------------------------- /docs/images/array-assign.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/array-assign.png -------------------------------------------------------------------------------- /docs/images/for-loop-cmp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/for-loop-cmp.png -------------------------------------------------------------------------------- /docs/images/global-alias.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/global-alias.png -------------------------------------------------------------------------------- /docs/images/ideal-string.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/ideal-string.png -------------------------------------------------------------------------------- /docs/images/highlight-less.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/highlight-less.png -------------------------------------------------------------------------------- /docs/images/highlight-much.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z-shell/F-Sy-H/HEAD/docs/images/highlight-much.png -------------------------------------------------------------------------------- /.zunit.yml: -------------------------------------------------------------------------------- 1 | tap: false 2 | directories: 3 | tests: tests 4 | time_limit: 0 5 | fail_fast: false 6 | allow_risky: false 7 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "*za-*": "shellscript", 4 | ".ch": "shellscript", 5 | "fast-*": "shellscript", 6 | ".fast-*": "shellscript" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.trunk/configs/.shellcheckrc: -------------------------------------------------------------------------------- 1 | enable=all 2 | source-path=SCRIPTDIR 3 | disable=SC2154 4 | 5 | # If you're having issues with shellcheck following source, disable the errors via: 6 | # disable=SC1090 7 | # disable=SC1091 8 | -------------------------------------------------------------------------------- /.github/workflows/sync-labels.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "♻️ Sync Labels" 3 | 4 | on: 5 | schedule: 6 | - cron: "22 2 * * 2" 7 | workflow_dispatch: {} 8 | 9 | jobs: 10 | labels: 11 | name: "♻️ Sync labels" 12 | uses: z-shell/.github/.github/workflows/sync-labels.yml@main 13 | -------------------------------------------------------------------------------- /.trunk/configs/.markdownlint.yaml: -------------------------------------------------------------------------------- 1 | # Autoformatter friendly markdownlint config (all formatting rules disabled) 2 | default: true 3 | blank_lines: false 4 | bullet: false 5 | html: false 6 | indentation: false 7 | line_length: false 8 | spaces: false 9 | url: false 10 | whitespace: false 11 | -------------------------------------------------------------------------------- /.github/workflows/labeler.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🔖 Pull Request Labeler 3 | on: 4 | pull_request_target: 5 | 6 | permissions: 7 | contents: read 8 | pull-requests: write 9 | 10 | jobs: 11 | triage: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/labeler@v5 15 | with: 16 | repo-token: "${{ secrets.GITHUB_TOKEN }}" 17 | sync-labels: false 18 | -------------------------------------------------------------------------------- /.github/workflows/assign.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "❇️ Assign" 3 | 4 | on: 5 | issues: 6 | types: 7 | - opened 8 | pull_request: 9 | types: 10 | - labeled 11 | 12 | jobs: 13 | assign: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/add-to-project@main 17 | with: 18 | project-url: https://github.com/orgs/z-shell/projects/4 19 | github-token: ${{ secrets.GITHUB_TOKEN }} 20 | labeled: bug 🐞, triage 📑, plugin ⚙️ 21 | label-operator: OR 22 | -------------------------------------------------------------------------------- /chroma/-precommand.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | 4 | 5 | local __first_call="$1" __start_pos="$3" __end_pos="$4" 6 | 7 | [[ "$__arg_type" = 3 ]] && return 2 8 | 9 | (( __first_call )) && { 10 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 11 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}precommand]}") 12 | (( next_word = (next_word & ~2) | 4 | 1 )) 13 | } || { 14 | return 1 15 | } 16 | 17 | (( this_word = next_word )) 18 | _start_pos=$_end_pos 19 | return 0 20 | -------------------------------------------------------------------------------- /.github/workflows/trunk-check.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "⭕ Trunk" 3 | on: 4 | push: 5 | branches: [main] 6 | tags: ["v*.*.*"] 7 | pull_request: 8 | types: [opened, synchronize] 9 | schedule: 10 | - cron: "0 05 * * 5" 11 | workflow_dispatch: 12 | 13 | jobs: 14 | check: 15 | if: github.event.schedule != '0 05 * * 5' 16 | name: "⚡" 17 | uses: z-shell/.github/.github/workflows/trunk.yml@main 18 | upload: 19 | if: github.event.schedule == '0 05 * * 5' 20 | name: "🆙" 21 | uses: z-shell/.github/.github/workflows/trunk.yml@main 22 | secrets: 23 | trunk-token: ${{ secrets.TRUNK_TOKEN }} 24 | -------------------------------------------------------------------------------- /functions/.fast-zts-read-all: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # $1 - file-descriptor to be read from 5 | # $2 - name of output variable (default: REPLY) 6 | 7 | local __in_fd=${1:-0} __out_var=${2:-REPLY} 8 | local -a __tmp 9 | integer __ret=1 __repeat=10 __tmp_size=0 10 | 11 | while sysread -s 65535 -i "$__in_fd" '__tmp[__tmp_size + 1]'; do 12 | (( ( __ret=$? ) == 0 )) && (( ++ __tmp_size )) 13 | (( __ret == 5 )) && { __ret=0; (( --__repeat == 0 )) && break; } 14 | done 15 | 16 | : ${(P)__out_var::="${(j::)__tmp}"} 17 | 18 | return __ret 19 | -------------------------------------------------------------------------------- /.trunk/trunk.yaml: -------------------------------------------------------------------------------- 1 | version: 0.1 2 | cli: 3 | version: 1.3.2 4 | plugins: 5 | sources: 6 | - id: trunk 7 | ref: v0.0.8 8 | uri: https://github.com/trunk-io/plugins 9 | lint: 10 | enabled: 11 | - gitleaks@8.15.3 12 | - shellcheck@0.9.0 13 | - git-diff-check 14 | - actionlint@1.6.23 15 | - shfmt@3.5.0 16 | - markdownlint@0.33.0 17 | - oxipng@8.0.0 18 | - prettier@2.8.3 19 | ignore: 20 | - linters: [ALL] 21 | paths: 22 | - "share/test/**" 23 | runtimes: 24 | enabled: 25 | - go@1.18.3 26 | - node@18.12.1 27 | actions: 28 | enabled: 29 | - trunk-announce 30 | - trunk-check-pre-push 31 | - trunk-fmt-pre-commit 32 | - trunk-upgrade-available 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | blank_issues_enabled: true 3 | contact_links: 4 | - name: ZI Wiki 5 | url: https://z.digitalclouds.dev 6 | about: Knowledge base. 7 | - name: Community Discussions 8 | url: https://github.com/orgs/z-shell/discussions 9 | about: Please ask and answer questions here. 10 | - name: Slack Workspace 11 | url: https://join.slack.com/t/z-shell/shared_invite/zt-16twpopd2-p08ROUeT2aGZ5njJwysawA 12 | about: Join to ask and answer questions or collaborate. 13 | - name: Crowdin Translations 14 | url: https://digitalclouds.crowdin.com/z-shell 15 | about: Join to participate in translations. 16 | - name: Z-Shell Portfolio 17 | url: https://github.zshell.dev/ 18 | about: Z-Shell organization portfolio and governance. 19 | -------------------------------------------------------------------------------- /chroma/-autorandr.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | 4 | (( next_word = 2 | 8192 )) 5 | [[ "$__arg_type" = 3 ]] && return 2 6 | 7 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 8 | 9 | if (( __first_call )) || [[ "$__wrd" = -* ]]; then 10 | return 1 11 | else 12 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 13 | return 1 14 | fi 15 | if [[ -d "${XDG_CONFIG_HOME:-$HOME/.config}/autorandr/$__wrd" ]] then 16 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 17 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") 18 | fi 19 | fi 20 | 21 | (( this_word = next_word )) 22 | _start_pos=$_end_pos 23 | 24 | return 0 25 | -------------------------------------------------------------------------------- /chroma/-subcommand.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | 4 | (( next_word = 2 | 8192 )) 5 | [[ "$__arg_type" = 3 ]] && return 2 6 | 7 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 8 | 9 | if (( __first_call )); then 10 | FAST_HIGHLIGHT[chroma-subcommand]="" 11 | return 1 12 | elif (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 13 | return 1 14 | elif [[ "$2" = -* ]]; then 15 | return 1 16 | elif [[ -z "${FAST_HIGHLIGHT[chroma-subcommand]}" ]]; then 17 | FAST_HIGHLIGHT[chroma-subcommand]="$__wrd" 18 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 19 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}") 20 | else 21 | return 1 22 | fi 23 | 24 | (( this_word = next_word )) 25 | _start_pos=$_end_pos 26 | 27 | return 0 28 | -------------------------------------------------------------------------------- /.github/labeler.yml: -------------------------------------------------------------------------------- 1 | documentation 📝: 2 | - "docs/**/*.md" 3 | - "community/**/*.md" 4 | - "ecosystem/**/*.md" 5 | dependencies 📦: 6 | - "package.json" 7 | - "pnpm-lock.yaml" 8 | - "yarn.lock" 9 | enhancement ✨: 10 | - "functions/**" 11 | - "src/**" 12 | - "lib/**" 13 | maintenance 📈: 14 | - ".editorconfig" 15 | - ".gitattributes" 16 | - ".gitignore" 17 | - ".github/CODEOWNERS" 18 | - ".github/*rc" 19 | - ".github/*.md" 20 | - ".github/*.yml" 21 | - ".github/*.yaml" 22 | - ".github/*.json" 23 | - ".markdownlint.json" 24 | - ".prettierrc" 25 | - ".prettierignore" 26 | - ".trunk/*.yaml" 27 | - ".trunk/*.json" 28 | - ".trunk/*rc" 29 | - ".vscode/**" 30 | - "babel.config.js" 31 | - "crowdin.yml" 32 | - "netlify.toml" 33 | - "tsconfig.json" 34 | i18n 🌐: 35 | - "i18n/**" 36 | - "docs/i18n/**" 37 | #annex 🌀: 38 | # - "*" 39 | #package 📦: 40 | # - 'ecosystem/packages/**/*.md' 41 | # - 'i18n/**/docusaurus-plugin-content-ecosystem/**/packages/**/*.md' 42 | plugin ⚙️: 43 | - "*.zsh" 44 | ci 🤖: 45 | - ".github/workflows/*" 46 | -------------------------------------------------------------------------------- /chroma/-alias.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | 5 | (( next_word = 2 | 8192 )) 6 | [[ "$__arg_type" = 3 ]] && return 2 7 | 8 | local __first_call="$1" __wrd="${2%%=*}" __start_pos="$3" __end_pos="$4" 9 | 10 | if (( __first_call )) || [[ "$2" = -* ]]; then 11 | return 1 12 | else 13 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 14 | return 1 15 | elif (( $+aliases[(e)$__wrd] )) || (( ${+galiases[(e)$__wrd]} )); then 16 | (( __start=__start_pos-${#PREBUFFER}, __end=__start_pos+${#__wrd}-${#PREBUFFER}, __start >= 0 )) \ 17 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") 18 | elif (( $+functions[(e)$__wrd] )) || (( $+builtins[(e)$__wrd] )) || (( $+commands[(e)$__wrd] )) || (( $reswords[(Ie)$__wrd] )); then 19 | (( __start=__start_pos-${#PREBUFFER}, __end=__start_pos+${#__wrd}-${#PREBUFFER}, __start >= 0 )) \ 20 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") 21 | else 22 | return 1 23 | fi 24 | if [[ "$__wrd" != "$2" ]]; then 25 | return 1 26 | fi 27 | fi 28 | 29 | (( this_word = next_word )) 30 | _start_pos=$_end_pos 31 | 32 | return 0 33 | -------------------------------------------------------------------------------- /functions/.fast-read-ini-file: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # Copyright (c) 2018 Sebastian Gniazdowski 5 | # 6 | # $1 - path to the ini file to parse 7 | # $2 - name of output hash (INI by default) 8 | # $3 - prefix for keys in the hash (can be empty) 9 | # 10 | # Writes to given hash under keys built in following way: ${3}
_field. 11 | # Values are values from ini file. 12 | 13 | local __ini_file="$1" __out_hash="${2:-INI}" __key_prefix="$3" 14 | local IFS='' __line __cur_section="void" __access_string 15 | local -a match mbegin mend 16 | 17 | [[ ! -r "$__ini_file" ]] && { builtin print -r "fast-syntax-highlighting: an ini file is unreadable ($__ini_file)"; return 1; } 18 | 19 | while read -r -t 1 __line; do 20 | if [[ "$__line" = [[:blank:]]#\;* ]]; then 21 | continue 22 | elif [[ "$__line" = (#b)[[:blank:]]#\[([^\]]##)\][[:blank:]]# ]]; then 23 | __cur_section="${match[1]}" 24 | elif [[ "$__line" = (#b)[[:blank:]]#([^[:blank:]=]##)[[:blank:]]#[=][[:blank:]]#(*) ]]; then 25 | match[2]="${match[2]%"${match[2]##*[! $'\t']}"}" # remove trailing whitespace 26 | __access_string="${__out_hash}[${__key_prefix}<$__cur_section>_${match[1]}]" 27 | : "${(P)__access_string::=${match[2]}}" 28 | fi 29 | done < "$__ini_file" 30 | 31 | return 0 32 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Pull request template 2 | 3 | 4 | 5 | ## Type of changes 6 | 7 | 8 | 9 | - [ ] CI 10 | - [ ] Bugfix 11 | - [ ] Feature 12 | - [ ] Generic maintenance tasks 13 | - [ ] Documentation content changes 14 | - [ ] Code style update (formatting, renaming) 15 | - [ ] Refactoring (no functional changes, no URL changes) 16 | - [ ] Improving the performance of the project (not introducing new features) 17 | - [ ] Other (please describe): 18 | 19 | Issue Number: N/A 20 | 21 | ## What is the current behavior? 22 | 23 | 24 | 25 | ## What is the new behavior? 26 | 27 | 28 | 29 | ### Does this introduce a breaking change? 30 | 31 | - [ ] Yes 32 | - [ ] No 33 | 34 | 35 | 36 | ## Other information 37 | 38 | 39 | 40 | N/A 41 | -------------------------------------------------------------------------------- /chroma/-node.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | 4 | (( next_word = 2 | 8192 )) 5 | [[ "$__arg_type" = 3 ]] && return 2 6 | 7 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 8 | local __style 9 | 10 | if (( __first_call )); then 11 | FAST_HIGHLIGHT[chroma-node-file]=1 12 | elif (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 13 | return 1 14 | elif [[ "$__wrd" = -- ]]; then 15 | FAST_HIGHLIGHT[chroma-node-file]=2 16 | elif (( FAST_HIGHLIGHT[chroma-node-file] != 2 )) && [[ "$__wrd" = -* ]]; then 17 | if [[ "$__wrd" = -*e* || "$__wrd" = --eval ]]; then 18 | FAST_HIGHLIGHT[chroma-node-file]=0 19 | fi 20 | elif (( FAST_HIGHLIGHT[chroma-node-file] )); then 21 | if [[ "$__wrd" = debug || "$__wrd" = inspect ]]; then 22 | __style=${FAST_THEME_NAME}subcommand 23 | else 24 | FAST_HIGHLIGHT[chroma-node-file]=0 25 | if [[ -f ${~__wrd} || -f ${~__wrd}.js || -f ${~__wrd}/index.js ]]; then 26 | __style=${FAST_THEME_NAME}path 27 | else 28 | __style=${FAST_THEME_NAME}incorrect-subtle 29 | fi 30 | fi 31 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 32 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 33 | (( this_word = next_word )) 34 | _start_pos=$_end_pos 35 | 36 | return 0 37 | fi 38 | 39 | return 1 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2016 zsh-syntax-highlighting contributors 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted 5 | provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this list of conditions 8 | and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, this list of 10 | conditions and the following disclaimer in the documentation and/or other materials provided 11 | with the distribution. 12 | * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors 13 | may be used to endorse or promote products derived from this software without specific prior 14 | written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 17 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 19 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 22 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 23 | OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /chroma/-fast-theme.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | 4 | (( next_word = 2 | 8192 )) 5 | [[ "$__arg_type" = 3 ]] && return 2 6 | 7 | local __first_call="$1" __wrd="${(Q)2}" __start_pos="$3" __end_pos="$4" 8 | local __style 9 | 10 | if (( __first_call )); then 11 | FAST_HIGHLIGHT[chroma-fast-theme-first]=0 12 | return 1 13 | elif (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 14 | return 1 15 | elif (( ${FAST_HIGHLIGHT[chroma-fast-theme-first]} )) || [[ $__wrd = -* ]]; then 16 | return 1 17 | else 18 | FAST_HIGHLIGHT[chroma-fast-theme-first]=1 19 | fi 20 | 21 | if [[ "$__wrd" = */* || "$__wrd" = (CONFIG|CACHE|LOCAL|HOME|OPT):* ]]; then 22 | __wrd="${${__wrd/(#s)CONFIG:/${${XDG_CONFIG_HOME:-$HOME/.config}%/}/f-sy-h/}%.ini}.ini" 23 | __wrd="${${__wrd/(#s)CACHE:/${${XDG_CACHE_HOME:-$HOME/.cache}%/}/f-sy-h/}%.ini}.ini" 24 | __wrd="${${__wrd/(#s)LOCAL://usr/local/share/f-sy-h/}%.ini}.ini" 25 | __wrd="${${__wrd/(#s)HOME:/$HOME/.f-sy-h/}%.ini}.ini" 26 | __wrd="${${__wrd/(#s)OPT://opt/local/share/f-sy-h/}%.ini}.ini" 27 | __wrd=${~__wrd} # allow user to quote ~ 28 | else 29 | __wrd="$FAST_BASE_DIR/themes/$__wrd.ini" 30 | fi 31 | 32 | if [[ -f $__wrd ]]; then 33 | __style=${FAST_THEME_NAME}path 34 | else 35 | __style=${FAST_THEME_NAME}incorrect-subtle 36 | fi 37 | 38 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 39 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 40 | (( this_word = next_word )) 41 | _start_pos=$_end_pos 42 | 43 | return 0 44 | -------------------------------------------------------------------------------- /functions/.fast-run-command: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # Copyright (c) 2018 Sebastian Gniazdowski 5 | # 6 | # FAST_HIGHLIGHT hash serves as container for variables that 7 | # prevents creating them in global scope. (P) flag is not used, 8 | # output array is fixed (__lines_list). 9 | # 10 | # $1 - the command, e.g. "git remote"; 2>/dev/null redirection is 11 | # added automatically 12 | # $2 - FAST_HIGHLIGHT field name, e.g. "chroma-git-branches"; two 13 | # additional fields will be used, $2-cache, $2-cache-born-at 14 | # $3 - what to remove from beginning of the lines returned by the 15 | # command 16 | # $4 - cache validity time, default 5 (seconds) 17 | # 18 | # Output: array __lines_list, with output of the command ran 19 | 20 | # User should not forget to define this array, the below code 21 | # will only ensure that it's array (can also define a global) 22 | typeset -ga __lines_list 23 | local -a __response 24 | 25 | if [[ -z "${FAST_HIGHLIGHT[$2-cache]}" || $(( EPOCHSECONDS - FAST_HIGHLIGHT[$2-cache-born-at] )) -gt ${4:-5} ]]; then 26 | FAST_HIGHLIGHT[$2-cache-born-at]="$EPOCHSECONDS" 27 | __response=( ${${(f)"$(command ${(Qz)1#+} 2>/dev/null)"}#${~3}} ) 28 | [[ "$1" = "+"* ]] && __lines_list+=( "${__response[@]}" ) || __lines_list=( "${__response[@]}" ) 29 | FAST_HIGHLIGHT[$2-cache]="${(j:;:)__response}" 30 | else 31 | # Quoted (s:;:) flag without @ will skip empty elements. It 32 | # still produces array output, interestingly. All this is for 33 | # the trailing ";" above, to skip last, empty element. 34 | [[ "$1" = "+"* ]] && \ 35 | __lines_list+=( "${(@s:;:)FAST_HIGHLIGHT[$2-cache]}" ) || __lines_list=( "${(@s:;:)FAST_HIGHLIGHT[$2-cache]}" ) 36 | fi 37 | -------------------------------------------------------------------------------- /.github/workflows/zsh-n.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "✅ Zsh" 3 | on: 4 | push: 5 | paths: 6 | - "**/*.ch" 7 | - "**/*.zsh" 8 | - "tests/*" 9 | - "share/*" 10 | - "themes/*" 11 | - "functions/*" 12 | pull_request: 13 | paths: 14 | - "**/*.ch" 15 | - "**/*.zsh" 16 | - "tests/*" 17 | - "share/*" 18 | - "themes/*" 19 | - "functions/*" 20 | workflow_dispatch: {} 21 | 22 | jobs: 23 | zsh-matrix: 24 | runs-on: ubuntu-latest 25 | outputs: 26 | matrix: ${{ steps.set-matrix.outputs.matrix }} 27 | steps: 28 | - name: ⤵️ Check out code from GitHub 29 | uses: actions/checkout@v4 30 | - name: "⚡ Set matrix output" 31 | id: set-matrix 32 | run: | 33 | MATRIX="$(find . -type d -name 'doc' -prune -o -type f \( -iname '*.zsh' -o -iname '*.ch' -o -iname 'fast-*' \) -print | jq -ncR '{"include": [{"file": inputs}]}')" 34 | echo "MATRIX=${MATRIX}" >&2 35 | echo "matrix=${MATRIX}" >> $GITHUB_OUTPUT 36 | zsh-n: 37 | runs-on: ubuntu-latest 38 | needs: zsh-matrix 39 | strategy: 40 | fail-fast: false 41 | matrix: ${{ fromJSON(needs.zsh-matrix.outputs.matrix) }} 42 | steps: 43 | - name: ⤵️ Check out code from GitHub 44 | uses: actions/checkout@v4 45 | - name: "⚡ Install dependencies" 46 | run: sudo apt update && sudo apt-get install -yq zsh 47 | - name: "⚡ zsh -n: ${{ matrix.file }}" 48 | env: 49 | ZSH_FILE: ${{ matrix.file }} 50 | run: | 51 | zsh -n "${ZSH_FILE}" 52 | - name: "⚡ zcompile ${{ matrix.file }}" 53 | env: 54 | ZSH_FILE: ${{ matrix.file }} 55 | run: | 56 | zsh -fc "zcompile ${ZSH_FILE}"; rc=$? 57 | ls -al "${ZSH_FILE}.zwc"; exit "$rc" 58 | -------------------------------------------------------------------------------- /themes/base16.ini: -------------------------------------------------------------------------------- 1 | [base] 2 | default = none 3 | unknown-token = 1,bold 4 | commandseparator = none 5 | redirection = none 6 | here-string-tri = 14 7 | here-string-text = bg:11 8 | here-string-var = 1,bg:11 9 | exec-descriptor = 9,bold 10 | comment = 8 11 | correct-subtle = 12 12 | incorrect-subtle = 1 13 | subtle-separator = 12 14 | subtle-bg = bg:10 15 | ; secondary = 16 | ; recursive-base = 17 | 18 | [command-point] 19 | reserved-word = 5 20 | subcommand = 6 21 | alias = 4 22 | suffix-alias = 4 23 | global-alias = 4,bg:11 24 | builtin = 4 25 | function = 4 26 | command = 4 27 | precommand = 6 28 | hashed-command = 4 29 | single-sq-bracket = 4 30 | double-sq-bracket = 4 31 | double-paren = 5 32 | 33 | [paths] 34 | path = 9 35 | pathseparator = 36 | path-to-dir = 9,underline 37 | globbing = 6 38 | globbing-ext = 6,bold 39 | 40 | [brackets] 41 | paired-bracket = bg:8 42 | bracket-level-1 = 3,bold 43 | bracket-level-2 = 6,bold 44 | bracket-level-3 = 2,bold 45 | 46 | [arguments] 47 | single-hyphen-option = 3 48 | double-hyphen-option = 3 49 | back-quoted-argument = none 50 | single-quoted-argument = 2 51 | double-quoted-argument = 2 52 | dollar-quoted-argument = 2 53 | 54 | [in-string] 55 | ; backslash in $'...' 56 | back-dollar-quoted-argument = 6 57 | ; backslash or $... in "..." 58 | back-or-dollar-double-quoted-argument = 1 59 | 60 | [other] 61 | variable = 1 62 | assign = none 63 | assign-array-bracket = 5 64 | history-expansion = 6,bold 65 | 66 | [math] 67 | mathvar = 1 68 | mathnum = 9 69 | matherr = 1,bold 70 | 71 | [for-loop] 72 | forvar = 1 73 | fornum = 9 74 | ; operator 75 | foroper = none 76 | ; separator 77 | forsep = none 78 | 79 | [case] 80 | case-input = 1 81 | case-parentheses = 5 82 | case-condition = bg:10 83 | -------------------------------------------------------------------------------- /themes/z-shell.ini: -------------------------------------------------------------------------------- 1 | [base] 2 | default = none 3 | unknown-token = 196,bold 4 | commandseparator = none 5 | redirection = none 6 | here-string-tri = 141 7 | here-string-text = bg:19 8 | here-string-var = 45,bg:19 9 | exec-descriptor = yellow,bold 10 | comment = black,bold 11 | correct-subtle = bg:55 12 | incorrect-subtle = bg:52 13 | subtle-bg = bg:17 14 | secondary = base16 15 | recursive-base = 190 16 | 17 | [command-point] 18 | reserved-word = 48 19 | reserved-word = 48 20 | alias = 93 21 | suffix-alias = 93 22 | global-alias = bg:19 23 | builtin = 93 24 | function = 93 25 | command = 93 26 | precommand = 93 27 | hashed-command = 93 28 | single-sq-bracket = 93 29 | double-sq-bracket = 93 30 | double-paren = 48 31 | 32 | [paths] 33 | path = 82 34 | pathseparator = 35 | path-to-dir = 82,underline 36 | globbing = 200 37 | globbing-ext = 135 38 | 39 | [brackets] 40 | paired-bracket = bg:blue 41 | bracket-level-1 = 165 42 | bracket-level-2 = 226 43 | bracket-level-3 = 50 44 | 45 | [arguments] 46 | single-hyphen-option = 45 47 | double-hyphen-option = 45 48 | back-quoted-argument = none 49 | single-quoted-argument = 48 50 | double-quoted-argument = 48 51 | dollar-quoted-argument = 48 52 | 53 | [in-string] 54 | ; backslash in $'...' 55 | back-dollar-quoted-argument = 45 56 | ; backslash or $... in "..." 57 | back-or-dollar-double-quoted-argument = 45 58 | 59 | [other] 60 | variable = none 61 | assign = none 62 | assign-array-bracket = 93 63 | history-expansion = blue,bold 64 | 65 | [math] 66 | mathvar = blue,bold 67 | mathnum = 82 68 | matherr = red 69 | 70 | [for-loop] 71 | forvar = none 72 | fornum = 82 73 | ; operator 74 | foroper = 48 75 | ; separator 76 | forsep = 111 77 | 78 | [case] 79 | case-input = 93 80 | case-parentheses = 141 81 | case-condition = bg:19 82 | -------------------------------------------------------------------------------- /themes/zdharma.ini: -------------------------------------------------------------------------------- 1 | [base] 2 | default = none 3 | unknown-token = red,bold 4 | commandseparator = none 5 | redirection = none 6 | here-string-tri = 141 7 | here-string-text = bg:19 8 | here-string-var = 177,bg:19 9 | exec-descriptor = yellow,bold 10 | comment = black,bold 11 | correct-subtle = bg:55 12 | incorrect-subtle = bg:52 13 | subtle-bg = bg:17 14 | secondary = safari 15 | recursive-base = 186 16 | 17 | [command-point] 18 | reserved-word = 146 19 | reserved-word = 146 20 | alias = 63 21 | suffix-alias = 63 22 | global-alias = bg:19 23 | builtin = 63 24 | function = 63 25 | command = 63 26 | precommand = 63 27 | hashed-command = 63 28 | single-sq-bracket = 63 29 | double-sq-bracket = 63 30 | double-paren = 146 31 | 32 | [paths] 33 | path = 154 34 | pathseparator = 35 | path-to-dir = 154,underline 36 | globbing = 114 37 | globbing-ext = 153 38 | 39 | [brackets] 40 | paired-bracket = bg:blue 41 | bracket-level-1 = 117 42 | bracket-level-2 = 141 43 | bracket-level-3 = 90 44 | 45 | [arguments] 46 | single-hyphen-option = 177 47 | double-hyphen-option = 177 48 | back-quoted-argument = none 49 | single-quoted-argument = 146 50 | double-quoted-argument = 146 51 | dollar-quoted-argument = 146 52 | 53 | [in-string] 54 | ; backslash in $'...' 55 | back-dollar-quoted-argument = 177 56 | ; backslash or $... in "..." 57 | back-or-dollar-double-quoted-argument = 177 58 | 59 | [other] 60 | variable = none 61 | assign = none 62 | assign-array-bracket = 63 63 | history-expansion = blue,bold 64 | 65 | [math] 66 | mathvar = blue,bold 67 | mathnum = 154 68 | matherr = red 69 | 70 | [for-loop] 71 | forvar = none 72 | fornum = 154 73 | ; operator 74 | foroper = 146 75 | ; separator 76 | forsep = 109 77 | 78 | [case] 79 | case-input = 63 80 | case-parentheses = 141 81 | case-condition = bg:19 82 | -------------------------------------------------------------------------------- /themes/forest.ini: -------------------------------------------------------------------------------- 1 | [base] 2 | default = none 3 | unknown-token = 124,bold 4 | commandseparator = none 5 | redirection = none 6 | here-string-tri = yellow 7 | here-string-text = underline 8 | here-string-var = 65,underline 9 | exec-descriptor = yellow,bold 10 | comment = black,bold 11 | correct-subtle = bg:55 12 | incorrect-subtle = bg:52 13 | subtle-bg = bg:18 14 | secondary = zdharma 15 | recursive-base = 183 16 | 17 | [command-point] 18 | reserved-word = 186 19 | subcommand = 186 20 | alias = 101 21 | suffix-alias = 101 22 | global-alias = bg:55 23 | builtin = 101 24 | function = 101 25 | command = 101 26 | precommand = 101 27 | hashed-command = 101 28 | single-sq-bracket = 101 29 | double-sq-bracket = 101 30 | double-paren = 186 31 | 32 | [paths] 33 | path = 107 34 | pathseparator = 35 | path-to-dir = 107,underline 36 | globbing = 114 37 | globbing-ext = 118 38 | 39 | [brackets] 40 | paired-bracket = bg:blue 41 | bracket-level-1 = green,bold 42 | bracket-level-2 = yellow,bold 43 | bracket-level-3 = cyan,bold 44 | 45 | [arguments] 46 | single-hyphen-option = 65 47 | double-hyphen-option = 65 48 | back-quoted-argument = none 49 | single-quoted-argument = 186 50 | double-quoted-argument = 186 51 | dollar-quoted-argument = 186 52 | 53 | [in-string] 54 | ; backslash in $'...' 55 | back-dollar-quoted-argument = 65 56 | ; backslash or $... in "..." 57 | back-or-dollar-double-quoted-argument = 65 58 | 59 | [other] 60 | variable = none 61 | assign = none 62 | assign-array-bracket = 101 63 | history-expansion = 114 64 | 65 | [math] 66 | mathvar = 114 67 | mathnum = 107 68 | matherr = 124 69 | 70 | [for-loop] 71 | forvar = none 72 | fornum = 107 73 | ; operator 74 | foroper = 186 75 | ; separator 76 | forsep = 109 77 | 78 | [case] 79 | case-input = 101 80 | case-parentheses = 65 81 | case-condition = underline 82 | -------------------------------------------------------------------------------- /themes/clean.ini: -------------------------------------------------------------------------------- 1 | [base] 2 | default = none 3 | unknown-token = 124,bold 4 | commandseparator = none 5 | redirection = none 6 | here-string-tri = yellow 7 | here-string-text = bg:19 8 | here-string-var = 185,bg:19 9 | exec-descriptor = yellow,bold 10 | comment = black,bold 11 | correct-subtle = bg:55 12 | incorrect-subtle = bg:52 13 | subtle-bg = bg:17 14 | secondary = zdharma 15 | recursive-base = 183 16 | 17 | [command-point] 18 | reserved-word = 146 19 | subcommand = 146 20 | alias = 109 21 | suffix-alias = 109 22 | global-alias = bg:19 23 | builtin = 109 24 | function = 109 25 | command = 109 26 | precommand = 109 27 | hashed-command = 109 28 | single-sq-bracket = 109 29 | double-sq-bracket = 109 30 | double-paren = 146 31 | 32 | [paths] 33 | path = 208 34 | pathseparator = 35 | path-to-dir = 208,underline 36 | globbing = 220 37 | globbing-ext = 225 38 | 39 | [brackets] 40 | paired-bracket = bg:blue 41 | bracket-level-1 = 115 42 | bracket-level-2 = 177 43 | bracket-level-3 = 220 44 | 45 | [arguments] 46 | single-hyphen-option = 185 47 | double-hyphen-option = 185 48 | back-quoted-argument = none 49 | single-quoted-argument = 147 50 | double-quoted-argument = 147 51 | dollar-quoted-argument = 147 52 | 53 | [in-string] 54 | ; backslash in $'...' 55 | back-dollar-quoted-argument = 185 56 | ; backslash or $... in "..." (i.e. variable in string) 57 | back-or-dollar-double-quoted-argument = 185 58 | 59 | [other] 60 | variable = none 61 | assign = none 62 | assign-array-bracket = 109 63 | history-expansion = blue,bold 64 | 65 | [math] 66 | mathvar = blue,bold 67 | mathnum = 208 68 | matherr = 124 69 | 70 | [for-loop] 71 | forvar = none 72 | fornum = 208 73 | ; operator 74 | foroper = 147 75 | ; separator 76 | forsep = 109 77 | 78 | [case] 79 | case-input = 109 80 | case-parentheses = 116 81 | case-condition = bg:19 82 | -------------------------------------------------------------------------------- /themes/free.ini: -------------------------------------------------------------------------------- 1 | [base] 2 | default = none 3 | unknown-token = red,bold 4 | commandseparator = none 5 | redirection = none 6 | here-string-tri = yellow 7 | here-string-text = bg:19 8 | here-string-var = 110,bg:19 9 | exec-descriptor = yellow,bold 10 | comment = black,bold 11 | correct-subtle = bg:55 12 | incorrect-subtle = bg:52 13 | subtle-bg = bg:18 14 | secondary = zdharma 15 | recursive-base = 183 16 | 17 | [command-point] 18 | reserved-word = 150 19 | subcommand = 150 20 | alias = 180 21 | suffix-alias = 180 22 | global-alias = bg:19 23 | builtin = 180 24 | function = 180 25 | command = 180 26 | precommand = 180 27 | hashed-command = 180 28 | single-sq-bracket = 180 29 | double-sq-bracket = 180 30 | double-paren = 150 31 | 32 | [paths] 33 | path = 166 34 | pathseparator = 35 | path-to-dir = 166,underline 36 | globbing = 112 37 | globbing-ext = 118 38 | 39 | [brackets] 40 | paired-bracket = bg:blue 41 | bracket-level-1 = 130 42 | bracket-level-2 = 70 43 | bracket-level-3 = 69 44 | 45 | [arguments] 46 | single-hyphen-option = 110 47 | double-hyphen-option = 110 48 | back-quoted-argument = none 49 | single-quoted-argument = 150 50 | double-quoted-argument = 150 51 | dollar-quoted-argument = 150 52 | 53 | [in-string] 54 | ; backslash in $'...' 55 | back-dollar-quoted-argument = 110 56 | ; backslash or $... in "..." (i.e. variable inside a string) 57 | back-or-dollar-double-quoted-argument = 110 58 | 59 | [other] 60 | variable = none 61 | assign = none 62 | assign-array-bracket = 180 63 | history-expansion = blue,bold 64 | 65 | [math] 66 | mathvar = blue,bold 67 | mathnum = 166 68 | matherr = red 69 | 70 | [for-loop] 71 | forvar = none 72 | fornum = 150 73 | ; operator 74 | foroper = 150 75 | ; separator 76 | forsep = 109 77 | 78 | [case] 79 | case-input = 180 80 | case-parentheses = 116 81 | case-condition = bg:19 82 | -------------------------------------------------------------------------------- /functions/_fast-theme: -------------------------------------------------------------------------------- 1 | #compdef fast-theme 2 | #---------------------------------------------------------------------------------------------------------------------- 3 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 4 | # vim: ft=zsh sw=2 ts=2 et 5 | #---------------------------------------------------------------------------------------------------------------------- 6 | # 7 | # Copyright (c) 2018 Sebastian Gniazdowski 8 | # Copyright (c) 2022-present, Z-Shell Community 9 | # 10 | # Completion for theme-switching function, fast-theme, 11 | # part of z-shell/F-Sy-H, zdharma/fast-syntax-highlighting. 12 | 13 | builtin emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace} 14 | builtin setopt extended_glob local_options typeset_silent no_short_loops rc_quotes no_auto_pushd 15 | 16 | typeset -a themes themes2 arguments expl 17 | 18 | arguments=( 19 | {-w,--workdir}'[cd into $FAST_WORK_DIR (if not set, then into the plugin directory)]' 20 | {-R,--ov-reset}'[unset overlay, use styles only from main-theme (requires restart)]' 21 | {-p,--palette}'[just print all 256 colors and exit (useful when creating a theme)]' 22 | {-r,--reset}'[unset any theme (revert to default highlighting)]' 23 | {-t,--test}'[test theme after setting it (show example code)]' 24 | {-s,--show}'[get and display the theme currently being set]' 25 | {-v,--verbose}'[more messages during operation]' 26 | {-i,--info}'[additional information]' 27 | {-l,--list}'[list available themes]' 28 | {-q,--quiet}'[no default messages]' 29 | {-h,--help}'[display help text]' 30 | ) 31 | 32 | integer ret=1 33 | themes=( "$FAST_BASE_DIR"/themes/*.ini(:t:r) ) 34 | 35 | if [[ -d ${XDG_CONFIG_HOME:-$HOME/.config}/f-sy-h ]]; then 36 | themes2=( "${XDG_CONFIG_HOME:-$HOME/.config}"/f-sy-h/*.ini(:t:r) ) 37 | themes+=( CONFIG:${^themes2[@]} ) 38 | fi 39 | 40 | _wanted themes expl "themes" compadd "$@" -a - themes && ret=0 41 | _arguments -s $arguments && ret=0 42 | 43 | return $ret 44 | -------------------------------------------------------------------------------- /themes/spa.ini: -------------------------------------------------------------------------------- 1 | ; 144, 187, 110, 203 2 | [base] 3 | default = none 4 | unknown-token = 196 5 | commandseparator = 150 6 | redirection = none 7 | here-string-tri = yellow 8 | here-string-text = bg:19 9 | here-string-var = 186,bg:19 10 | exec-descriptor = yellow,bold 11 | comment = black,bold 12 | correct-subtle = bg:55 13 | incorrect-subtle = bg:52 14 | subtle-bg = bg:17 15 | secondary = zdharma 16 | recursive-base = 183 17 | 18 | [command-point] 19 | reserved-word = 144 20 | subcommand = 144 21 | alias = 187 22 | suffix-alias = 187 23 | global-alias = bg:19 24 | builtin = 150 25 | function = 187 26 | command = 187 27 | precommand = 187 28 | hashed-command = 187 29 | single-sq-bracket = 150 30 | double-sq-bracket = 150 31 | double-paren = 144 32 | 33 | [paths] 34 | path = 110 35 | pathseparator = 36 | path-to-dir = 110,underline 37 | globbing = 220 38 | globbing-ext = 225 39 | 40 | [brackets] 41 | paired-bracket = bg:blue 42 | bracket-level-1 = 115 43 | bracket-level-2 = 177 44 | bracket-level-3 = 220 45 | 46 | [arguments] 47 | single-hyphen-option = 185 48 | double-hyphen-option = 185 49 | back-quoted-argument = none 50 | single-quoted-argument = 110 51 | double-quoted-argument = 110 52 | dollar-quoted-argument = 110 53 | 54 | [in-string] 55 | ; backslash in $'...' 56 | back-dollar-quoted-argument = 186 57 | ; backslash or $... in "..." (i.e. variable in string) 58 | back-or-dollar-double-quoted-argument = 186 59 | 60 | [other] 61 | variable = none 62 | assign = none 63 | assign-array-bracket = 187 64 | history-expansion = blue,bold 65 | 66 | [math] 67 | mathvar = 150 68 | mathnum = 110 69 | matherr = 196 70 | 71 | [for-loop] 72 | forvar = 71 73 | fornum = 110 74 | ; operator 75 | foroper = 203 76 | ; separator 77 | forsep = 147 78 | 79 | [case] 80 | case-input = 187 81 | case-parentheses = 116 82 | case-condition = bg:19 83 | -------------------------------------------------------------------------------- /themes/safari.ini: -------------------------------------------------------------------------------- 1 | ; Light theme with colors of a Sahara oasis 2 | 3 | [base] 4 | default = none 5 | unknown-token = red,bold 6 | commandseparator = none 7 | redirection = none 8 | here-string-tri = yellow 9 | here-string-text = bg:19 10 | here-string-var = 153,bg:19 11 | exec-descriptor = yellow,bold 12 | comment = black,bold 13 | correct-subtle = bg:55 14 | incorrect-subtle = bg:52 15 | subtle-bg = bg:18 16 | secondary = zdharma 17 | recursive-base = 183 18 | 19 | [command-point] 20 | reserved-word = 150 21 | subcommand = 150 22 | alias = 185 23 | suffix-alias = 185 24 | global-alias = bg:19 25 | builtin = 185 26 | function = 185 27 | command = 185 28 | precommand = 185 29 | hashed-command = 185 30 | single-sq-bracket = 185 31 | double-sq-bracket = 185 32 | double-paren = 150 33 | 34 | [paths] 35 | path = 187 36 | pathseparator = 37 | path-to-dir = 187,underline 38 | globbing = 180 39 | globbing-ext = 184 40 | 41 | [brackets] 42 | paired-bracket = bg:blue 43 | bracket-level-1 = 178 44 | bracket-level-2 = 148 45 | bracket-level-3 = 141 46 | 47 | [arguments] 48 | single-hyphen-option = 152 49 | double-hyphen-option = 152 50 | back-quoted-argument = none 51 | single-quoted-argument = 151 52 | double-quoted-argument = 151 53 | dollar-quoted-argument = 151 54 | 55 | [in-string] 56 | ; backslash in $'...' 57 | back-dollar-quoted-argument = 153 58 | ; backslash or $... in "..." (i.e. variable inside a string) 59 | back-or-dollar-double-quoted-argument = 153 60 | 61 | [other] 62 | variable = none 63 | assign = none 64 | assign-array-bracket = 185 65 | history-expansion = blue,bold 66 | 67 | [math] 68 | mathvar = blue,bold 69 | mathnum = 187 70 | matherr = red 71 | 72 | [for-loop] 73 | forvar = none 74 | fornum = 187 75 | ; operator 76 | foroper = 151 77 | ; separator 78 | forsep = 109 79 | 80 | [case] 81 | case-input = 185 82 | case-parentheses = 116 83 | case-condition = bg:19 84 | -------------------------------------------------------------------------------- /chroma/-vim.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # Chroma for vim, shows last opened files under prompt. 5 | # 6 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 7 | # 8 | # $2 - the current token, also accessible by $__arg from the above scope - 9 | # basically a private copy of $__arg; the token can be eg.: "grep" 10 | # 11 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 12 | # command line buffer, used to add region_highlight entry (see man), 13 | # because Zsh colorizes by *ranges* in command line buffer 14 | # 15 | # $4 - a private copy of $_end_pos from the above scope 16 | # 17 | 18 | (( next_word = 2 | 8192 )) 19 | 20 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 21 | local __style __chars 22 | integer __idx1 __idx2 23 | local -a __viminfo 24 | 25 | # First call, i.e. command starts, i.e. "grep" token etc. 26 | (( __first_call )) && { 27 | (( ${+commands[vim]} )) && __style=${FAST_THEME_NAME}command || __style=${FAST_THEME_NAME}unknown-token 28 | 29 | { __viminfo=( ${(f)"$(<$HOME/.viminfo)"} ); } >> /dev/null 30 | __viminfo=( "${${(M)__viminfo[@]:#>*}[@]:t}" ) 31 | __viminfo=( "${__viminfo[@]:#COMMIT_EDITMSG}" ) 32 | zle -M "Last opened:"$'\n'"${(F)__viminfo[1,5]}" 33 | } || { 34 | # Pass almost everything to big loop 35 | return 1 36 | } 37 | 38 | # Add region_highlight entry (via `reply' array). 39 | # 40 | # This is a common place of adding such entry, but any above 41 | # code can do it itself (and it does, see other chromas) and 42 | # skip setting __style to disable this code. 43 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 44 | 45 | # We aren't passing-through (no return 1 occurred), do obligatory things ourselves. 46 | (( this_word = next_word )) 47 | _start_pos=$_end_pos 48 | 49 | return 0 50 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/03_codebase_improvement.yml: -------------------------------------------------------------------------------- 1 | name: "✨ Codebase improvement" 2 | description: Suggest a better solution for algorithms, annexea, packages, development tools, etc. 3 | title: "[dev]: " 4 | labels: ["enhancement ✨"] 5 | body: 6 | - type: textarea 7 | id: enhancement 8 | attributes: 9 | label: "Your feedback for the existing codebase" 10 | validations: 11 | required: false 12 | - type: markdown 13 | attributes: 14 | value: | 15 | First off, thanks for taking the time to contribute! 16 | Contributions are what make the open-source community such an amazing place to learn, inspire, and create. 17 | Any contributions you make will benefit everybody else and are greatly appreciated. 18 | - type: checkboxes 19 | attributes: 20 | label: Self-service 21 | description: | 22 | If you feel like you could contribute to this issue, please check the box below. This would tell us and other people looking for contributions that someone's working on it. 23 | If you do check this box, please send a pull request within 7 days so we can still delegate this to someone else. 24 | options: 25 | - label: I'd be willing to address this documentation request myself. 26 | - type: checkboxes 27 | attributes: 28 | label: Have you read the Contributing Guidelines? 29 | options: 30 | - label: I have read the [Contributing Guidelines](https://github.com/z-shell/community/blob/main/docs/CONTRIBUTING_GUIDELINES.md). 31 | required: true 32 | - type: checkboxes 33 | attributes: 34 | label: Are you familiar with Contributor Covenant Code of Conduct? 35 | options: 36 | - label: I have read the [Contributor Covenant Code of Conduct](https://github.com/z-shell/zi/blob/main/docs/CODE_OF_CONDUCT.md). 37 | required: true 38 | - type: input 39 | id: contact 40 | attributes: 41 | label: Contact Details 42 | description: How can we get in touch with you if we need more info? 43 | placeholder: ex. email@example.com 44 | validations: 45 | required: false 46 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Space or Tabs? 2 | # https://stackoverflow.com/questions/35649847/objective-reasons-for-using-spaces-instead-of-tabs-for-indentation 3 | # https://stackoverflow.com/questions/12093748/how-to-use-tabs-instead-of-spaces-in-a-shell-script 4 | # https://github.com/editorconfig/editorconfig-defaults/blob/master/editorconfig-defaults.json 5 | # 6 | # 1. What happens when I press the Tab key in my text editor? 7 | # 2. What happens when I request my editor to indent one or more lines? 8 | # 3. What happens when I view a file containing U+0009 HORIZONTAL TAB characters? 9 | # 10 | # Answers: 11 | # 12 | # 1. Pressing the Tab key should indent the current line (or selected lines) one additional level. 13 | # 2. As a secondary alternative, I can also tolerate an editor that, 14 | # like Emacs, uses this key for a context-sensitive fix-my-indentation command. 15 | # 3. Indenting one or more lines should follow the reigning convention, if consensus is sufficiently strong; otherwise, 16 | # I greatly prefer 2-space indentation at each level. U+0009 characters should shift subsequent characters to the next tab stop. 17 | # 18 | # Note: VIM users should use alternate marks [[[ and ]]] as the original ones can confuse nested substitutions, e.g.: ${${${VAR}}} 19 | # 20 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 21 | # vim: ft=zsh sw=2 ts=2 et 22 | 23 | root = true 24 | 25 | [*] 26 | charset = utf-8 27 | indent_style = space 28 | indent_size = 2 29 | insert_final_newline = true 30 | trim_trailing_whitespace = true 31 | 32 | [*.sln] 33 | indent_style = tab 34 | 35 | [*.{md,mdx,rst}] 36 | trim_trailing_whitespace = false 37 | 38 | [*.{cmd,bat}] 39 | end_of_line = crlf 40 | 41 | [*za-*] 42 | end_of_line = lf 43 | 44 | [*.{sh,bash,zsh,fish}] 45 | end_of_line = lf 46 | 47 | [Makefile] 48 | indent_style = tab 49 | indent_size = 4 50 | 51 | [*.{py,rb}] 52 | indent_size = 4 53 | 54 | [*.{go,java,scala,groovy,kotlin}] 55 | indent_style = tab 56 | indent_size = 4 57 | 58 | [*.{cs,csx,cake,vb,vbx}] 59 | # Default Severity for all .NET Code Style rules below 60 | dotnet_analyzer_diagnostic.severity = warning 61 | -------------------------------------------------------------------------------- /themes/default.ini: -------------------------------------------------------------------------------- 1 | ; default theme, also embedded in the source of fast-syntax-highlighting 2 | 3 | [base] 4 | default = none 5 | unknown-token = red,bold 6 | commandseparator = none 7 | redirection = none 8 | here-string-tri = yellow 9 | here-string-text = 18 10 | here-string-var = cyan,bg:18 11 | exec-descriptor = yellow,bold 12 | comment = black,bold 13 | correct-subtle = 12 14 | incorrect-subtle = red 15 | subtle-separator = green 16 | subtle-bg = bg:18 17 | secondary = free 18 | ; recursive-base = 19 | 20 | [command-point] 21 | reserved-word = yellow 22 | subcommand = yellow 23 | alias = green 24 | suffix-alias = green 25 | global-alias = bg:blue 26 | builtin = green 27 | function = green 28 | command = green 29 | precommand = green 30 | hashed-command = green 31 | single-sq-bracket = green 32 | double-sq-bracket = green 33 | double-paren = yellow 34 | 35 | [paths] 36 | path = magenta 37 | pathseparator = 38 | path-to-dir = magenta,underline 39 | globbing = blue,bold 40 | globbing-ext = 13 41 | 42 | [brackets] 43 | paired-bracket = bg:blue 44 | bracket-level-1 = green,bold 45 | bracket-level-2 = yellow,bold 46 | bracket-level-3 = cyan,bold 47 | 48 | [arguments] 49 | single-hyphen-option = cyan 50 | double-hyphen-option = cyan 51 | back-quoted-argument = none 52 | single-quoted-argument = yellow 53 | double-quoted-argument = yellow 54 | dollar-quoted-argument = yellow 55 | 56 | [in-string] 57 | ; backslash in $'...' 58 | back-dollar-quoted-argument = cyan 59 | ; backslash or $... in "..." 60 | back-or-dollar-double-quoted-argument = cyan 61 | 62 | [other] 63 | variable = 113 64 | assign = none 65 | assign-array-bracket = green 66 | history-expansion = blue,bold 67 | 68 | [math] 69 | mathvar = blue,bold 70 | mathnum = magenta 71 | matherr = red 72 | 73 | [for-loop] 74 | forvar = none 75 | fornum = magenta 76 | ; operator 77 | foroper = yellow 78 | ; separator 79 | forsep = yellow,bold 80 | 81 | [case] 82 | case-input = green 83 | case-parentheses = yellow 84 | case-condition = bg:blue 85 | -------------------------------------------------------------------------------- /.github/workflows/zunit.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🛡️ ZUnit 3 | 4 | on: 5 | workflow_dispatch: 6 | push: 7 | paths: 8 | - "**/*.ch" 9 | - "**/*.zsh" 10 | - "tests/*" 11 | - "share/*" 12 | - "themes/*" 13 | - "functions/*" 14 | pull_request_target: 15 | paths: 16 | - "**/*.ch" 17 | - "**/*.zsh" 18 | - "tests/*" 19 | - "share/*" 20 | - "themes/*" 21 | - "functions/*" 22 | 23 | jobs: 24 | build-macos: 25 | name: 🧪 ZUnit Mac 26 | runs-on: macos-latest 27 | steps: 28 | - uses: actions/checkout@v4 29 | - name: 📚 Get ZUnit 30 | run: | 31 | mkdir bin 32 | curl -fsSL https://raw.githubusercontent.com/zdharma/revolver/13e7af7ee037b6db0a598a4e54242dd9c63a4c45/revolver > bin/revolver 33 | curl -fsSL https://raw.githubusercontent.com/zdharma/color/d8f91ab5fcfceb623ae45d3333ad0e543775549c/color.zsh > bin/color 34 | git clone https://github.com/zdharma/zunit.git zunit.git 35 | cd zunit.git 36 | ./build.zsh 37 | cd .. 38 | mv ./zunit.git/zunit bin 39 | chmod u+x bin/{color,revolver,zunit} 40 | - name: ✏️ Run 41 | run: | 42 | export TERM="xterm-256color" 43 | export PATH="$PWD/bin:$PATH" 44 | zunit 45 | 46 | build-linux: 47 | name: 🧪 ZUnit Linux 48 | runs-on: ubuntu-latest 49 | steps: 50 | - uses: actions/checkout@v4 51 | - name: ℹ️ Setup linux dependencies 52 | run: | 53 | sudo apt update 54 | sudo apt-get install zsh -yq 55 | - name: 📚 Get ZUnit 56 | run: | 57 | mkdir bin 58 | curl -fsSL https://raw.githubusercontent.com/zdharma/revolver/13e7af7ee037b6db0a598a4e54242dd9c63a4c45/revolver > bin/revolver 59 | curl -fsSL https://raw.githubusercontent.com/zdharma/color/d8f91ab5fcfceb623ae45d3333ad0e543775549c/color.zsh > bin/color 60 | git clone https://github.com/zdharma/zunit.git zunit.git 61 | cd zunit.git 62 | ./build.zsh 63 | cd .. 64 | mv ./zunit.git/zunit bin 65 | chmod u+x bin/{color,revolver,zunit} 66 | - name: ✏️ Run 67 | run: | 68 | export TERM="xterm-256color" 69 | export PATH="$PWD/bin:$PATH" 70 | zunit 71 | -------------------------------------------------------------------------------- /chroma/-fpath_peq.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # This chroma does a narrow, obscure but prestigious parsing of fpath+=( elem1 5 | # elem2 ... ) construct to provide *the* *future* contents of $fpath to 6 | # -autoload.ch, so that it can detect functions in those provided directories 7 | # `elem1', `elem2', etc. and highlight the functions with `correct-subtle' 8 | # instead of `incorrect-subtle'. Basically all this is for command-lines like: 9 | # 10 | # % fpath+=( `pwd` ); autoload my-fun-from-PWD 11 | 12 | # Keep chroma-takeover state meaning: until ; or similar (see $__arg_type below) 13 | # The 8192 sum takes care that the next token will be routed to this chroma 14 | (( next_word = 2 | 8192 )) 15 | 16 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 17 | local -a deserialized 18 | 19 | (( __first_call )) && { 20 | case $__wrd in 21 | (fpath=\() 22 | FAST_HIGHLIGHT[fpath_peq_mode]=1 23 | ;; 24 | (fpath+=\() 25 | FAST_HIGHLIGHT[fpath_peq_mode]=2 26 | ;; 27 | (FPATH=) 28 | FAST_HIGHLIGHT[fpath_peq_mode]=4 29 | ;; 30 | (FPATH+=) 31 | FAST_HIGHLIGHT[fpath_peq_mode]=8 32 | ;; 33 | esac 34 | if (( FAST_HIGHLIGHT[fpath_peq_mode] & 5 )); then 35 | FAST_HIGHLIGHT[chroma-fpath_peq-elements]="! ${FAST_HIGHLIGHT[chroma-fpath_peq-elements]}" 36 | fi 37 | return 1 38 | } || { 39 | # Following call, i.e. not the first one 40 | 41 | # Check if chroma should end – test if token is of type 42 | # "starts new command", if so pass-through – chroma ends 43 | [[ "$__arg_type" = 3 ]] && return 2 44 | 45 | [[ "$__wrd" != ")" ]] && { 46 | deserialized=( "${(Q@)${(z@)FAST_HIGHLIGHT[chroma-fpath_peq-elements]}}" ) 47 | [[ -z "${deserialized[1]}" && ${#deserialized} -eq 1 ]] && deserialized=() 48 | # Support ~ and $VAR, for [a-zA-Z_][a-ZA-Z0-9_]# characters in "VAR" 49 | deserialized+=( "${(Q)${${(j: :)__wrd}//(#b)((\$([0-9]##|[a-zA-Z_][a-zA-Z0-9_]#))|(\$\{([0-9]##|[a-zA-Z_][a-zA-Z0-9_]#)\})|(#s)~)/${(P)${${${${match[1]##\$\{(#c0,1)}%\}}:#\~}:-HOME}}}}" ) 50 | FAST_HIGHLIGHT[chroma-fpath_peq-elements]="${(j: :)${(q@)deserialized}}" 51 | } 52 | 53 | return 1 54 | } 55 | 56 | (( this_word = next_word )) 57 | _start_pos=$_end_pos 58 | 59 | return 0 60 | -------------------------------------------------------------------------------- /themes/sv-plant.ini: -------------------------------------------------------------------------------- 1 | ; https://www.syntaxenvy.com/0854668 2 | ; 3 | ; comment: 4 | ; #5b4e3f -> 58 5 | ; keyword: 6 | ; #a1f2b2 -> 157 7 | ; number, string: 8 | ; #91cf9e -> 115 (114) 9 | ; title, section, name, selector-id: 10 | ; #dadff0 -> 189 11 | ; attribute, variable, type: 12 | ; #debb91 -> 180 13 | ; symbol, link: 14 | ; #f1dcc6 -> 224 15 | ; builtin, deletion: 16 | ; #95cbc1 -> 115 17 | ; formula: 18 | ; #3f352a -> 16 19 | 20 | [base] 21 | default = none 22 | unknown-token = 124 23 | commandseparator = 189 24 | redirection = none 25 | here-string-tri = 157 26 | here-string-text = bg:25 27 | here-string-var = 180,bg:25 28 | exec-descriptor = 180 29 | comment = 58 30 | correct-subtle = bg:55 31 | incorrect-subtle = bg:52 32 | subtle-bg = bg:17 33 | secondary = zdharma 34 | recursive-base = 183 35 | 36 | [command-point] 37 | reserved-word = 157 38 | subcommand = 224 39 | alias = 180 40 | suffix-alias = 180 41 | global-alias = bg:58 42 | builtin = 115 43 | function = 180 44 | command = 180 45 | precommand = 157 46 | hashed-command = 180 47 | single-sq-bracket = 115 48 | double-sq-bracket = 115 49 | double-paren = 157 50 | 51 | [paths] 52 | path = 224 53 | pathseparator = 54 | path-to-dir = 224,underline 55 | globbing = 157 56 | globbing-ext = 159 57 | 58 | [brackets] 59 | paired-bracket = bg:blue 60 | bracket-level-1 = 115 61 | bracket-level-2 = 177 62 | bracket-level-3 = 220 63 | 64 | [arguments] 65 | single-hyphen-option = 180 66 | double-hyphen-option = 180 67 | back-quoted-argument = none 68 | single-quoted-argument = 114 69 | double-quoted-argument = 114 70 | dollar-quoted-argument = 114 71 | 72 | [in-string] 73 | ; backslash in $'...' 74 | back-dollar-quoted-argument = 189 75 | ; backslash or $... in "..." (i.e. variable in string) 76 | back-or-dollar-double-quoted-argument = 180 77 | 78 | [other] 79 | variable = none 80 | assign = none 81 | assign-array-bracket = 224 82 | history-expansion = blue,bold 83 | 84 | [math] 85 | mathvar = 180 86 | mathnum = 114 87 | matherr = 124 88 | 89 | [for-loop] 90 | forvar = 180 91 | fornum = 114 92 | ; operator 93 | foroper = 147 94 | ; separator 95 | forsep = 224 96 | 97 | [case] 98 | case-input = 180 99 | case-parentheses = 58 100 | case-condition = bg:25 101 | -------------------------------------------------------------------------------- /themes/sv-orple.ini: -------------------------------------------------------------------------------- 1 | ; https://www.syntaxenvy.com/0073437 2 | ; 3 | ; comment: 4 | ; #363355 -> 61 5 | ; keyword: 6 | ; #dda69f -> 181 (138) 7 | ; number, string: 8 | ; #ca887e -> 174 (173) 9 | ; title, section, name, selector-id: 10 | ; #b3afd9 -> 146 (146) 11 | ; attribute, variable, type: 12 | ; #be85c0 -> 139 (140) 13 | ; symbol, link: 14 | ; #d6a2d8 -> 182 (182) 15 | ; builtin, deletion: 16 | ; #969c77 -> 108 (108) 17 | ; formula-bg: 18 | ; #211f37 -> 16 (17) 19 | 20 | [base] 21 | default = none 22 | unknown-token = 124 23 | commandseparator = 146 24 | redirection = none 25 | here-string-tri = 138 26 | here-string-text = bg:25 27 | here-string-var = 140,bg:25 28 | exec-descriptor = 140 29 | comment = 61 30 | correct-subtle = bg:55 31 | incorrect-subtle = bg:52 32 | subtle-bg = bg:17 33 | secondary = clean 34 | recursive-base = 186 35 | 36 | [command-point] 37 | reserved-word = 138 38 | subcommand = 182 39 | alias = 140 40 | suffix-alias = 140 41 | global-alias = bg:17 42 | builtin = 173 43 | function = 140 44 | command = 108 45 | precommand = 138 46 | hashed-command = 140 47 | single-sq-bracket = 173 48 | double-sq-bracket = 173 49 | double-paren = 138 50 | 51 | [paths] 52 | path = 182 53 | pathseparator = 54 | path-to-dir = 182,underline 55 | globbing = 138 56 | globbing-ext = 141 57 | 58 | [brackets] 59 | paired-bracket = bg:blue 60 | bracket-level-1 = 173 61 | bracket-level-2 = 177 62 | bracket-level-3 = 220 63 | 64 | [arguments] 65 | single-hyphen-option = 140 66 | double-hyphen-option = 140 67 | back-quoted-argument = none 68 | single-quoted-argument = 173 69 | double-quoted-argument = 173 70 | dollar-quoted-argument = 173 71 | 72 | [in-string] 73 | ; backslash in $'...' 74 | back-dollar-quoted-argument = 146 75 | ; backslash or $... in "..." (i.e. variable in string) 76 | back-or-dollar-double-quoted-argument = 140 77 | 78 | [other] 79 | variable = none 80 | assign = none 81 | assign-array-bracket = 182 82 | history-expansion = blue,bold 83 | 84 | [math] 85 | mathvar = 140 86 | mathnum = 173 87 | matherr = 124 88 | 89 | [for-loop] 90 | forvar = 140 91 | fornum = 173 92 | ; operator 93 | foroper = 147 94 | ; separator 95 | forsep = 182 96 | 97 | [case] 98 | case-input = 140 99 | case-parentheses = 17 100 | case-condition = bg:25 101 | -------------------------------------------------------------------------------- /functions/.fast-run-git-command: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # Copyright (c) 2018 Sebastian Gniazdowski 5 | # 6 | # It runs given command, which in general will be a git command, 7 | # automatically looking at cache first (a field named *-cache, 8 | # in FAST_HIGHLIGHT), which is valid for 5 seconds, and in case 9 | # of outdated or not existing cache, runs the command, splitting 10 | # on new-lines, first checking if PWD is inside git repository. 11 | # 12 | # FAST_HIGHLIGHT hash serves as container for variables that 13 | # prevents creating them in global scope. (P) flag is not used, 14 | # output array is fixed (__lines_list). 15 | # 16 | # $1 - the command, e.g. "git remote"; 2>/dev/null redirection is 17 | # added automatically 18 | # $2 - FAST_HIGHLIGHT field name, e.g. "chroma-git-branches"; two 19 | # additional fields will be used, $2-cache, $2-cache-born-at 20 | # $3 - what to remove from beginning of the lines returned by the 21 | # command 22 | # $4 - cache validity time, default 5 (seconds) 23 | # 24 | # Output: array __lines_list, with output of the (git) command ran 25 | 26 | # User should not forget to define this array, the below code 27 | # will only ensure that it's array (can also define a global) 28 | typeset -ga __lines_list 29 | local -a __response 30 | 31 | if [[ $1 == --status ]] { 32 | integer __status=1 33 | shift 34 | } 35 | 36 | if [[ -z ${FAST_HIGHLIGHT[$2-cache]} || $(( EPOCHSECONDS - FAST_HIGHLIGHT[$2-cache-born-at] )) -gt ${4:-5} ]]; then 37 | FAST_HIGHLIGHT[$2-cache-born-at]=$EPOCHSECONDS 38 | if [[ "$(command git rev-parse --is-inside-work-tree 2>/dev/null)" = true ]]; then 39 | __response=( ${${(f)"$(command ${(Qz)${1#+}} 2>/dev/null)"}#$3} ) 40 | integer retval=$? 41 | if (( __status )) { 42 | __response=( $retval ) 43 | __lines_list=( $retval ) 44 | } else { 45 | [[ "$1" = "+"* ]] && \ 46 | __lines_list+=( "${__response[@]}" ) || __lines_list=( "${__response[@]}" ) 47 | } 48 | else 49 | __lines_list=() 50 | fi 51 | FAST_HIGHLIGHT[$2-cache]="${(j:;:)__response}" 52 | else 53 | # Quoted (s:;:) flag without @ will skip empty elements. It 54 | # still produces array output, interestingly. All this is for 55 | # the trailing ";" above, to skip last, empty element. 56 | [[ "$1" = "+"* ]] && __lines_list+=( "${(@s:;:)FAST_HIGHLIGHT[$2-cache]}" ) || \ 57 | __lines_list=( "${(@s:;:)FAST_HIGHLIGHT[$2-cache]}" ) 58 | fi 59 | 60 | return 0 61 | -------------------------------------------------------------------------------- /chroma/-nmcli.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | 4 | (( next_word = 2 | 8192 )) 5 | [[ "$__arg_type" = 3 ]] && return 2 6 | 7 | typeset -A subcommands 8 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" subcommand 9 | subcommands=( 10 | help "_" 11 | general "help status hostname permissions logging _" 12 | networking "help on off connectivity _" 13 | radio "help all wifi wwan _" 14 | connection "help show up down add modify clone edit delete monitor reload load import export _" 15 | device "help status show set connect reapply modify disconnect delete monitor wifi lldp _" 16 | agent "help secret polkit all _" 17 | monitor "help _" 18 | _ "_" 19 | ) 20 | 21 | if (( __first_call )); then 22 | FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]="" 23 | FAST_HIGHLIGHT[chroma-nmcli-subcommand-b]="" 24 | return 1 25 | elif (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 26 | return 1 27 | elif [[ "$2" = -* ]]; then 28 | return 1 29 | elif [[ -z ${FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]} ]]; then 30 | for subcommand in ${(@k)subcommands}; do 31 | [[ $subcommand = $__wrd* ]] && break || subcommand="_" 32 | done 33 | if [[ $subcommand = _ ]]; then 34 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 35 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") 36 | else 37 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 38 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}") 39 | fi 40 | FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]="$subcommand" 41 | elif [[ -z ${FAST_HIGHLIGHT[chroma-nmcli-subcommand-b]} ]]; then 42 | for subcommand in ${(s. .)subcommands[${FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]}]}; do 43 | [[ "$subcommand" = $__wrd* ]] && break || subcommand="_" 44 | done 45 | if [[ $subcommand = _ ]]; then 46 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 47 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") 48 | else 49 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 50 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}") 51 | fi 52 | FAST_HIGHLIGHT[chroma-nmcli-subcommand-b]="$subcommand" 53 | else 54 | return 1 55 | fi 56 | 57 | (( this_word = next_word )) 58 | _start_pos=$_end_pos 59 | 60 | return 0 61 | -------------------------------------------------------------------------------- /chroma/-hub.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | 4 | (( next_word = 2 | 8192 )) 5 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 6 | 7 | if (( __first_call )); then 8 | chroma/-git.ch $* 9 | return 1 10 | fi 11 | [[ "$__arg_type" = 3 ]] && return 2 12 | 13 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 14 | return 1 15 | fi 16 | 17 | if [[ "$__wrd" != -* ]] && (( FAST_HIGHLIGHT[chroma-git-got-subcommand] == 0 )); then 18 | .fast-run-command "git config --get-regexp 'alias.*'" chroma-git-alias-list "" $(( 5 * 60 )) 19 | # Grep for line: alias.{user-entered-subcmd}[[:space:]], and remove alias. prefix 20 | __lines_list=( ${${(M)__lines_list[@]:#alias.${__wrd}[[:space:]]##*}#alias.} ) 21 | 22 | if (( ${#__lines_list} > 0 )); then 23 | # (*) 24 | # First remove alias name (#*[[:space:]]) and the space after it, then 25 | # remove any leading spaces from what's left (##[[:space:]]##), then 26 | # remove everything except the first word that's in the left line 27 | # (%%[[:space:]]##*, i.e.: "everything from right side up to any space") 28 | FAST_HIGHLIGHT[chroma-git-subcommand]="${${${__lines_list[1]#*[[:space:]]}##[[:space:]]##}%%[[:space:]]##*}" 29 | else 30 | FAST_HIGHLIGHT[chroma-git-subcommand]="$__wrd" 31 | fi 32 | if [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "browse" \ 33 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "ci-status" \ 34 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "compare" \ 35 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "create" \ 36 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "delete" \ 37 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "fork" \ 38 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "issue" \ 39 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "pr" \ 40 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "pull-request" \ 41 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "release" \ 42 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "sync" ]]; then 43 | FAST_HIGHLIGHT[chroma-git-got-subcommand]=1 44 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 45 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}") 46 | (( FAST_HIGHLIGHT[chroma-git-counter] += 1 )) 47 | (( this_word = next_word )) 48 | _start_pos=$4 49 | return 0 50 | fi 51 | fi 52 | 53 | chroma/-git.ch $* 54 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/02_feature_request.yml: -------------------------------------------------------------------------------- 1 | name: "💡 Feature request" 2 | description: Suggest an idea for this project 3 | title: "[feat]: " 4 | labels: ["feature-request 💡"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | First off, thanks for taking the time to contribute! Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and are greatly appreciated. 10 | - type: input 11 | id: description 12 | attributes: 13 | label: Feature description 14 | description: A clear and concise description of what the feature request is. Please include if your feature request is related to a problem 15 | validations: 16 | required: true 17 | - type: textarea 18 | id: code-snippet 19 | attributes: 20 | label: Related Code 21 | description: "If you are able to illustrate the bug or feature request with an example, please provide it here" 22 | validations: 23 | required: false 24 | - type: textarea 25 | id: additional 26 | attributes: 27 | label: Additional Context 28 | description: "List any other information that is relevant to your issue. Stack traces, related issues, suggestions on how to add, use case, Stack Overflow links, forum links, screenshots, OS if applicable, etc." 29 | validations: 30 | required: false 31 | - type: checkboxes 32 | attributes: 33 | label: Self-service 34 | description: | 35 | If you feel like you could contribute to this issue, please check the box below. This would tell us and other people looking for contributions that someone's working on it. 36 | If you do check this box, please send a pull request within 7 days so we can still delegate this to someone else. 37 | options: 38 | - label: I'd be willing to address this documentation request myself. 39 | - type: checkboxes 40 | attributes: 41 | label: Have you read the Contributing Guidelines? 42 | options: 43 | - label: I have read the [Contributing Guidelines](https://github.com/z-shell/community/blob/main/docs/CONTRIBUTING_GUIDELINES.md). 44 | required: true 45 | - type: checkboxes 46 | attributes: 47 | label: Are you familiar with Contributor Covenant Code of Conduct? 48 | options: 49 | - label: I have read the [Contributor Covenant Code of Conduct](https://github.com/z-shell/zi/blob/main/docs/CODE_OF_CONDUCT.md). 50 | required: true 51 | - type: input 52 | id: contact 53 | attributes: 54 | label: Contact Details 55 | description: How can we get in touch with you if we need more info? 56 | placeholder: ex. email@example.com 57 | validations: 58 | required: false 59 | -------------------------------------------------------------------------------- /chroma/-sh.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # 3 | # Chroma function for `sh' shell. It colorizes string passed with -c option. 4 | # 5 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 6 | # $2 - the current token, also accessible by $__arg from the above scope - 7 | # basically a private copy of $__arg 8 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 9 | # command line buffer, used to add region_highlight entry (see man), 10 | # because Zsh colorizes by *ranges* in command line buffer 11 | # $4 - a private copy of $_end_pos from the above scope 12 | # 13 | 14 | (( next_word = 2 | 8192 )) 15 | 16 | local __first_call=$1 __wrd=$2 __start_pos=$3 __end_pos=$4 17 | local __style 18 | integer __idx1 __idx2 19 | local -a __lines_list 20 | 21 | (( __first_call )) && { 22 | # Called for the first time - new command 23 | FAST_HIGHLIGHT[chrome-git-got-c]=0 24 | return 1 25 | } || { 26 | # Following call, i.e. not the first one 27 | 28 | # Check if chroma should end – test if token is of type 29 | # "starts new command", if so pass-through – chroma ends 30 | [[ $__arg_type = 3 ]] && return 2 31 | 32 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 33 | return 1 34 | fi 35 | 36 | __wrd=${${${(Q)__wrd}#[\"\']}%[\"\']} 37 | if [[ $__wrd = -* && $__wrd != -*c* ]]; then 38 | __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option} 39 | else 40 | if (( FAST_HIGHLIGHT[chrome-git-got-c] == 1 )); then 41 | for (( __idx1 = 1, __idx2 = 1; __idx2 <= __asize; ++ __idx1 )); do 42 | [[ ${__arg[__idx2]} = ${__wrd[__idx1]} ]] && break 43 | while [[ ${__arg[__idx2]} != ${__wrd[__idx1]} ]]; do 44 | (( ++ __idx2 )) 45 | (( __idx2 > __asize )) && { __idx2=0; break; } 46 | done 47 | (( __idx2 == 0 )) && break 48 | [[ ${__arg[__idx2]} = ${__wrd[__idx1]} ]] && break 49 | done 50 | 51 | FAST_HIGHLIGHT[chrome-git-got-c]=0 52 | (( _start_pos-__PBUFLEN >= 0 )) && \ 53 | -fast-highlight-process "$PREBUFFER" "${__wrd}" "$(( __start_pos + __idx2 - 1 ))" 54 | elif [[ $__wrd = -*c* ]]; then 55 | FAST_HIGHLIGHT[chrome-git-got-c]=1 56 | else 57 | return 1 58 | fi 59 | fi 60 | } 61 | 62 | # Add region_highlight entry (via `reply' array) 63 | [[ -n $__style ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 64 | 65 | # We aren't passing-through, do obligatory things ourselves 66 | (( this_word = next_word )) 67 | _start_pos=$_end_pos 68 | 69 | return 0 70 | 71 | # vim: ft=zsh sw=2 ts=2 et 72 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/04_documentation.yml: -------------------------------------------------------------------------------- 1 | name: "📚 Documentation" 2 | description: The issue request for changes indocumentation 3 | title: "[docs]: " 4 | labels: ["documentation 📝"] 5 | assignees: 6 | - ss-o 7 | body: 8 | - type: markdown 9 | attributes: 10 | value: | 11 | This template is strictly used for documentation requests, including: 12 | 13 | - Elaborating on a particular topic; 14 | - Updating external links; 15 | - Anything else that doesn't require touching the codebase itself. 16 | 17 | If you followed the documentation but things don't work, take some time to consider if it's the documentation or the code that's wrong. In the latter, prefer using the "bug" template. 18 | 19 | You may proceed directly to sending a pull request without filing this issue, and we can improve on your work. 20 | If you think some of the requirements above are not met, or if you are not able to contribute yourself, the issue is still welcomed. 21 | 22 | - type: textarea 23 | id: request-info 24 | attributes: 25 | label: Description 26 | description: Tell us, what can be done better or a clear and concise description of what the issue is. 27 | validations: 28 | required: true 29 | - type: dropdown 30 | id: ecosystem 31 | attributes: 32 | label: Select the area that is associated with this issue. 33 | multiple: true 34 | options: 35 | - ZI (this repository) 36 | - Annexes 37 | - Plugins 38 | - Packages 39 | - Other 40 | - type: checkboxes 41 | attributes: 42 | label: Self-service 43 | description: | 44 | If you feel like you could contribute to this issue, please check the box below. This would tell us and other people looking for contributions that someone's working on it. 45 | If you do check this box, please send a pull request within 7 days so we can still delegate this to someone else. 46 | options: 47 | - label: I'd be willing to address this documentation request myself. 48 | - type: checkboxes 49 | attributes: 50 | label: Have you read the Contributing Guidelines? 51 | options: 52 | - label: I have read the [Contributing Guidelines](https://github.com/z-shell/community/blob/main/docs/CONTRIBUTING_GUIDELINES.md). 53 | required: true 54 | - type: checkboxes 55 | attributes: 56 | label: Are you familiar with Contributor Covenant Code of Conduct? 57 | options: 58 | - label: I have read the [Contributor Covenant Code of Conduct](https://github.com/z-shell/zi/blob/main/docs/CODE_OF_CONDUCT.md). 59 | required: true 60 | - type: input 61 | id: contact 62 | attributes: 63 | label: Contact Details 64 | description: How can we get in touch with you if we need more info? 65 | placeholder: ex. email@example.com 66 | validations: 67 | required: false 68 | -------------------------------------------------------------------------------- /functions/.fast-make-targets: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # Almost all code borrowed from Zshell's _make function 5 | # 6 | # Copyright (c) 2018 Sebastian Gniazdowski 7 | 8 | local -a TARGETS 9 | 10 | .make-expandVars() { 11 | local open close var val front='' rest=$1 12 | 13 | while [[ $rest == (#b)[^$]#($)* ]]; do 14 | front=$front${rest[1,$mbegin[1]-1]} 15 | rest=${rest[$mbegin[1],-1]} 16 | case $rest[2] in 17 | ($) # '$$'. may not appear in target and variable's value 18 | front=$front\$\$ 19 | rest=${rest[3,-1]} 20 | continue 21 | ;; 22 | (\() # Variable of the form $(foobar) 23 | open='(' 24 | close=')' 25 | ;; 26 | ({) # ${foobar} 27 | open='{' 28 | close='}' 29 | ;; 30 | ([[:alpha:]]) # $foobar. This is exactly $(f)oobar. 31 | open='' 32 | close='' 33 | var=$rest[2] 34 | ;; 35 | (*) # bad parameter name 36 | print -- $front$rest 37 | return 1 38 | ;; 39 | esac 40 | 41 | if [[ -n $open ]]; then 42 | if [[ $rest == \$$open(#b)([[:alnum:]_]##)(#B)$close* ]]; then 43 | var=$match 44 | else # unmatched () or {}, or bad parameter name 45 | print -- $front$rest 46 | return 1 47 | fi 48 | fi 49 | 50 | val='' 51 | if [[ -n ${VAR_ARGS[(i)$var]} ]]; then 52 | val=${VAR_ARGS[$var]} 53 | else 54 | if [[ -n $opt_args[(I)(-e|--environment-overrides)] ]]; then 55 | if [[ $parameters[$var] == scalar-export* ]]; then 56 | val=${(P)var} 57 | elif [[ -n ${VARIABLES[(i)$var]} ]]; then 58 | val=${VARIABLES[$var]} 59 | fi 60 | else 61 | if [[ -n ${VARIABLES[(i)$var]} ]]; then 62 | val=${VARIABLES[$var]} 63 | elif [[ $parameters[$var] == scalar-export* ]]; then 64 | val=${(P)var} 65 | fi 66 | fi 67 | fi 68 | rest=${rest//\$$open$var$close/$val} 69 | done 70 | 71 | print -- ${front}${rest} 72 | } 73 | 74 | 75 | .make-parseMakefile () { 76 | local input var val target dep TAB=$'\t' tmp IFS= 77 | 78 | while read input 79 | do 80 | case "$input " in 81 | # TARGET: dependencies 82 | # TARGET1 TARGET2 TARGET3: dependencies 83 | ([[*?[:alnum:]$][^$TAB:=%]#:[^=]*) 84 | target=$(.make-expandVars ${input%%:*}) 85 | TARGETS+=( ${(z)target} ) 86 | ;; 87 | esac 88 | done 89 | } 90 | 91 | if [[ -z "${FAST_HIGHLIGHT[chroma-make-cache]}" || $(( EPOCHSECONDS - FAST_HIGHLIGHT[chroma-make-cache-born-at] )) -gt 7 ]]; then 92 | .make-parseMakefile 93 | FAST_HIGHLIGHT[chroma-make-cache-born-at]="$EPOCHSECONDS" 94 | FAST_HIGHLIGHT[chroma-make-cache]="${(j:;:)TARGETS}" 95 | fi 96 | 97 | reply2=( "${(s:;:)FAST_HIGHLIGHT[chroma-make-cache]}" ) 98 | -------------------------------------------------------------------------------- /chroma/-source.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # Chroma for `source' builtin - verifies if file to be sourced compiles 5 | # correctly. 6 | # 7 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 8 | # 9 | # $2 - the current token, also accessible by $__arg from the above scope - 10 | # basically a private copy of $__arg; the token can be eg.: "grep" 11 | # 12 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 13 | # command line buffer, used to add region_highlight entry (see man), 14 | # because Zsh colorizes by *ranges* in command line buffer 15 | # 16 | # $4 - a private copy of $_end_pos from the above scope 17 | # 18 | 19 | (( next_word = 2 | 8192 )) 20 | 21 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 22 | local __style __chars __home=$FAST_WORK_DIR 23 | integer __idx1 __idx2 24 | 25 | # First call, i.e. command starts, i.e. "grep" token etc. 26 | (( __first_call )) && { 27 | FAST_HIGHLIGHT[chroma-src-counter]=0 28 | __style=${FAST_THEME_NAME}builtin 29 | 30 | } || { 31 | 32 | # Following call, i.e. not the first one. 33 | # Check if chroma should end – test if token is of type 34 | # "starts new command", if so pass-through – chroma ends 35 | [[ "$__arg_type" = 3 ]] && return 2 36 | 37 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 38 | return 1 39 | fi 40 | 41 | if [[ "$__wrd" = -* ]]; then 42 | # Detected option, add style for it. 43 | [[ "$__wrd" = --* ]] && \ 44 | __style=${FAST_THEME_NAME}double-hyphen-option || __style=${FAST_THEME_NAME}single-hyphen-option 45 | else 46 | # Count non-option tokens. 47 | (( FAST_HIGHLIGHT[chroma-src-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-src-counter] )) 48 | if (( FAST_HIGHLIGHT[chroma-src-counter] == 1 )); then 49 | command mkdir -p "$__home" 50 | command cp -f "${__wrd}" "$__home" 2>/dev/null && { 51 | zcompile "$__home"/"${__wrd:t}" 2>/dev/null 1>&2 && \ 52 | __style=${FAST_THEME_NAME}correct-subtle || __style=${FAST_THEME_NAME}incorrect-subtle 53 | } 54 | elif (( FAST_HIGHLIGHT[chroma-src-counter] == 2 )); then 55 | # Handle paths, etc. normally - just pass-through to the big highlighter (the main f-sy-h highlighter, used before chromas). 56 | return 1 57 | fi 58 | fi 59 | } 60 | 61 | # Add region_highlight entry (via `reply' array). 62 | # 63 | # This is a common place of adding such entry, but any above 64 | # code can do it itself (and it does) and skip setting __style 65 | # to disable this code. 66 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 67 | 68 | # We aren't passing-through (no return 1 occurred), do obligatory things ourselves. 69 | (( this_word = next_word )) 70 | _start_pos=$_end_pos 71 | 72 | return 0 73 | -------------------------------------------------------------------------------- /chroma/-lab.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # The `lab' tool after which this chroma is modeled after: 5 | # https://github.com/zaquestion/lab 6 | # 7 | (( next_word = 2 | 8192 )) 8 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 9 | 10 | if (( __first_call )); then 11 | chroma/-git.ch $* 12 | return 1 13 | fi 14 | [[ "$__arg_type" = 3 ]] && return 2 15 | 16 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 17 | return 1 18 | fi 19 | 20 | if [[ "$__wrd" != -* ]] && (( FAST_HIGHLIGHT[chroma-git-got-subcommand] == 0 )); then 21 | .fast-run-command "git config --get-regexp 'alias.*'" chroma-git-alias-list "" $(( 5 * 60 )) 22 | # Grep for line: alias.{user-entered-subcmd}[[:space:]], and remove alias. prefix 23 | __lines_list=( ${${(M)__lines_list[@]:#alias.${__wrd}[[:space:]]##*}#alias.} ) 24 | 25 | if (( ${#__lines_list} > 0 )); then 26 | # (*) 27 | # First remove alias name (#*[[:space:]]) and the space after it, then 28 | # remove any leading spaces from what's left (##[[:space:]]##), then 29 | # remove everything except the first word that's in the left line 30 | # (%%[[:space:]]##*, i.e.: "everything from right side up to any space") 31 | FAST_HIGHLIGHT[chroma-git-subcommand]="${${${__lines_list[1]#*[[:space:]]}##[[:space:]]##}%%[[:space:]]##*}" 32 | else 33 | FAST_HIGHLIGHT[chroma-git-subcommand]="$__wrd" 34 | fi 35 | if [[ "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "browse" \ 36 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "ci" \ 37 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "mr" \ 38 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "project" \ 39 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "snippet" \ 40 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "ci-status" \ 41 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "compare" \ 42 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "create" \ 43 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "delete" \ 44 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "fork" \ 45 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "issue" \ 46 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "pr" \ 47 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "pull-request" \ 48 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "release" \ 49 | || "${FAST_HIGHLIGHT[chroma-git-subcommand]}" = "sync" ]]; then 50 | FAST_HIGHLIGHT[chroma-git-got-subcommand]=1 51 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 52 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}") 53 | (( FAST_HIGHLIGHT[chroma-git-counter] += 1 )) 54 | (( this_word = next_word )) 55 | _start_pos=$4 56 | return 0 57 | fi 58 | fi 59 | 60 | chroma/-git.ch $* 61 | -------------------------------------------------------------------------------- /docs/THEME_GUIDE.md: -------------------------------------------------------------------------------- 1 | # Theme Guide for F-Sy-H 2 | 3 | `fast-theme` tool is used to select a theme. There are 6 shipped themes, they can be listed with `fast-theme -l`. 4 | Themes are basic [INI files](https://github.com/z-shell/fast-syntax-highlighting/tree/main/themes) where each 5 | key is a _style_. 6 | Besides shipped themes, user can point this tool to any other theme, by simple `fast-theme ~/mytheme.ini`. To 7 | obtain template to work on when creating own theme, issue `fast-theme --copy-shipped-theme {theme-name}`. 8 | 9 | To alter just a few styles and not create a whole new theme, use **overlay**. What is overlay? It is in the same 10 | format as full theme, but can have only a few styles defined, and these styles will overwrite styles in main-theme. 11 | Example overlay file: 12 | 13 | ```ini 14 | ; overlay.ini 15 | [base] 16 | commandseparator = yellow,bold 17 | comment = 17 18 | 19 | [command-point] 20 | function = green 21 | command = 180 22 | ``` 23 | 24 | File name `overlay.ini` is treated specially. 25 | 26 | When specifing path, following short-hands can be used: 27 | 28 | ```ini 29 | CONFIG: = ~/.config/f-sy-h (respects $XDG_CONFIG_HOME env var) 30 | CACHE: = ~/.cache/zi/f-sy-h (respects $XDG_CACHE_HOME env var) 31 | LOCAL: = /usr/local/share/f-sy-h/ 32 | HOME: = ~/.f-sy-h/ 33 | OPT: = /opt/local/share/f-sy-h/ 34 | ``` 35 | 36 | So for example, issue `fast-theme CONFIG:overlay` to load `~/.config/f-sy-h/overlay.ini` as overlay. The `.ini` 37 | extension is optional. 38 | 39 | ## Secondary Theme 40 | 41 | Each theme has key `secondary`, e.g. for theme `free`: 42 | 43 | ```ini 44 | ; free.ini 45 | [base] 46 | default = none 47 | unknown-token = red,bold 48 | ; ... 49 | ; ... 50 | ; ... 51 | secondary = zdharma 52 | ``` 53 | 54 | Secondary theme (`zdharma` in the example) will be used for highlighting of argument for `eval` 55 | and of `$( ... )` interior (i.e. of interior of command substitution). Basically, recursive 56 | highlighting uses alternate theme to make the highlighted code distinct: 57 | 58 | ![sshot](https://raw.githubusercontent.com/z-shell/F-Sy-H/main/docs/images/cmdsubst.png) 59 | 60 | In the above screen-shot the interior of `$( ... )` uses different colors than the rest of the 61 | code. Example for `eval`: 62 | 63 | ![image](https://raw.githubusercontent.com/z-shell/F-Sy-H/main/docs/images/eval_cmp.png) 64 | 65 | First line doesn't use recursive highlighting, highlights `eval` argument as regular string. 66 | Second line switches theme to `zdharma` and does full recursive highlighting of eval argument. 67 | 68 | ## Custom Working Directory 69 | 70 | Set `$FAST_WORK_DIR` before loading the plugin to have e.g. processed theme files (ready to 71 | load, in Zsh format, not INI) kept under specified location. This is handy if e.g. you install 72 | Fast-Syntax-Highlighting system-wide (e.g. from AUR on ArchLinux) and want to have per-user 73 | theme setup. 74 | 75 | You can use "~" in the path, e.g. `FAST_WORK_DIR=~/.f-sy-h` and also the `CONFIG:`, `CACHE:`, `LOCAL:`, `OPT:`, 76 | etc. short-hands, so e.g. `FAST_WORK_DIR=CONFIG` or `FAST_WORK_DIR=CONFIG:` is allowed (in this case 77 | it will be changed to `$HOME/.config/f-sy-h` by default by F-Sy-H loader). 78 | -------------------------------------------------------------------------------- /chroma/-perl.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # Chroma function for command `perl'. It highlights code passed to perl 5 | # with -e option - does syntax check by calling `perl -ce', then highlights 6 | # as correct or incorrect code. 7 | # 8 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 9 | # $2 - the current token, also accessible by $__arg from the above scope - 10 | # basically a private copy of $__arg 11 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 12 | # command line buffer, used to add region_highlight entry (see man), 13 | # because Zsh colorizes by *ranges* in command line buffer 14 | # $4 - a private copy of $_end_pos from the above scope 15 | # 16 | 17 | (( next_word = 2 | 8192 )) 18 | 19 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 20 | local __style 21 | integer __idx1 __idx2 22 | 23 | (( __first_call )) && { 24 | # Called for the first time - new command. 25 | # FAST_HIGHLIGHT is used because it survives between calls, and 26 | # allows to use a single global hash only, instead of multiple 27 | # global variables. 28 | FAST_HIGHLIGHT[chrome-perl-got-eswitch]=0 29 | return 1 30 | } || { 31 | # Following call, i.e. not the first one. 32 | 33 | # Check if chroma should end – test if token is of type 34 | # "starts new command", if so pass-through – chroma ends 35 | [[ "$__arg_type" = 3 ]] && return 2 36 | 37 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 38 | return 1 39 | fi 40 | 41 | if [[ "$__wrd" = -* && ${FAST_HIGHLIGHT[chroma-perl-got-subcommand]} -eq 0 ]]; then 42 | __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option} 43 | 44 | if [[ "$__wrd" = "-e" || ("$__wrd" = -*e* && "$__wrd" != --*) ]]; then 45 | FAST_HIGHLIGHT[chrome-perl-got-eswitch]=1 46 | fi 47 | else 48 | __wrd="${__wrd//\`/x}" 49 | __arg="${__arg//\`/x}" 50 | __wrd="${(Q)__wrd}" 51 | if (( FAST_HIGHLIGHT[chrome-perl-got-eswitch] == 1 )); then 52 | FAST_HIGHLIGHT[chrome-perl-got-eswitch]=0 53 | if perl -ce "$__wrd" >/dev/null 2>&1; then 54 | # Add correct-subtle style 55 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") 56 | else 57 | # Add incorrect-subtle style 58 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") 59 | fi 60 | else 61 | # Pass-through to the big-loop outside 62 | return 1 63 | fi 64 | fi 65 | } 66 | 67 | # Add region_highlight entry (via `reply' array) 68 | # 69 | # This is a common place of adding such entry, but any above 70 | # code can do it itself (and it does) and skip setting __style 71 | # to disable this code. 72 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 73 | 74 | # We aren't passing-through, do obligatory things ourselves 75 | (( this_word = next_word )) 76 | _start_pos=$_end_pos 77 | 78 | return 0 79 | -------------------------------------------------------------------------------- /functions/fast-string-highlight: -------------------------------------------------------------------------------- 1 | #---------------------------------------------------------------------------------------------------------------------- 2 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 3 | # vim: ft=zsh sw=2 ts=2 et 4 | #---------------------------------------------------------------------------------------------------------------------- 5 | # 6 | # $1 - PREBUFFER 7 | # $2 - BUFFER 8 | # 9 | -fast-highlight-string-process() { 10 | builtin emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace} 11 | builtin setopt extended_glob typeset_silent no_short_loops rc_quotes no_auto_pushd 12 | 13 | local -A pos_to_level level_to_pos pair_map final_pairs 14 | local input=$1$2 _mybuf=$1$2 __style __quoting 15 | integer __idx=0 __pair_idx __level=0 __start __end 16 | local -a match mbegin mend 17 | 18 | pair_map=( "(" ")" "{" "}" "[" "]" ) 19 | 20 | while [[ $_mybuf = (#b)([^"{}()[]\\\"'"]#)((["({[]})\"'"])|[\\](*))(*) ]]; do 21 | if [[ -n ${match[4]} ]] { 22 | __idx+=${mbegin[2]} 23 | [[ $__quoting = \' ]] && _mybuf=${match[4]} || { _mybuf=${match[4]:1}; (( ++ __idx )); } 24 | } else { 25 | __idx+=${mbegin[2]} 26 | [[ -z $__quoting && -z ${_FAST_COMPLEX_BRACKETS[(r)$((__idx-${#PREBUFFER}-1))]} ]] && { 27 | if [[ ${match[2]} = ["({["] ]]; then 28 | pos_to_level[$__idx]=$(( ++__level )) 29 | level_to_pos[$__level]=$__idx 30 | elif [[ ${match[2]} = ["]})"] ]]; then 31 | if (( __level > 0 )); then 32 | __pair_idx=${level_to_pos[$__level]} 33 | pos_to_level[$__idx]=$(( __level -- )) 34 | [[ ${pair_map[${input[__pair_idx]}]} = ${input[__idx]} ]] && { 35 | final_pairs[$__idx]=$__pair_idx 36 | final_pairs[$__pair_idx]=$__idx 37 | } 38 | else 39 | pos_to_level[$__idx]=-1 40 | fi 41 | fi 42 | } 43 | if [[ ${match[2]} = \" && $__quoting != \' ]] { 44 | [[ $__quoting = '"' ]] && __quoting="" || __quoting='"'; 45 | } 46 | if [[ ${match[2]} = \' && $__quoting != \" ]] { 47 | if [[ $__quoting = ("'"|"$'") ]] { 48 | __quoting="" 49 | } else { 50 | if [[ $match[1] = *\$ ]] { 51 | __quoting="\$'"; 52 | } else { 53 | __quoting="'"; 54 | } 55 | } 56 | } 57 | _mybuf=${match[5]} 58 | } 59 | done 60 | 61 | for __idx in ${(k)pos_to_level}; do 62 | (( ${+final_pairs[$__idx]} )) && \ 63 | __style=${FAST_THEME_NAME}bracket-level-$(( ( (pos_to_level[$__idx]-1) % 3 ) + 1 )) || \ 64 | __style=${FAST_THEME_NAME}unknown-token 65 | (( __start=__idx-${#PREBUFFER}-1, __end=__idx-${#PREBUFFER}, __start >= 0 )) && \ 66 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 67 | done 68 | 69 | # If cursor is on a bracket, then highlight corresponding bracket, if any. 70 | if [[ $WIDGET != zle-line-finish ]]; then 71 | __idx=$(( CURSOR + 1 )) 72 | if (( ${+pos_to_level[$__idx]} )) && (( ${+final_pairs[$__idx]} )); then 73 | (( __start=final_pairs[$__idx]-${#PREBUFFER}-1, __end=final_pairs[$__idx]-${#PREBUFFER}, __start >= 0 )) && \ 74 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}paired-bracket]}") && \ 75 | reply+=("$CURSOR $__idx ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}paired-bracket]}") 76 | fi 77 | fi 78 | return 0 79 | } 80 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/01_bug_report.yml: -------------------------------------------------------------------------------- 1 | name: "🐞 Bug report" 2 | description: File a bug report 3 | title: "[bug]: " 4 | labels: ["bug 🐞", "triage 📑"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | First off, thanks for taking the time to contribute! Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and are greatly appreciated. 10 | - type: input 11 | id: environment 12 | attributes: 13 | label: Environment 14 | description: > 15 | Please describe your environment e.g: `echo "OSTYPE=${OSTYPE} CPUTYPE=$(uname -m) / MACHINE_TYPE=$MACHTYPE ZSH_VERSION=${ZSH_VERSION}"` 16 | 17 | It may contain any additional information which would help to reproduce the issue. 18 | placeholder: "OSTYPE=linux-gnu CPUTYPE=x86_64 / MACHINE_TYPE=x86_64 ZSH_VERSION=5.8" 19 | validations: 20 | required: true 21 | - type: textarea 22 | id: expected 23 | attributes: 24 | label: Expected behavior 25 | description: "Please describe the expected behavior" 26 | validations: 27 | required: true 28 | - type: textarea 29 | id: current 30 | attributes: 31 | label: Current behavior 32 | description: "Please describe how the bug manifests" 33 | validations: 34 | required: true 35 | - type: textarea 36 | id: reproduce 37 | attributes: 38 | label: Steps to reproduce 39 | description: "Explain the steps required to duplicate the issue" 40 | validations: 41 | required: true 42 | - type: textarea 43 | id: code-snippet 44 | attributes: 45 | label: Code snippet 46 | description: "Please insert your zshrc or just a short code snippet in concern" 47 | validations: 48 | required: true 49 | - type: textarea 50 | id: additional 51 | attributes: 52 | label: Aditional information 53 | description: "List any other information that is relevant to your issue. For reports and stats run `zi analytics`" 54 | validations: 55 | required: true 56 | - type: checkboxes 57 | attributes: 58 | label: Self-service 59 | description: | 60 | If you feel like you could contribute to this issue, please check the box below. This would tell us and other people looking for contributions that someone's working on it. 61 | If you do check this box, please send a pull request within 7 days so we can still delegate this to someone else. 62 | options: 63 | - label: I'd be willing to address this documentation request myself. 64 | - type: checkboxes 65 | attributes: 66 | label: Have you read the Contributing Guidelines? 67 | options: 68 | - label: I have read the [Contributing Guidelines](https://github.com/z-shell/community/blob/main/docs/CONTRIBUTING_GUIDELINES.md). 69 | required: true 70 | - type: checkboxes 71 | attributes: 72 | label: Are you familiar with Contributor Covenant Code of Conduct? 73 | options: 74 | - label: I have read the [Contributor Covenant Code of Conduct](https://github.com/z-shell/zi/blob/main/docs/CODE_OF_CONDUCT.md). 75 | required: true 76 | - type: input 77 | id: contact 78 | attributes: 79 | label: Contact Details 80 | description: How can we get in touch with you if we need more info? 81 | placeholder: ex. email@example.com 82 | validations: 83 | required: false 84 | -------------------------------------------------------------------------------- /chroma/-ruby.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # 3 | # Chroma function for command `ruby'. It highlights code passed to ruby 4 | # with -e option - does syntax check by calling `ruby -ce', then highlights 5 | # as correct or incorrect code. 6 | # 7 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 8 | # $2 - the current token, also accessible by $__arg from the above scope - 9 | # basically a private copy of $__arg 10 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 11 | # command line buffer, used to add region_highlight entry (see man), 12 | # because Zsh colorizes by *ranges* in command line buffer 13 | # $4 - a private copy of $_end_pos from the above scope 14 | # 15 | 16 | (( next_word = 2 | 8192 )) 17 | 18 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 19 | local __style 20 | integer __idx1 __idx2 21 | 22 | (( __first_call )) && { 23 | # Called for the first time - new command. 24 | # FAST_HIGHLIGHT is used because it survives between calls, and 25 | # allows to use a single global hash only, instead of multiple 26 | # global variables. 27 | FAST_HIGHLIGHT[chrome-ruby-got-eswitch]=0 28 | return 1 29 | } || { 30 | # Following call, i.e. not the first one. 31 | 32 | # Check if chroma should end – test if token is of type 33 | # "starts new command", if so pass-through – chroma ends 34 | [[ "$__arg_type" = 3 ]] && return 2 35 | 36 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 37 | return 1 38 | fi 39 | 40 | if [[ "$__wrd" = -* && ${FAST_HIGHLIGHT[chroma-ruby-got-subcommand]} -eq 0 ]]; then 41 | __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option} 42 | 43 | if [[ "$__wrd" = "-e" || ("$__wrd" = -*e* && "$__wrd" != --*) ]]; then 44 | FAST_HIGHLIGHT[chrome-ruby-got-eswitch]=1 45 | fi 46 | else 47 | __wrd="${__wrd//\`/x}" 48 | __arg="${__arg//\`/x}" 49 | __wrd="${(Q)__wrd}" 50 | if (( FAST_HIGHLIGHT[chrome-ruby-got-eswitch] == 1 )); then 51 | FAST_HIGHLIGHT[chrome-ruby-got-eswitch]=0 52 | if ruby -ce "$__wrd" >/dev/null 2>&1; then 53 | # Add correct-subtle style 54 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") 55 | else 56 | # Add incorrect-subtle style 57 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") 58 | fi 59 | else 60 | # Pass-through to the big-loop outside 61 | return 1 62 | fi 63 | FAST_HIGHLIGHT[chrome-ruby-got-eswitch]=0 64 | fi 65 | } 66 | 67 | # Add region_highlight entry (via `reply' array) 68 | # 69 | # This is a common place of adding such entry, but any above 70 | # code can do it itself (and it does) and skip setting __style 71 | # to disable this code. 72 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 73 | 74 | # We aren't passing-through, do obligatory things ourselves 75 | (( this_word = next_word )) 76 | _start_pos=$_end_pos 77 | 78 | return 0 79 | 80 | # vim: ft=zsh sw=2 ts=2 et 81 | -------------------------------------------------------------------------------- /share/free_theme.zsh: -------------------------------------------------------------------------------- 1 | : ${FAST_HIGHLIGHT_STYLES[freealias]:=fg=180} 2 | : ${FAST_HIGHLIGHT_STYLES[freeassign-array-bracket]:=fg=180} 3 | : ${FAST_HIGHLIGHT_STYLES[freeassign]:=none} 4 | : ${FAST_HIGHLIGHT_STYLES[freeback-dollar-quoted-argument]:=fg=110} 5 | : ${FAST_HIGHLIGHT_STYLES[freeback-or-dollar-double-quoted-argument]:=fg=110} 6 | : ${FAST_HIGHLIGHT_STYLES[freeback-quoted-argument]:=none} 7 | : ${FAST_HIGHLIGHT_STYLES[freebracket-level-1]:=fg=130} 8 | : ${FAST_HIGHLIGHT_STYLES[freebracket-level-2]:=fg=70} 9 | : ${FAST_HIGHLIGHT_STYLES[freebracket-level-3]:=fg=69} 10 | : ${FAST_HIGHLIGHT_STYLES[freebuiltin]:=fg=180} 11 | : ${FAST_HIGHLIGHT_STYLES[freecase-condition]:=bg=19} 12 | : ${FAST_HIGHLIGHT_STYLES[freecase-input]:=fg=180} 13 | : ${FAST_HIGHLIGHT_STYLES[freecase-parentheses]:=fg=116} 14 | : ${FAST_HIGHLIGHT_STYLES[freecommand]:=fg=180} 15 | : ${FAST_HIGHLIGHT_STYLES[freecommandseparator]:=none} 16 | : ${FAST_HIGHLIGHT_STYLES[freecomment]:=fg=black,bold} 17 | : ${FAST_HIGHLIGHT_STYLES[freecorrect-subtle]:=bg=55} 18 | : ${FAST_HIGHLIGHT_STYLES[freedefault]:=none} 19 | : ${FAST_HIGHLIGHT_STYLES[freedollar-quoted-argument]:=fg=150} 20 | : ${FAST_HIGHLIGHT_STYLES[freedouble-hyphen-option]:=fg=110} 21 | : ${FAST_HIGHLIGHT_STYLES[freedouble-paren]:=fg=150} 22 | : ${FAST_HIGHLIGHT_STYLES[freedouble-quoted-argument]:=fg=150} 23 | : ${FAST_HIGHLIGHT_STYLES[freedouble-sq-bracket]:=fg=180} 24 | : ${FAST_HIGHLIGHT_STYLES[freeexec-descriptor]:=fg=yellow,bold} 25 | : ${FAST_HIGHLIGHT_STYLES[freefor-loop-number]:=fg=150} 26 | : ${FAST_HIGHLIGHT_STYLES[freefor-loop-operator]:=fg=150} 27 | : ${FAST_HIGHLIGHT_STYLES[freefor-loop-separator]:=fg=109} 28 | : ${FAST_HIGHLIGHT_STYLES[freefor-loop-variable]:=none} 29 | : ${FAST_HIGHLIGHT_STYLES[freefunction]:=fg=180} 30 | : ${FAST_HIGHLIGHT_STYLES[freeglobal-alias]:=bg=19} 31 | : ${FAST_HIGHLIGHT_STYLES[freeglobbing-ext]:=fg=118} 32 | : ${FAST_HIGHLIGHT_STYLES[freeglobbing]:=fg=112} 33 | : ${FAST_HIGHLIGHT_STYLES[freehashed-command]:=fg=180} 34 | : ${FAST_HIGHLIGHT_STYLES[freehere-string-text]:=bg=19} 35 | : ${FAST_HIGHLIGHT_STYLES[freehere-string-tri]:=fg=yellow} 36 | : ${FAST_HIGHLIGHT_STYLES[freehere-string-var]:=fg=110,bg=19} 37 | : ${FAST_HIGHLIGHT_STYLES[freehistory-expansion]:=fg=blue,bold} 38 | : ${FAST_HIGHLIGHT_STYLES[freeincorrect-subtle]:=bg=52} 39 | : ${FAST_HIGHLIGHT_STYLES[freematherr]:=fg=red} 40 | : ${FAST_HIGHLIGHT_STYLES[freemathnum]:=fg=166} 41 | : ${FAST_HIGHLIGHT_STYLES[freemathvar]:=fg=blue,bold} 42 | : ${FAST_HIGHLIGHT_STYLES[freeoptarg-number]:=fg=166} 43 | : ${FAST_HIGHLIGHT_STYLES[freeoptarg-string]:=fg=150} 44 | : ${FAST_HIGHLIGHT_STYLES[freepaired-bracket]:=bg=blue} 45 | : ${FAST_HIGHLIGHT_STYLES[freepath_pathseparator]:=} 46 | : ${FAST_HIGHLIGHT_STYLES[freepath-to-dir]:=fg=166,underline} 47 | : ${FAST_HIGHLIGHT_STYLES[freepath]:=fg=166} 48 | : ${FAST_HIGHLIGHT_STYLES[freeprecommand]:=fg=180} 49 | : ${FAST_HIGHLIGHT_STYLES[freerecursive-base]:=fg=183} 50 | : ${FAST_HIGHLIGHT_STYLES[freeredirection]:=none} 51 | : ${FAST_HIGHLIGHT_STYLES[freereserved-word]:=fg=150} 52 | : ${FAST_HIGHLIGHT_STYLES[freesecondary]:=zdharma} 53 | : ${FAST_HIGHLIGHT_STYLES[freesingle-hyphen-option]:=fg=110} 54 | : ${FAST_HIGHLIGHT_STYLES[freesingle-quoted-argument]:=fg=150} 55 | : ${FAST_HIGHLIGHT_STYLES[freesingle-sq-bracket]:=fg=180} 56 | : ${FAST_HIGHLIGHT_STYLES[freesubcommand]:=fg=150} 57 | : ${FAST_HIGHLIGHT_STYLES[freesubtle-bg]:=bg=18} 58 | : ${FAST_HIGHLIGHT_STYLES[freesubtle-separator]:=none} 59 | : ${FAST_HIGHLIGHT_STYLES[freesuffix-alias]:=fg=180} 60 | : ${FAST_HIGHLIGHT_STYLES[freeunknown-token]:=fg=red,bold} 61 | : ${FAST_HIGHLIGHT_STYLES[freevariable]:=none} 62 | -------------------------------------------------------------------------------- /chroma/-scp.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # 3 | # Tracks scp command and emits message when one tries to pass port to hostspec. 4 | # 5 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 6 | # 7 | # $2 - the current token, also accessible by $__arg from the above scope - 8 | # basically a private copy of $__arg; the token can be eg.: "grep" 9 | # 10 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 11 | # command line buffer, used to add region_highlight entry (see man), 12 | # because Zsh colorizes by *ranges* in command line buffer 13 | # 14 | # $4 - a private copy of $_end_pos from the above scope 15 | # 16 | 17 | (( next_word = 2 | 8192 )) 18 | 19 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 20 | local __style __chars 21 | integer __idx1 __idx2 22 | local -a __results 23 | 24 | # First call, i.e. command starts, i.e. "grep" token etc. 25 | (( __first_call )) && { 26 | FAST_HIGHLIGHT[chroma-scp-counter]=0 27 | FAST_HIGHLIGHT[chroma-scp-counter-all]=1 28 | FAST_HIGHLIGHT[chroma-scp-message]="" 29 | FAST_HIGHLIGHT[chroma-scp-skip-two]=0 30 | return 1 31 | } || { 32 | (( FAST_HIGHLIGHT[chroma-scp-counter-all] += 1, __idx2 = FAST_HIGHLIGHT[chroma-scp-counter-all] )) 33 | 34 | # Following call, i.e. not the first one. 35 | 36 | # Check if chroma should end – test if token is of type 37 | # "starts new command", if so pass-through – chroma ends 38 | [[ "$__arg_type" = 3 ]] && return 2 39 | 40 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 41 | return 1 42 | fi 43 | 44 | if [[ "$__wrd" = -* ]]; then 45 | # Detected option, add style for it. 46 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 47 | __style=${FAST_THEME_NAME}single-hyphen-option 48 | if [[ "$__wrd" = (-c|-F|-i|-l|-o|-P|-S) ]]; then 49 | FAST_HIGHLIGHT[chroma-scp-skip-two]=1 50 | fi 51 | else 52 | # Count non-option tokens. 53 | if (( FAST_HIGHLIGHT[chroma-scp-skip-two] )); then 54 | FAST_HIGHLIGHT[chroma-scp-skip-two]=0 55 | else 56 | (( FAST_HIGHLIGHT[chroma-scp-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-scp-counter] )) 57 | if [[ "${FAST_HIGHLIGHT[chroma-scp-counter]}" -eq 1 ]]; then 58 | if [[ "$__arg" = [^:]##:[0-9]## ]]; then 59 | FAST_HIGHLIGHT[chroma-scp-message]+="Format of hostname incorrect, use -P to pass port number" 60 | else 61 | return 1 62 | fi 63 | else 64 | return 1 65 | fi 66 | fi 67 | fi 68 | 69 | if (( ${#${(z)BUFFER}} <= FAST_HIGHLIGHT[chroma-scp-counter-all] )); then 70 | [[ -n "${FAST_HIGHLIGHT[chroma-scp-message]}" ]] && zle -M "${FAST_HIGHLIGHT[chroma-scp-message]}" 71 | fi 72 | } 73 | 74 | # Add region_highlight entry (via `reply' array). 75 | # 76 | # This is a common place of adding such entry, but any above code 77 | # can do it itself and skip setting __style to disable this code. 78 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 79 | 80 | # We aren't passing-through (no return 1 occured), do obligatory things ourselves. 81 | (( this_word = next_word )) 82 | _start_pos=$_end_pos 83 | 84 | return 0 85 | 86 | # vim: ft=zsh sw=2 ts=2 et 87 | -------------------------------------------------------------------------------- /chroma/-printf.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # 3 | # Highlights the special sequences like "%s" in string passed to `printf'. 4 | # 5 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 6 | # 7 | # $2 - the current token, also accessible by $__arg from the above scope - 8 | # basically a private copy of $__arg; the token can be eg.: "grep" 9 | # 10 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 11 | # command line buffer, used to add region_highlight entry (see man), 12 | # because Zsh colorizes by *ranges* in command line buffer 13 | # 14 | # $4 - a private copy of $_end_pos from the above scope 15 | # 16 | 17 | (( next_word = 2 | 8192 )) 18 | 19 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 20 | local __style __val 21 | integer __idx1 __idx2 22 | 23 | # First call, i.e. command starts, i.e. "grep" token etc. 24 | (( __first_call )) && { 25 | FAST_HIGHLIGHT[chroma-printf-counter]=0 26 | FAST_HIGHLIGHT[chroma-printf-counter-all]=1 27 | FAST_HIGHLIGHT[chroma-printf-message]="" 28 | FAST_HIGHLIGHT[chroma-printf-skip-two]=0 29 | return 1 30 | # Following call (not first one). 31 | } || { 32 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 33 | return 1 34 | fi 35 | (( FAST_HIGHLIGHT[chroma-printf-counter-all] += 1, __idx2 = FAST_HIGHLIGHT[chroma-printf-counter-all] )) 36 | 37 | # Check if chroma should end – test if token is of type 38 | # "starts new command", if so pass-through – chroma ends 39 | [[ "$__arg_type" = 3 ]] && return 2 40 | 41 | if [[ "$__wrd" = -* ]]; then 42 | if [[ "$__wrd" = "-v" ]]; then 43 | FAST_HIGHLIGHT[chroma-printf-skip-two]=1 44 | fi 45 | return 1 46 | else 47 | # Count non-option tokens. 48 | if (( FAST_HIGHLIGHT[chroma-printf-skip-two] )); then 49 | FAST_HIGHLIGHT[chroma-printf-skip-two]=0 50 | return 1 51 | else 52 | (( FAST_HIGHLIGHT[chroma-printf-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-printf-counter] )) 53 | if [[ "$__idx1" -eq 1 ]]; then 54 | [[ "$__wrd" = \"* ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 55 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}") 56 | [[ "$__wrd" = \'* ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ 57 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}single-quoted-argument]}") 58 | FSH_LIST=() # use fsh_sy_h_append function to write to FSH_LIST 59 | : "${__wrd//(#m)\%[\#\+\ 0-]#[0-9]#([.][0-9]#)(#c0,1)[diouxXfFeEgGaAcsb]/$(( fsh_sy_h_append($MBEGIN, $MEND) ))}"; 60 | for __val in "${FSH_LIST[@]}" ; do 61 | __idx1=$(( __start_pos + ${__val%%;;*} )) 62 | __idx2=__idx1+${__val##*;;}-${__val%%;;*}+1 63 | (( __start=__idx1-${#PREBUFFER}, __end=__idx2-${#PREBUFFER}-1, __start >= 0 )) && \ 64 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}mathnum]}") 65 | done 66 | else 67 | return 1 68 | fi 69 | fi 70 | fi 71 | } 72 | 73 | # Add region_highlight entry (via `reply' array). 74 | # 75 | # This is a common place of adding such entry, but any above code 76 | # can do it itself and skip setting __style to disable this code. 77 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 78 | 79 | # We aren't passing-through (no return 1 occured), do obligatory things ourselves. 80 | (( this_word = next_word )) 81 | _start_pos=$_end_pos 82 | 83 | return 0 84 | 85 | # vim: ft=zsh sw=2 ts=2 et 86 | -------------------------------------------------------------------------------- /chroma/-grep.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # 3 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 4 | # 5 | # $2 - the current token, also accessible by $__arg from the above scope - 6 | # basically a private copy of $__arg; the token can be eg.: "grep" 7 | # 8 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 9 | # command line buffer, used to add region_highlight entry (see man), 10 | # because Zsh colorizes by *ranges* in command line buffer 11 | # 12 | # $4 - a private copy of $_end_pos from the above scope 13 | # 14 | 15 | (( next_word = 2 | 8192 )) 16 | 17 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 18 | local __style __chars 19 | integer __idx1 __idx2 20 | 21 | # First call, i.e. command starts, i.e. "grep" token etc. 22 | (( __first_call )) && { 23 | FAST_HIGHLIGHT[chroma-grep-counter]=0 24 | return 1 25 | } || { 26 | # Following call, i.e. not the first one. 27 | 28 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 29 | return 1 30 | fi 31 | 32 | # Check if chroma should end – test if token is of type 33 | # "starts new command", if so pass-through – chroma ends 34 | [[ "$__arg_type" = 3 ]] && return 2 35 | 36 | if [[ "$__wrd" = -* ]]; then 37 | # Detected option, add style for it. 38 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 39 | __style=${FAST_THEME_NAME}single-hyphen-option 40 | else 41 | # Count non-option tokens. 42 | (( FAST_HIGHLIGHT[chroma-grep-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-grep-counter] )) 43 | 44 | # First non-option token is the pattern (regex), we will 45 | # highlight it. 46 | if (( FAST_HIGHLIGHT[chroma-grep-counter] == 1 )); then 47 | [[ "$__wrd" = \"* ]] && __style=${FAST_THEME_NAME}double-quoted-argument 48 | [[ "$__wrd" = \'* ]] && __style=${FAST_THEME_NAME}single-quoted-argument 49 | [[ "$__wrd" = \$\'* ]] && __style=${FAST_THEME_NAME}dollar-quoted-argument 50 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 51 | __style="" 52 | 53 | __chars="*+\\)([]^\$" 54 | __idx1=__start_pos 55 | __idx2=__start_pos 56 | while [[ "$__wrd" = (#b)[^$__chars]#([\\][\\])#((+|\*|\[|\]|\)|\(|\^|\$)|[\\](+|\*|\[|\]|\)|\(|\^|\$))(*) ]]; do 57 | if [[ -n "${match[3]}" ]]; then 58 | __idx1+=${mbegin[3]}-1 59 | __idx2=__idx1+${mend[3]}-${mbegin[3]}+1 60 | (( __start=__idx1-${#PREBUFFER}, __end=__idx2-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}for-loop-operator]}") 61 | __idx1=__idx2 62 | else 63 | __idx1+=${mbegin[5]}-1 64 | fi 65 | __wrd="${match[5]}" 66 | done 67 | elif (( FAST_HIGHLIGHT[chroma-grep-counter] == 2 )); then 68 | # Handle paths, etc. normally - just pass-through to the big 69 | # highlighter (the main f-sy-h highlighter, used before chromas). 70 | return 1 71 | fi 72 | fi 73 | } 74 | 75 | # Add region_highlight entry (via `reply' array). 76 | # 77 | # This is a common place of adding such entry, but any above 78 | # code can do it itself (and it does) and skip setting __style 79 | # to disable this code. 80 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 81 | 82 | # We aren't passing-through (no return 1 occurred), do obligatory things ourselves. 83 | (( this_word = next_word )) 84 | _start_pos=$_end_pos 85 | 86 | return 0 87 | 88 | # vim: ft=zsh sw=2 ts=2 et 89 | -------------------------------------------------------------------------------- /chroma/-docker.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # Chroma function for command `docker'. It verifies command line, by denoting 5 | # wrong and good arguments by color. Currently implemented: verification of 6 | # image IDs passed to: docker image rm . 7 | # 8 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 9 | # $2 - the current token, also accessible by $__arg from the above scope - 10 | # basically a private copy of $__arg 11 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 12 | # command line buffer, used to add region_highlight entry (see man), 13 | # because Zsh colorizes by *ranges* in command line buffer 14 | # $4 - a private copy of $_end_pos from the above scope 15 | # 16 | 17 | (( next_word = 2 | 8192 )) 18 | 19 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 20 | local __style 21 | integer __idx1 __idx2 22 | local -a __lines_list 23 | 24 | (( __first_call )) && { 25 | # Called for the first time - new command 26 | # FAST_HIGHLIGHT is used because it survives between calls, and 27 | # allows to use a single global hash only, instead of multiple 28 | # global variables 29 | FAST_HIGHLIGHT[chroma-docker-counter]=0 30 | FAST_HIGHLIGHT[chroma-docker-got-subcommand]=0 31 | FAST_HIGHLIGHT[chroma-docker-subcommand]="" 32 | FAST_HIGHLIGHT[chrome-docker-got-msg1]=0 33 | return 1 34 | } || { 35 | # Following call, i.e. not the first one 36 | 37 | # Check if chroma should end – test if token is of type 38 | # "starts new command", if so pass-through – chroma ends 39 | [[ "$__arg_type" = 3 ]] && return 2 40 | 41 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 42 | return 1 43 | fi 44 | 45 | if [[ "$__wrd" = -* && ${FAST_HIGHLIGHT[chroma-docker-got-subcommand]} -eq 0 ]]; then 46 | __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option} 47 | else 48 | if (( FAST_HIGHLIGHT[chroma-docker-got-subcommand] == 0 )); then 49 | FAST_HIGHLIGHT[chroma-docker-got-subcommand]=1 50 | FAST_HIGHLIGHT[chroma-docker-subcommand]="$__wrd" 51 | __style=${FAST_THEME_NAME}subcommand 52 | (( FAST_HIGHLIGHT[chroma-docker-counter] += 1 )) 53 | else 54 | __wrd="${__wrd//\`/x}" 55 | __arg="${__arg//\`/x}" 56 | __wrd="${(Q)__wrd}" 57 | if [[ "${FAST_HIGHLIGHT[chroma-docker-subcommand]}" = "image" ]]; then 58 | [[ "$__wrd" != -* ]] && { 59 | (( FAST_HIGHLIGHT[chroma-docker-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-docker-counter] )) 60 | if (( __idx1 == 2 )); then 61 | __style=${FAST_THEME_NAME}subcommand 62 | elif (( __idx1 == 3 )); then 63 | .fast-run-command "docker images -q" chroma-docker-list "" 64 | [[ -n "${__lines_list[(r)$__wrd]}" ]] && { 65 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \ 66 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") 67 | } || { 68 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \ 69 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") 70 | } 71 | fi 72 | } || __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option} 73 | else 74 | return 1 75 | fi 76 | fi 77 | fi 78 | } 79 | 80 | # Add region_highlight entry (via `reply' array) 81 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 82 | 83 | # We aren't passing-through, do obligatory things ourselves 84 | (( this_word = next_word )) 85 | _start_pos=$_end_pos 86 | 87 | return 0 88 | -------------------------------------------------------------------------------- /themes/q-jmnemonic.ini: -------------------------------------------------------------------------------- 1 | ; X-JMnemonic theme for Fast-Syntax-Highlighting: 2 | ; https://github.com/zdharma/fast-syntax-highlighting 3 | ; Version: 1.1 4 | ; 5 | ; Copyright (c) 2018 Sebastian Gniazdowski 6 | ; 7 | ; Based on: https://www.syntaxenvy.com/0753499 8 | ; 9 | ; When I first saw the above theme upon syntaxenvy.com generated it randomly, 10 | ; I've had a quick, bold association with the Johnny Mnemonic movie. I don't 11 | ; know why, but I've decided to name the theme like this and who knows, maybe 12 | ; someone will decipher the connection one day. The theme looks suprisingly 13 | ; well IMO and maybe it's the effect of having this movie property/connection. 14 | ; 15 | ; This theme is a descent of the 40 work hours (or more) non-public theme X-Paragon, 16 | ; which was created to say `thanks' to the patrons at Patreon.com/psprint. It should 17 | ; carry the same quality. 18 | ; 19 | ; The palette - naive and CIE L*a*b conversion: 20 | ; 21 | ; main: 22 | ; #5e6466 -> 59 -> CIELab: 241 23 | ; comment: 24 | ; #434749 -> 16 -> CIELab: 238 25 | ; keyword: 26 | ; #b77c4b -> 137 -> CIELab: 173 27 | ; number, string: 28 | ; #5794a2 -> 67 -> CIELab: 66 29 | ; title, section, name, selector-id: 30 | ; #778ce0 -> 104 -> CIELab: 104 31 | ; attribute, variable, type: 32 | ; #d55383 -> 168 -> CIELab: 168 33 | ; symbol, link: 34 | ; #e66493 -> 168 -> CIELab: 168 35 | ; builtin, deletion: 36 | ; #bd5ac0 -> 133 -> CIELab: 170 37 | ; formula-bg: 38 | ; #363a3b -> 16 -> CIELab: 237 39 | ; 40 | ; Token.Literal: "#dc5be0" -> CIELab: 170 (Orchid; naive: 170) 41 | ; Token.Operator: "#677dcf" -> CIELab: 68 (SteelBlue3; naive: 68) 42 | ; 43 | 44 | [base] 45 | default = none 46 | unknown-token = 196 47 | secondary = sv-orple 48 | recursive-base = 183 49 | 50 | [background] 51 | correct-subtle = bg:18 52 | incorrect-subtle = bg:238 53 | subtle-bg = bg:17 54 | global-alias = bg:20 55 | 56 | ;; 57 | ;; COLOR-GROUPS 58 | ;; 59 | 60 | [gray] 61 | comment = 243 62 | 63 | 64 | 65 | [pastel] 66 | here-string-tri = 217 67 | 68 | 69 | 70 | [no-color] 71 | assign = none 72 | back-quoted-argument = none 73 | redirection = none 74 | variable = none 75 | 76 | 77 | 78 | 79 | [magenta-3] 80 | dollar-quoted-argument = 173 81 | double-quoted-argument = 173 82 | history-expansion = 173 83 | globbing-ext = 173 84 | precommand = 173 85 | 86 | [light-salmon-3] 87 | builtin = 137 88 | subcommand = 137 89 | single-quoted-argument = 137 90 | 91 | [steel-blue-3] 92 | command = 68 93 | double-sq-bracket = 68 94 | double-paren = 68 95 | single-sq-bracket = 68 96 | 97 | [steel-blue] 98 | reserved-word = 67 99 | 100 | 101 | 102 | [medium-purple] 103 | ; backslash in $'...' 104 | back-dollar-quoted-argument = 104 105 | commandseparator = 104 106 | single-hyphen-option = 104 107 | 108 | [dark-khaki] 109 | double-hyphen-option = 143 110 | 111 | 112 | 113 | [hot-pink-3] 114 | alias = 168 115 | exec-descriptor = 168 116 | function = 168 117 | hashed-command = 168 118 | here-string-var = 168 119 | suffix-alias = 168 120 | 121 | [pale-green-3] 122 | assign-array-bracket = 114 123 | ; variable $... or backslash in "..." (i.e. variable in string) 124 | back-or-dollar-double-quoted-argument = 114 125 | globbing = 114 126 | here-string-text = 114 127 | 128 | 129 | 130 | [orchid] 131 | path = 170 132 | path-to-dir = 170,underline 133 | pathseparator = 134 | 135 | 136 | 137 | ;; 138 | ;; FUNCTIONALITY-GROUPS 139 | ;; 140 | 141 | [brackets] 142 | paired-bracket = black,bg:216 143 | bracket-level-1 = 117 144 | bracket-level-2 = 217 145 | bracket-level-3 = 220 146 | 147 | [math] 148 | mathvar = 68 149 | mathnum = 173 150 | matherr = 124 151 | 152 | [for-loop] 153 | forvar = 68 154 | fornum = 173 155 | ; operator 156 | foroper = 133 157 | ; separator 158 | forsep = 104 159 | 160 | [case] 161 | case-input = 168 162 | case-parentheses = 217 163 | case-condition = bg:25 164 | -------------------------------------------------------------------------------- /chroma/-which.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # Outputs (under prompt) result of query done with `which', `type -w', 5 | # `whence -v', `whereis', `whatis'. 6 | # 7 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 8 | # 9 | # $2 - the current token, also accessible by $__arg from the above scope - 10 | # basically a private copy of $__arg; the token can be eg.: "grep" 11 | # 12 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 13 | # command line buffer, used to add region_highlight entry (see man), 14 | # because Zsh colorizes by *ranges* in command line buffer 15 | # 16 | # $4 - a private copy of $_end_pos from the above scope 17 | # 18 | 19 | (( next_word = 2 | 8192 )) 20 | 21 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 22 | local __style __output __chars 23 | integer __idx1 __idx2 24 | local -a __results 25 | 26 | # First call, i.e. command starts, i.e. "grep" token etc. 27 | (( __first_call )) && { 28 | FAST_HIGHLIGHT[chroma-which-counter]=0 29 | FAST_HIGHLIGHT[chroma-which-counter-all]=1 30 | FAST_HIGHLIGHT[chroma-which-message]="" 31 | FAST_HIGHLIGHT[chroma-which-skip-two]=0 32 | __style=${FAST_THEME_NAME}command 33 | __output="" 34 | 35 | # Following call (not first one). 36 | } || { 37 | (( FAST_HIGHLIGHT[chroma-which-counter-all] += 1, __idx2 = FAST_HIGHLIGHT[chroma-which-counter-all] )) 38 | 39 | # Check if chroma should end – test if token is of type 40 | # "starts new command", if so pass-through – chroma ends 41 | [[ "$__arg_type" = 3 ]] && return 2 42 | 43 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 44 | return 1 45 | fi 46 | 47 | if [[ "$__wrd" = -* ]]; then 48 | # Detected option, add style for it. 49 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 50 | __style=${FAST_THEME_NAME}single-hyphen-option 51 | if [[ "$__wrd" = "-x" ]]; then 52 | FAST_HIGHLIGHT[chroma-which-skip-two]=1 53 | fi 54 | else 55 | # Count non-option tokens. 56 | if (( FAST_HIGHLIGHT[chroma-which-skip-two] )); then 57 | FAST_HIGHLIGHT[chroma-which-skip-two]=0 58 | else 59 | (( FAST_HIGHLIGHT[chroma-which-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-which-counter] )) 60 | if [[ "$__idx1" -eq 1 ]]; then 61 | __chars="{" 62 | __output="$(command which "$__wrd" 2>/dev/null)" 63 | FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"command which: $__output" 64 | __output="$(builtin which "$__wrd" 2>/dev/null)" 65 | FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"builtin which: ${${${${__output[1,100]}//$'\n'/;}//$'\t'/ }//$__chars;/$__chars}${__output[101,101]:+...}" 66 | __output="$(builtin type -w "$__wrd" 2>/dev/null)" 67 | FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"type -w: $__output" 68 | __output="$(builtin whence -v "$__wrd" 2>/dev/null)" 69 | FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"whence -v: $__output" 70 | __output="$(command whereis "$__wrd" 2>/dev/null)" 71 | FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"whereis: $__output" 72 | __output="$(command whatis "$__wrd" 2>/dev/null)" 73 | __output="${${__output%%$'\n'*}//[[:blank:]]##/ }" 74 | FAST_HIGHLIGHT[chroma-which-message]+=$'\n'"whatis: $__output" 75 | fi 76 | fi 77 | fi 78 | 79 | if (( ${#${(z)BUFFER}} <= FAST_HIGHLIGHT[chroma-which-counter-all] )); then 80 | [[ -n "${FAST_HIGHLIGHT[chroma-which-message]}" ]] && zle -M "${FAST_HIGHLIGHT[chroma-which-message]#$'\n'}" 81 | fi 82 | } 83 | 84 | # Add region_highlight entry (via `reply' array). 85 | # 86 | # This is a common place of adding such entry, but any above code 87 | # can do it itself and skip setting __style to disable this code. 88 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 89 | 90 | # We aren't passing-through (no return 1 occured), do obligatory things ourselves. 91 | (( this_word = next_word )) 92 | _start_pos=$_end_pos 93 | 94 | return 0 95 | -------------------------------------------------------------------------------- /chroma/-awk.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 5 | # 6 | # $2 - the current token, also accessible by $__arg from the above scope - 7 | # basically a private copy of $__arg; the token can be eg.: "grep" 8 | # 9 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 10 | # command line buffer, used to add region_highlight entry (see man), 11 | # because Zsh colorizes by *ranges* in command line buffer 12 | # 13 | # $4 - a private copy of $_end_pos from the above scope 14 | # 15 | 16 | (( next_word = 2 | 8192 )) 17 | 18 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 19 | local __style __chars __val __style2 20 | integer __idx1 __idx2 21 | 22 | # First call, i.e. command starts, i.e. "grep" token etc. 23 | (( __first_call )) && { 24 | FAST_HIGHLIGHT[chroma-awk-counter]=0 25 | FAST_HIGHLIGHT[chroma-awk-f-seen]=0 26 | return 1 27 | } || { 28 | # Following call, i.e. not the first one. 29 | 30 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 31 | return 1 32 | fi 33 | 34 | # Check if chroma should end – test if token is of type 35 | # "starts new command", if so pass-through – chroma ends 36 | [[ "$__arg_type" = 3 ]] && return 2 37 | 38 | if [[ "$__wrd" = -* ]]; then 39 | # Detected option, add style for it. 40 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 41 | __style=${FAST_THEME_NAME}single-hyphen-option 42 | [[ "$__wrd" = "-f" ]] && FAST_HIGHLIGHT[chroma-awk-f-seen]=1 43 | else 44 | # Count non-option tokens. 45 | (( FAST_HIGHLIGHT[chroma-awk-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-awk-counter] )) 46 | 47 | # First non-option token is the pattern (regex), we will 48 | # highlight it. 49 | if (( FAST_HIGHLIGHT[chroma-awk-counter] == 1 && FAST_HIGHLIGHT[chroma-awk-f-seen] == 0 )); then 50 | if print -r -- "${(Q)__wrd}" | gawk --source 'BEGIN { exit } END { exit 0 }' -f - >/dev/null 2>&1; then 51 | __style2="${FAST_THEME_NAME}subtle-bg" 52 | else 53 | __style2="${FAST_THEME_NAME}incorrect-subtle" 54 | fi 55 | 56 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \ 57 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style2]}") 58 | 59 | # Highlight keywords 60 | FSH_LIST=() 61 | : "${__wrd//(#m)(BEGIN|END|FIELDWIDTHS|RS|ARGC|ARGV|ENVIRON|NF|NR|IGNORECASE|FILENAME|if|then|else|while|toupper|tolower|function|print|sub)/$(( fsh_sy_h_append($MBEGIN, $MEND) ))}"; 62 | for __val in "${FSH_LIST[@]}" ; do 63 | [[ ${__wrd[${__val%%;;*}]} = [a-zA-Z0-9_] || ${__wrd[${__val##*;;}+1]} = [a-zA-Z0-9_] ]] && continue 64 | __idx1=$(( __start_pos + ${__val%%;;*} )) 65 | __idx2=__idx1+${__val##*;;}-${__val%%;;*}+1 66 | (( __start=__idx1-${#PREBUFFER}, __end=__idx2-${#PREBUFFER}-1, __start >= 0 )) && \ 67 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}reserved-word]},${FAST_HIGHLIGHT_STYLES[$__style2]}") 68 | done 69 | 70 | # Highlight regex characters 71 | __chars="*+\\)(\{\}[]^" 72 | __idx1=__start_pos 73 | __idx2=__start_pos 74 | while [[ "$__wrd" = (#b)[^$__chars]#([\\][\\])#((+|\*|\[|\]|\)|\(|\^|\}|\{)|[\\](+|\*|\[|\]|\)|\(|\^|\{|\}))(*) ]]; do 75 | if [[ -n "${match[3]}" ]]; then 76 | __idx1+=${mbegin[3]}-1 77 | __idx2=__idx1+${mend[3]}-${mbegin[3]}+1 78 | (( __start=__idx1-${#PREBUFFER}, __end=__idx2-${#PREBUFFER}, __start >= 0 )) && \ 79 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}mathnum]},${FAST_HIGHLIGHT_STYLES[$__style2]}") 80 | __idx1=__idx2 81 | else 82 | __idx1+=${mbegin[5]}-1 83 | fi 84 | __wrd="${match[5]}" 85 | done 86 | elif (( FAST_HIGHLIGHT[chroma-awk-counter] >= 2 || FAST_HIGHLIGHT[chroma-awk-f-seen] == 1 )); then 87 | FAST_HIGHLIGHT[chroma-awk-f-seen]=0 88 | # Handle paths, etc. normally - just pass-through to the big 89 | # highlighter (the main f-sy-h highlighter, used before chromas). 90 | return 1 91 | fi 92 | fi 93 | } 94 | 95 | # Add region_highlight entry (via `reply' array). 96 | # 97 | # This is a common place of adding such entry, but any above 98 | # code can do it itself (and it does) and skip setting __style 99 | # to disable this code. 100 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 101 | 102 | # We aren't passing-through (no return 1 occurred), do obligatory things ourselves. 103 | (( this_word = next_word )) 104 | _start_pos=$_end_pos 105 | 106 | return 0 107 | -------------------------------------------------------------------------------- /chroma/-make.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # 3 | # Chroma function for command `make'. 4 | # 5 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 6 | # $2 - the current token, also accessible by $__arg from the above scope - 7 | # basically a private copy of $__arg 8 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 9 | # command line buffer, used to add region_highlight entry (see man), 10 | # because Zsh colorizes by *ranges* in command line buffer 11 | # $4 - a private copy of $_end_pos from the above scope 12 | # 13 | 14 | (( next_word = 2 | 8192 )) 15 | 16 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 17 | local __style 18 | integer __idx1 __idx2 19 | local -a __lines_list reply2 20 | 21 | (( __first_call )) && { 22 | # Called for the first time - new command. 23 | # FAST_HIGHLIGHT is used because it survives between calls, and 24 | # allows to use a single global hash only, instead of multiple 25 | # global variables. 26 | FAST_HIGHLIGHT[chroma-make-counter]=0 27 | FAST_HIGHLIGHT[chroma-make-skip-two]=0 28 | FAST_HIGHLIGHT[chroma-make-custom-dir]="./" 29 | FAST_HIGHLIGHT[chroma-make-custom-file]="Makefile" 30 | FAST_HIGHLIGHT[chroma-make-got-custom-dir-opt]=0 31 | FAST_HIGHLIGHT[chroma-make-got-custom-file-opt]=0 32 | return 1 33 | } || { 34 | # Following call, i.e. not the first one. 35 | 36 | # Check if chroma should end – test if token is of type 37 | # "starts new command", if so pass-through – chroma ends 38 | [[ "$__arg_type" = 3 ]] && return 2 39 | 40 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 41 | return 1 42 | fi 43 | 44 | if [[ "$__wrd" = -* || "$__wrd" = *=* ]]; then 45 | [[ "$__wrd" = *=* ]] && { 46 | __style=${FAST_THEME_NAME}variable 47 | } || { 48 | __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option} 49 | } 50 | 51 | if [[ "$__wrd" = (-I|-o|-W) ]]; then 52 | FAST_HIGHLIGHT[chroma-make-skip-two]=1 53 | elif [[ "$__wrd" = "-C" ]]; then 54 | FAST_HIGHLIGHT[chroma-make-got-custom-dir-opt]=1 55 | elif [[ "$__wrd" = "-f" ]]; then 56 | FAST_HIGHLIGHT[chroma-make-got-custom-file-opt]=1 57 | fi 58 | else 59 | if (( FAST_HIGHLIGHT[chroma-make-skip-two] )); then 60 | FAST_HIGHLIGHT[chroma-make-skip-two]=0 61 | elif (( FAST_HIGHLIGHT[chroma-make-got-custom-dir-opt] )); then 62 | FAST_HIGHLIGHT[chroma-make-got-custom-dir-opt]=0 63 | FAST_HIGHLIGHT[chroma-make-custom-dir]="$__wrd" 64 | elif (( FAST_HIGHLIGHT[chroma-make-got-custom-file-opt] )); then 65 | FAST_HIGHLIGHT[chroma-make-got-custom-file-opt]=0 66 | FAST_HIGHLIGHT[chroma-make-custom-file]="$__wrd" 67 | else 68 | # Count non-option tokens. 69 | (( FAST_HIGHLIGHT[chroma-make-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-make-counter] )) 70 | if (( FAST_HIGHLIGHT[chroma-make-counter] == 1 )); then 71 | __wrd="${__wrd//\`/x}" 72 | __wrd="${(Q)__wrd}" 73 | 74 | if [[ -f "${FAST_HIGHLIGHT[chroma-make-custom-dir]%/}/${FAST_HIGHLIGHT[chroma-make-custom-file]}" ]] && \ 75 | .fast-make-targets < "${FAST_HIGHLIGHT[chroma-make-custom-dir]%/}/${FAST_HIGHLIGHT[chroma-make-custom-file]}" 76 | then 77 | if [[ "${reply2[(r)$__wrd]}" ]]; then 78 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") 79 | else 80 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") 81 | fi 82 | fi 83 | else 84 | # Pass-through to the big-loop outside 85 | return 1 86 | fi 87 | fi 88 | fi 89 | } 90 | 91 | # Add region_highlight entry (via `reply' array) 92 | # 93 | # This is a common place of adding such entry, but any above 94 | # code can do it itself (and it does) and skip setting __style 95 | # to disable this code. 96 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 97 | 98 | # We aren't passing-through, do obligatory things ourselves 99 | (( this_word = next_word )) 100 | _start_pos=$_end_pos 101 | 102 | return 0 103 | 104 | # vim: ft=zsh sw=2 ts=2 et 105 | -------------------------------------------------------------------------------- /chroma/-autoload.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # Tracks autoload command - highlights function names if they exist somewhere 5 | # in $fpath. Also warns that the autoload function is already defined. 6 | # 7 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 8 | # 9 | # $2 - the current token, also accessible by $__arg from the above scope - 10 | # basically a private copy of $__arg; the token can be eg.: "grep" 11 | # 12 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 13 | # command line buffer, used to add region_highlight entry (see man), 14 | # because Zsh colorizes by *ranges* in command line buffer 15 | # 16 | # $4 - a private copy of $_end_pos from the above scope 17 | # 18 | 19 | (( next_word = 2 | 8192 )) 20 | 21 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 22 | local __style __chars 23 | integer __idx1 __idx2 24 | local -a __results __deserialized __noshsplit 25 | 26 | # First call, i.e. command starts, i.e. "grep" token etc. 27 | (( __first_call )) && { 28 | FAST_HIGHLIGHT[chroma-autoload-counter]=0 29 | FAST_HIGHLIGHT[chroma-autoload-counter-all]=1 30 | FAST_HIGHLIGHT[chroma-autoload-message]="" 31 | #FAST_HIGHLIGHT[chroma-autoload-message-shown]="" 32 | [[ -z ${FAST_HIGHLIGHT[chroma-autoload-message-shown-at]} ]] && FAST_HIGHLIGHT[chroma-autoload-message-shown-at]=0 33 | FAST_HIGHLIGHT[chroma-autoload-elements]="" 34 | __style=${FAST_THEME_NAME}command 35 | 36 | } || { 37 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 38 | return 1 39 | fi 40 | (( FAST_HIGHLIGHT[chroma-autoload-counter-all] += 1, __idx2 = FAST_HIGHLIGHT[chroma-autoload-counter-all] )) 41 | 42 | # Following call, i.e. not the first one. 43 | 44 | # Check if chroma should end – test if token is of type 45 | # "starts new command", if so pass-through – chroma ends 46 | [[ "$__arg_type" = 3 ]] && return 2 47 | 48 | if [[ "$__wrd" = [-+]* ]]; then 49 | # Detected option, add style for it. 50 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 51 | __style=${FAST_THEME_NAME}single-hyphen-option 52 | else 53 | # Count non-option tokens. 54 | (( FAST_HIGHLIGHT[chroma-autoload-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-autoload-counter] )) 55 | 56 | if [[ $__wrd != (\$|\"\$)* && $__wrd != (/|\"/|\'/)* && $__wrd != \`* ]]; then 57 | __results=( ${^fpath}/$__wrd(N) ) 58 | __deserialized=( "${(Q@)${(z@)FAST_HIGHLIGHT[chroma-fpath_peq-elements]}}" ) 59 | __results+=( ${^__deserialized}/$__wrd(N) ) 60 | [[ "${#__results}" -gt 0 ]] && { 61 | __style=${FAST_THEME_NAME}correct-subtle 62 | __deserialized=( "${(Q@)${(z@)FAST_HIGHLIGHT[chroma-autoload-elements]}}" ) 63 | [[ -z "${__deserialized[1]}" && ${#__deserialized} -eq 1 ]] && __deserialized=() 64 | # Cannot use ${abc:+"$abc"} trick with ${~...}, so handle most 65 | # cases of the possible shwordsplit through an additional array 66 | __noshsplit=( ${~__wrd} ) 67 | __deserialized+=( "${(j: :)__noshsplit}" ) 68 | FAST_HIGHLIGHT[chroma-autoload-elements]="${(j: :)${(q@)__deserialized}}" 69 | # Make the function defined for big-loop's *main-type mechanism 70 | __fast_highlight_main__command_type_cache[${(j: :)__noshsplit}]="function" 71 | } || __style=${FAST_THEME_NAME}incorrect-subtle 72 | fi 73 | 74 | if (( ${+functions[${(Q)__wrd}]} )); then 75 | FAST_HIGHLIGHT[chroma-autoload-message]+="Warning: Function ${(Q)__wrd} already defined (e.g. loaded)"$'\n' 76 | fi 77 | fi 78 | 79 | # Display only when processing last autoload argument 80 | if (( ${#${(z)BUFFER}} == FAST_HIGHLIGHT[chroma-autoload-counter-all] )); then 81 | # Display only if already shown message differs or when it timeouts 82 | if [[ ${FAST_HIGHLIGHT[chroma-autoload-message]} != ${FAST_HIGHLIGHT[chroma-autoload-message-shown]} || \ 83 | $(( EPOCHSECONDS - FAST_HIGHLIGHT[chroma-autoload-message-shown-at] )) -gt 7 ]]; then 84 | FAST_HIGHLIGHT[chroma-autoload-message-shown]=${FAST_HIGHLIGHT[chroma-autoload-message]} 85 | FAST_HIGHLIGHT[chroma-autoload-message-shown-at]=$EPOCHSECONDS 86 | zle -M "${FAST_HIGHLIGHT[chroma-autoload-message]}" 87 | fi 88 | fi 89 | } 90 | 91 | # Add region_highlight entry (via `reply' array). 92 | # 93 | # This is a common place of adding such entry, but any above code 94 | # can do it itself and skip setting __style to disable this code. 95 | [[ -n "$__style" ]] && \ 96 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \ 97 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 98 | 99 | # We aren't passing-through (no return 1 occurred), do obligatory things ourselves. 100 | (( this_word = next_word )) 101 | _start_pos=$_end_pos 102 | 103 | return 0 104 | -------------------------------------------------------------------------------- /chroma/-example.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # 3 | # Example chroma function. It colorizes first two arguments as `builtin' style, 4 | # third and following arguments as `globbing' style. First two arguments may 5 | # be "strings", they will be passed through to normal highlighter (by returning 1). 6 | # 7 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 8 | # 9 | # $2 - the current token, also accessible by $__arg from the above scope - 10 | # basically a private copy of $__arg; the token can be eg.: "grep" 11 | # 12 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 13 | # command line buffer, used to add region_highlight entry (see man), 14 | # because Zsh colorizes by *ranges* in command line buffer 15 | # 16 | # $4 - a private copy of $_end_pos from the above scope 17 | # 18 | # 19 | # Overall functioning is: when command "example" is occurred, this function 20 | # is called with $1 == 1, it ("example") is the first token ($2), then for any 21 | # following token, this function is called with $1 == 0, until end of command 22 | # is occurred (i.e. till enter is pressed or ";" is put into source, or the 23 | # command line simply ends). 24 | # 25 | # Other tips are: 26 | # - $CURSOR holds cursor position 27 | # - $BUFFER holds whole command line buffer 28 | # - $LBUFFER holds command line buffer that is left from the cursor, i.e. it's a 29 | # BUFFER substring 1 .. $CURSOR 30 | # - $RBUFFER is the same as LBUFFER but holds part of BUFFER right to the cursor 31 | # 32 | # The function receives $BUFFER but via sequence of tokens, which are shell words, 33 | # e.g. "a b c" is a shell word, while a b c are 3 shell words. 34 | # 35 | # FAST_HIGHLIGHT is a friendly hash array which allows to store strings without 36 | # creating global parameters (variables). If you need hash, just use it first 37 | # declaring, under some distinct name like: typeset -gA CHROMA_EXPLE_DICT. 38 | # Remember to reset the hash and others at __first_call == 1, so that you have 39 | # a fresh state for new command. 40 | 41 | # Keep chroma-takeover state meaning: until ;, handle highlighting via chroma. 42 | # So the below 8192 assignment takes care that next token will be routed to chroma. 43 | (( next_word = 2 | 8192 )) 44 | 45 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 46 | local __style 47 | integer __idx1 __idx2 48 | 49 | (( __first_call )) && { 50 | # Called for the first time - new command. 51 | # FAST_HIGHLIGHT is used because it survives between calls, and 52 | # allows to use a single global hash only, instead of multiple 53 | # global string variables. 54 | FAST_HIGHLIGHT[chroma-example-counter]=0 55 | 56 | # Set style for region_highlight entry. It is used below in 57 | # '[[ -n "$__style" ]] ...' line, which adds highlight entry, 58 | # like "10 12 fg=green", through `reply' array. 59 | # 60 | # Could check if command `example' exists and set `unknown-token' 61 | # style instead of `command' 62 | __style=${FAST_THEME_NAME}command 63 | 64 | } || { 65 | # Following call, i.e. not the first one 66 | 67 | # Check if chroma should end – test if token is of type 68 | # "starts new command", if so pass-through – chroma ends 69 | [[ "$__arg_type" = 3 ]] && return 2 70 | 71 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 72 | return 1 73 | fi 74 | 75 | if [[ "$__wrd" = -* ]]; then 76 | # Detected option, add style for it. 77 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 78 | __style=${FAST_THEME_NAME}single-hyphen-option 79 | else 80 | # Count non-option tokens 81 | (( FAST_HIGHLIGHT[chroma-example-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-example-counter] )) 82 | 83 | # Colorize 1..2 as builtin, 3.. as glob 84 | if (( FAST_HIGHLIGHT[chroma-example-counter] <= 2 )); then 85 | if [[ "$__wrd" = \"* ]]; then 86 | # Pass through, f-sy-h main code will do the highlight! 87 | return 1 88 | else 89 | __style=${FAST_THEME_NAME}builtin 90 | fi 91 | else 92 | __style=${FAST_THEME_NAME}globbing 93 | fi 94 | fi 95 | } 96 | 97 | # Add region_highlight entry (via `reply' array). 98 | # If 1 will be added to __start_pos, this will highlight "oken". 99 | # If 1 will be subtracted from __end_pos, this will highlight "toke". 100 | # $PREBUFFER is for specific situations when users does command \ 101 | # i.e. when multi-line command using backslash is entered. 102 | # 103 | # This is a common place of adding such entry, but any above code can do 104 | # it itself (and it does in other chromas) and skip setting __style to 105 | # this way disable this code. 106 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 107 | 108 | # We aren't passing-through, do obligatory things ourselves. 109 | # _start_pos=$_end_pos advances pointers in command line buffer. 110 | # 111 | # To pass through means to `return 1'. The highlighting of 112 | # this single token is then done by fast-syntax-highlighting's 113 | # main code and chroma doesn't have to do anything. 114 | (( this_word = next_word )) 115 | _start_pos=$_end_pos 116 | 117 | return 0 118 | 119 | # vim: ft=zsh sw=2 ts=2 et 120 | -------------------------------------------------------------------------------- /chroma/-whatis.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | 4 | (( next_word = 2 | 8192 )) 5 | local THEFD check __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 6 | local __style 7 | 8 | (( ! ${+FAST_HIGHLIGHT[whatis_chroma_callback_was_ran]} )) && \ 9 | FAST_HIGHLIGHT[whatis_chroma_callback_was_ran]=0 10 | 11 | (( ! ${+FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]} )) && { 12 | is-at-least 5.0.6 && local __res=1 || local __res=0 13 | FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]="$__res" 14 | } 15 | 16 | -fast-whatis-chroma-callback() { 17 | builtin emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace} 18 | builtin setopt extended_glob warn_create_global typeset_silent no_short_loops rc_quotes no_auto_pushd 19 | 20 | local THEFD="$1" input check=2 nl=$'\n' __wrd __style 21 | 22 | .fast-zts-read-all "$THEFD" input 23 | 24 | zle -F "$THEFD" 25 | exec {THEFD}<&- 26 | 27 | __wrd="${${input#[^$nl]#$nl}%%$nl*}" 28 | if [[ "$input" = test* ]]; then 29 | if [[ "${input%$nl}" = *[^0-9]'0' ]]; then 30 | if [[ "${input#test$nl}" = *nothing\ appropriate* ]]; then 31 | FAST_HIGHLIGHT[whatis_chroma_type]=2 32 | else 33 | FAST_HIGHLIGHT[whatis_chroma_type]=0 34 | fi 35 | else 36 | FAST_HIGHLIGHT[whatis_chroma_type]=1 37 | fi 38 | elif [[ "$input" = type2* ]]; then 39 | [[ "$input" != *nothing\ appropriate* ]] && check=1 || check=0 40 | elif [[ "$input" = type1* ]]; then 41 | [[ "${input%$nl}" = *0 ]] && check=1 || check=0 42 | fi 43 | 44 | if (( check != 2 )); then 45 | FAST_HIGHLIGHT[whatis-cache-$__wrd]=$check 46 | if (( check )) then 47 | __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]} 48 | elif [[ ${~__wrd} = */* && -e ${~__wrd} ]] then 49 | __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]} 50 | else 51 | __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]} 52 | fi 53 | local -a start_end 54 | start_end=( ${(s:/:)${${(M)${${input#type?${nl}[^$nl]#$nl}}#*$nl}%$nl}} ) 55 | (( start_end[1] >= 0 )) && region_highlight+=("$start_end[1] $start_end[2] $__style") 56 | zle -R 57 | fi 58 | 59 | FAST_HIGHLIGHT[whatis_chroma_callback_was_ran]=1 60 | return 0 61 | } 62 | 63 | zle -N -- -fast-whatis-chroma-callback 64 | 65 | if (( __first_call )) && [[ -z "${FAST_HIGHLIGHT[whatis_chroma_type]}" ]] ;then 66 | if ! command -v whatis > /dev/null; then 67 | FAST_HIGHLIGHT[whatis_chroma_type]=0 68 | return 1 69 | fi 70 | 71 | exec {THEFD}< <( 72 | print "test" 73 | LANG=C whatis "osx whatis fallback check" 74 | print "$?" 75 | ) 76 | command true # a workaround of Zsh bug 77 | zle -F ${${FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]:#0}:+-w} "$THEFD" -fast-whatis-chroma-callback 78 | fi 79 | 80 | [[ "$__arg_type" = 3 ]] && return 2 81 | 82 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 83 | return 1 84 | fi 85 | 86 | if (( __first_call )) || [[ "$__wrd" = -* ]]; then 87 | return 1 88 | elif (( ! FAST_HIGHLIGHT[whatis_chroma_type] )); then 89 | # Return 1 (i.e. treat the argument as a path) only if the callback have 90 | # had a chance to establish the whatis_chroma_type field 91 | (( FAST_HIGHLIGHT[whatis_chroma_callback_was_ran] )) && return 1 92 | else 93 | if [[ -z "${FAST_HIGHLIGHT[whatis-cache-$__wrd]}" ]]; then 94 | if (( FAST_HIGHLIGHT[whatis_chroma_type] == 2 )); then 95 | exec {THEFD}< <( 96 | print "type2" 97 | print "$__wrd" 98 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER} )) 99 | print "$__start/$__end" 100 | LANG=C whatis "$__wrd" 2>/dev/null 101 | ) 102 | command true # see above 103 | zle -F ${${FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]:#0}:+-w} "$THEFD" -fast-whatis-chroma-callback 104 | else 105 | exec {THEFD}< <( 106 | print "type1" 107 | print "$__wrd" 108 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER} )) 109 | print "$__start/$__end" 110 | LANG=C whatis "$__wrd" &> /dev/null 111 | print "$?" 112 | ) 113 | command true 114 | zle -F ${${FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]:#0}:+-w} "$THEFD" -fast-whatis-chroma-callback 115 | fi 116 | __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]} 117 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \ 118 | reply+=("$__start $__end $__style") 119 | else 120 | check=${FAST_HIGHLIGHT[whatis-cache-$__wrd]} 121 | if (( check )) then 122 | __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]} 123 | elif [[ ${~__wrd} = */* && -e ${~__wrd} ]] then 124 | __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]} 125 | elif (( FAST_HIGHLIGHT[whatis_chroma_type] )); then 126 | __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]} 127 | fi 128 | [[ -n "$__style" ]] && \ 129 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \ 130 | reply+=("$__start $__end $__style") 131 | fi 132 | fi 133 | (( this_word = next_word )) 134 | _start_pos=$_end_pos 135 | 136 | return 0 137 | -------------------------------------------------------------------------------- /chroma/-ionice.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # ------------------------------------------------------------------------------------------------- 5 | # Copyright (c) 2018 Sebastian Gniazdowski 6 | # Copyright (C) 2019 by Philippe Troin (F-i-f on GitHub) 7 | # All rights reserved. 8 | # 9 | # The only licensing for this file follows. 10 | # 11 | # Redistribution and use in source and binary forms, with or without modification, are permitted 12 | # provided that the following conditions are met: 13 | # 14 | # * Redistributions of source code must retain the above copyright notice, this list of conditions 15 | # and the following disclaimer. 16 | # * Redistributions in binary form must reproduce the above copyright notice, this list of 17 | # conditions and the following disclaimer in the documentation and/or other materials provided 18 | # with the distribution. 19 | # * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors 20 | # may be used to endorse or promote products derived from this software without specific prior 21 | # written permission. 22 | # 23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 24 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 25 | # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 26 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 30 | # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | # ------------------------------------------------------------------------------------------------- 32 | 33 | builtin setopt extended_glob warn_create_global typeset_silent no_short_loops rc_quotes no_auto_pushd local_options 34 | 35 | # Keep chroma-takever state meaning: until ;, handle highlighting via chroma. 36 | # So the below 8192 assignment takes care that next token will be routed to chroma. 37 | (( next_word = 2 | 8192 )) 38 | 39 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 40 | local __style option_start=0 option_end=0 number_start=0 number_end=0 41 | local -a match mbegin mend 42 | 43 | (( __first_call )) && { 44 | # Called for the first time - new command. 45 | # FAST_HIGHLIGHT is used because it survives between calls, and 46 | # allows to use a single global hash only, instead of multiple 47 | # global string variables. 48 | FAST_HIGHLIGHT[ionice-option-argument]=0 49 | 50 | # Set style for region_highlight entry. It is used below in 51 | # '[[ -n "$__style" ]] ...' line, which adds highlight entry, 52 | # like "10 12 fg=green", through `reply' array. 53 | # 54 | # Could check if command `example' exists and set `unknown-token' 55 | # style instead of `command' 56 | __style=${FAST_THEME_NAME}precommand 57 | 58 | } || { 59 | # Following call, i.e. not the first one 60 | 61 | # Check if chroma should end – test if token is of type 62 | # "starts new command", if so pass-through – chroma ends 63 | [[ "$__arg_type" = 3 ]] && return 2 64 | 65 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 66 | return 1 67 | fi 68 | 69 | if (( FAST_HIGHLIGHT[ionice-option-argument] )); then 70 | (( FAST_HIGHLIGHT[ionice-option-argument] = 0 )) 71 | [[ $__wrd == [0-9]# ]] && __style=${FAST_THEME_NAME}mathnum || __style=${FAST_THEME_NAME}incorrect-subtle 72 | else 73 | case $__wrd in 74 | --(class(data|)|(u|p(g|))id)) 75 | __style=${FAST_THEME_NAME}double-hyphen-option 76 | FAST_HIGHLIGHT[ionice-option-argument]=1 77 | ;; 78 | -[cnpPu]) 79 | __style=${FAST_THEME_NAME}single-hyphen-option 80 | FAST_HIGHLIGHT[ionice-option-argument]=1 81 | ;; 82 | --*) 83 | __style=${FAST_THEME_NAME}double-hyphen-option 84 | ;; 85 | -*) 86 | __style=${FAST_THEME_NAME}single-hyphen-option 87 | ;; 88 | *) 89 | this_word=1 90 | next_word=2 91 | return 1 92 | ;; 93 | esac 94 | fi 95 | } 96 | 97 | # Add region_highlight entry (via `reply' array). 98 | # If 1 will be added to __start_pos, this will highlight "oken". 99 | # If 1 will be subtracted from __end_pos, this will highlight "toke". 100 | # $PREBUFFER is for specific situations when users does command \ 101 | # i.e. when multi-line command using backslash is entered. 102 | # 103 | # This is a common place of adding such entry, but any above code can do 104 | # it itself (and it does in other chromas) and skip setting __style to 105 | # this way disable this code. 106 | [[ -n "$__style" ]] && \ 107 | (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \ 108 | reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 109 | 110 | # We aren't passing-through, do obligatory things ourselves. 111 | # _start_pos=$_end_pos advances pointers in command line buffer. 112 | # 113 | # To pass through means to `return 1'. The highlighting of 114 | # this single token is then done by fast-syntax-highlighting's 115 | # main code and chroma doesn't have to do anything. 116 | (( this_word = next_word )) 117 | _start_pos=$_end_pos 118 | 119 | return 0 120 | -------------------------------------------------------------------------------- /tests/main.zunit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zunit 2 | @setup { 3 | load "../functions/fast-highlight" 4 | setopt interactive_comments 5 | -fast-highlight-fill-option-variables 6 | } 7 | 8 | @test 'ls /usr/bin' { 9 | reply=() 10 | PREBUFFER="" 11 | BUFFER="ls /usr/bin" 12 | evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0 13 | 14 | assert "$reply[1]" same_as "0 2 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}command]}" 15 | assert "$reply[2]" same_as "3 11 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path-to-dir]}" 16 | assert "$reply[3]" same_as "" 17 | } 18 | 19 | @test 'ls /bin/df' { 20 | reply=() 21 | PREBUFFER="" 22 | BUFFER="ls /bin/df" 23 | evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0 24 | 25 | assert "$reply[1]" same_as "0 2 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}command]}" 26 | assert "$reply[2]" same_as "3 10 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]}" 27 | assert "$reply[3]" same_as "" 28 | } 29 | 30 | 31 | @test 'ls /bin/ls\\n # a comment\\nls /usr/bin' { 32 | reply=() 33 | PREBUFFER="" 34 | BUFFER=$'ls /bin/df\n # a comment\nls /usr/bin' 35 | evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0 36 | 37 | assert "$reply[1]" same_as "0 2 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}command]}" 38 | assert "$reply[2]" same_as "3 10 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]}" 39 | assert "$reply[3]" same_as "12 23 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}comment]}" 40 | assert "$reply[4]" same_as "24 26 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}command]}" 41 | assert "$reply[5]" same_as "27 35 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path-to-dir]}" 42 | assert "$reply[6]" same_as "" 43 | } 44 | 45 | 46 | @test 'exec {FD}< <( ls /bin )' { 47 | reply=() 48 | PREBUFFER="" 49 | BUFFER=$'exec {FD}< <( ls /bin )' 50 | evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0 51 | 52 | assert "$reply[1]" same_as "0 4 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}precommand]}" 53 | assert "$reply[2]" same_as "5 9 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}exec-descriptor]}" 54 | assert "$reply[3]" same_as "" 55 | } 56 | 57 | 58 | @test 'case x in x) a;; (y) ;; esac' { 59 | reply=() 60 | PREBUFFER="" 61 | BUFFER=$'case x in\nx) a;;\n(y)\n;;\nesac' 62 | evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0 63 | 64 | assert "$reply[1]" same_as "0 4 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}reserved-word]}" 65 | assert "$reply[2]" same_as "5 6 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-input]}" 66 | assert "$reply[3]" same_as "7 9 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-parentheses]}" 67 | assert "$reply[4]" same_as "10 11 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-condition]}" 68 | assert "$reply[5]" same_as "11 12 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-parentheses]}" 69 | assert "$reply[6]" same_as "13 14 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}unknown-token]}" 70 | assert "$reply[7]" same_as "17 18 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-parentheses]}" 71 | assert "$reply[8]" same_as "18 19 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-condition]}" 72 | assert "$reply[9]" same_as "19 20 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-parentheses]}" 73 | assert "$reply[10]" same_as "24 28 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}reserved-word]}" 74 | assert "$reply[11]" same_as "" 75 | } 76 | 77 | @test '-fast-highlight-process "$PREBUFFER" "$BUFFER" 0' { 78 | reply=() 79 | PREBUFFER="" 80 | BUFFER='-fast-highlight-process "$PREBUFFER" "$BUFFER" 0' 81 | evl -fast-highlight-process "\$PREBUFFER" "\$BUFFER" 0 82 | 83 | assert "$reply[1]" same_as "0 23 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}function]}" 84 | assert "$reply[2]" same_as "24 36 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}" 85 | assert "$reply[3]" same_as "25 35 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}back-or-dollar-double-quoted-argument]}" 86 | assert "$reply[4]" same_as "37 46 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}" 87 | assert "$reply[5]" same_as "38 45 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}back-or-dollar-double-quoted-argument]}" 88 | assert "$reply[6]" same_as "" 89 | } 90 | 91 | @test 'tr : \\\\n <<<$PATH' { 92 | reply=() 93 | PREBUFFER="" 94 | BUFFER='command tr : \\n << 127 | 128 | Assignments are no more one-colour default-white. When used in assignment, highlighted are: 129 | 130 | - variables (outside strings), 131 | - strings (double-quoted and single-quoted), 132 | - math-mode (`val=$(( ... ))`). 133 | 134 | ![sshot](https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/main/images/assign.png) 135 | 136 | ## 2018-01-06 137 | 138 | Math mode is highlighted – expressions `(( ... ))` and `$(( ... ))`. Empty variables are colorized as red. 139 | There are 3 style names (fields of 140 | [FAST_HIGHLIGHT_STYLES](https://github.com/zdharma/fast-syntax-highlighting/blob/main/functions/fast-highlight#L34) 141 | hash) for math-variable, number and empty variable (error): `mathvar`, `mathnum`, `matherr`. You can set 142 | them (like the animation below shows) to change colors. 143 | 144 | ![animation](https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/main/images/math.gif) 145 | -------------------------------------------------------------------------------- /chroma/-nice.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # ------------------------------------------------------------------------------------------------- 5 | # Copyright (c) 2018 Sebastian Gniazdowski 6 | # Copyright (C) 2019 by Philippe Troin (F-i-f on GitHub) 7 | # All rights reserved. 8 | # 9 | # The only licensing for this file follows. 10 | # 11 | # Redistribution and use in source and binary forms, with or without modification, are permitted 12 | # provided that the following conditions are met: 13 | # 14 | # * Redistributions of source code must retain the above copyright notice, this list of conditions 15 | # and the following disclaimer. 16 | # * Redistributions in binary form must reproduce the above copyright notice, this list of 17 | # conditions and the following disclaimer in the documentation and/or other materials provided 18 | # with the distribution. 19 | # * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors 20 | # may be used to endorse or promote products derived from this software without specific prior 21 | # written permission. 22 | # 23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 24 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 25 | # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 26 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 30 | # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | # ------------------------------------------------------------------------------------------------- 32 | 33 | builtin setopt extended_glob warn_create_global typeset_silent no_short_loops rc_quotes no_auto_pushd 34 | 35 | # Keep chroma-takever state meaning: until ;, handle highlighting via chroma. 36 | # So the below 8192 assignment takes care that next token will be routed to chroma. 37 | (( next_word = 2 | 8192 )) 38 | 39 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 40 | local __style option_start=0 option_end=0 number_start=0 number_end=0 41 | local -a match mbegin mend 42 | 43 | (( __first_call )) && { 44 | # Called for the first time - new command. 45 | # FAST_HIGHLIGHT is used because it survives between calls, and 46 | # allows to use a single global hash only, instead of multiple 47 | # global string variables. 48 | FAST_HIGHLIGHT[nice-arg-count]=0 49 | FAST_HIGHLIGHT[nice-increment-argument]=0 50 | 51 | # Set style for region_highlight entry. It is used below in 52 | # '[[ -n "$__style" ]] ...' line, which adds highlight entry, 53 | # like "10 12 fg=green", through `reply' array. 54 | # 55 | # Could check if command `example' exists and set `unknown-token' 56 | # style instead of `command' 57 | __style=${FAST_THEME_NAME}precommand 58 | 59 | } || { 60 | # Following call, i.e. not the first one 61 | 62 | # Check if chroma should end – test if token is of type 63 | # "starts new command", if so pass-through – chroma ends 64 | [[ "$__arg_type" = 3 ]] && return 2 65 | 66 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 67 | return 1 68 | fi 69 | 70 | if (( FAST_HIGHLIGHT[nice-increment-argument] )); then 71 | (( FAST_HIGHLIGHT[nice-increment-argument] = 0 )) 72 | [[ $__wrd = (-|+|)[0-9]## ]] \ 73 | && __style=${FAST_THEME_NAME}mathnum \ 74 | || __style=${FAST_THEME_NAME}incorrect-subtle 75 | else 76 | case $__wrd in 77 | -(-|+|)[0-9]##) 78 | (( option_start = __start_pos-${#PREBUFFER} , 79 | option_end = option_start+1 , 80 | number_start = option_end , 81 | number_end = __end_pos-${#PREBUFFER} )) 82 | option_style=${FAST_THEME_NAME}single-hyphen-option 83 | ;; 84 | (#b)(--adjustment)(=(-|+|)[0-9]#|)) 85 | (( option_start = __start_pos-${#PREBUFFER} , 86 | option_end = option_start+mend[1] )) 87 | option_style=${FAST_THEME_NAME}double-hyphen-option 88 | [[ -z $match[2] ]] \ 89 | && (( FAST_HIGHLIGHT[nice-increment-argument] = 1 )) \ 90 | || (( option_end += 1 , 91 | number_start = option_start+mbegin[2]-mbegin[1]+1 , 92 | number_end = __end_pos-${#PREBUFFER} )) 93 | ;; 94 | -n) 95 | __style=${FAST_THEME_NAME}double-hyphen-option 96 | FAST_HIGHLIGHT[nice-increment-argument]=1 97 | ;; 98 | --*) 99 | __style=${FAST_THEME_NAME}double-hyphen-option 100 | ;; 101 | -*) 102 | __style=${FAST_THEME_NAME}single-hyphen-option 103 | ;; 104 | *) 105 | this_word=1 106 | next_word=2 107 | return 1 108 | ;; 109 | esac 110 | 111 | (( option_start > 0 && option_end )) \ 112 | && reply+=("$option_start $option_end ${FAST_HIGHLIGHT_STYLES[$option_style]}") 113 | (( number_start > 0 && number_end )) \ 114 | && reply+=("$number_start $number_end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}mathnum]}") 115 | fi 116 | } 117 | 118 | # Add region_highlight entry (via `reply' array). 119 | # If 1 will be added to __start_pos, this will highlight "oken". 120 | # If 1 will be subtracted from __end_pos, this will highlight "toke". 121 | # $PREBUFFER is for specific situations when users does command \ 122 | # i.e. when multi-line command using backslash is entered. 123 | # 124 | # This is a common place of adding such entry, but any above code can do 125 | # it itself (and it does in other chromas) and skip setting __style to 126 | # this way disable this code. 127 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 128 | 129 | # We aren't passing-through, do obligatory things ourselves. 130 | # _start_pos=$_end_pos advances pointers in command line buffer. 131 | # 132 | # To pass through means to `return 1'. The highlighting of 133 | # this single token is then done by fast-syntax-highlighting's 134 | # main code and chroma doesn't have to do anything. 135 | (( this_word = next_word )) 136 | _start_pos=$_end_pos 137 | 138 | return 0 139 | -------------------------------------------------------------------------------- /docs/CHROMA_GUIDE.adoc: -------------------------------------------------------------------------------- 1 | # Chroma Guide for F-Sy-H 2 | 3 | ## Motivation 4 | 5 | Someone might want to create a detailed highlighting for a **specific program** 6 | and this document helps achieving this. It explains how chroma functions – the 7 | code behind such detailed highlighting – are constructed and used. 8 | 9 | ## Keywords 10 | 11 | - `chroma` - a shorthand for `chroma function` – the thing that literally colorizes selected commands, like `git`, `grep`, etc. invocations, see `chroma function` below, 12 | - `big loop` - main highlighting code, a loop over tokens and at least 2 large structular constructs (big `if` and `case`); 13 | it is advanced, e.g. parses `case` statements, here-string, it basically constitutes 90% of the F-Sy-H project, 14 | - `chroma function` - a plugin-function that is called when a specific command occurs (e.g. when user enters `git` at 15 | command line) suppressing activity of `big loop` (i.e. no standard highlighting unless requested), 16 | - `token` - result of splitting whole command line (i.e. `$BUFFER`, the Zle variable) into bits called tokens, which are 17 | words in general, separated by spaces on the command line. 18 | 19 | ## Overview Of Functioning 20 | 21 | 1. Big loop is working – token by token processes command line, changes states (e.g. enters state "inside case 22 | statement") and in the end decides on color of the token currently processed. 23 | 24 | 2. Big loop occurs a command that has a chroma, e.g. `git`. 25 | 26 | 3. Big loop enters "chroma" state, calls associated chroma function. 27 | 28 | 4. Chroma takes care of "chroma" state, ensures it will be set also for next token. 29 | 30 | 5. "chroma" state is active, so all following tokens are routed to the chroma (in general skipping big-loop, see next items), 31 | 32 | 6. When processing of a single token is complete, the associated chroma returns 0 33 | (shell-truth) to request no further processing by the big loop. 34 | 35 | 7. It can also return 1 so that single, current token will be passed into big-loop 36 | for processing (to do a standard highlighting). 37 | 38 | ## Chroma-Function Arguments 39 | 40 | - `$1` - 0 or 1, denoting if it's the first call to the chroma, or a following one, 41 | 42 | - `$2` - the current token, also accessible by `$\__arg` from the upper scope - 43 | basically a private copy of `$__arg`; the token can be eg.: "grep", 44 | 45 | - `$3` - a private copy of `$_start_pos`, i.e. the position of the token in the 46 | command line buffer, used to add region_highlight entry (see man), 47 | because Zsh colorizes by *ranges* applied onto command line buffer (e.g. 48 | `from-10 to-13 fg=red`), 49 | 50 | - `$4` - a private copy of `$_end_pos` from the upper scope; denotes where current token 51 | ends (at which index in the string being the command line). 52 | 53 | So example invocation could look like this: 54 | 55 | ---- 56 | chroma/-example.ch 1 "grep" "$_start_pos" "$_end_pos" 57 | ---- 58 | 59 | Big-loop will be doing such calls for the user, after occurring a specific chroma-enabled command (like e.g. `awk`), and then until chroma will detect end of this chroma-enabled command (end of whole invocation, with arguments, etc.; in other words, when e.g. new line or `;`-character occurs, etc.). 60 | 61 | ## Example Chroma-Function 62 | 63 | [source,zsh] 64 | ---- 65 | # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 66 | # Copyright (c) 2018 Sebastian Gniazdowski 67 | # 68 | # Example chroma function. It colorizes first two arguments as `builtin' style, 69 | # third and following arguments as `globbing' style. First two arguments may 70 | # be "strings", they will be passed through to normal higlighter (by returning 1). 71 | # 72 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 73 | # 74 | # $2 - like above document says 75 | # 76 | # $3 - ... 77 | # 78 | # $4 - ... 79 | # 80 | # Other tips are: 81 | # - $CURSOR holds cursor position 82 | # - $BUFFER holds whole command line buffer 83 | # - $LBUFFER holds command line buffer that is left from the cursor, i.e. it's a 84 | # BUFFER substring 1 .. $CURSOR 85 | # - $RBUFFER is the same as LBUFFER but holds part of BUFFER right to the cursor 86 | # 87 | # The function receives $BUFFER but via sequence of tokens, which are shell words, 88 | # e.g. "a b c" is a shell word, while a b c are 3 shell words. 89 | # 90 | # FAST_HIGHLIGHT is a friendly hash array which allows to store strings without 91 | # creating global parameters (variables). If you need hash, go ahead and use it, 92 | # declaring first, under some distinct name like: typeset -gA CHROMA_EXPLE_DICT. 93 | # Remember to reset the hash and others at __first_call == 1, so that you have 94 | # a fresh state for new command. 95 | 96 | # Keep chroma-takever state meaning: until ;, handle highlighting via chroma. 97 | # So the below 8192 assignment takes care that next token will be routed to chroma. 98 | (( next_word = 2 | 8192 )) 99 | 100 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 101 | local __style 102 | integer __idx1 __idx2 103 | 104 | (( __first_call )) && { 105 | # Called for the first time - new command. 106 | # FAST_HIGHLIGHT is used because it survives between calls, and 107 | # allows to use a single global hash only, instead of multiple 108 | # global string variables. 109 | FAST_HIGHLIGHT[chroma-example-counter]=0 110 | 111 | # Set style for region_highlight entry. It is used below in 112 | # '[[ -n "$__style" ]] ...' line, which adds highlight entry, 113 | # like "10 12 fg=green", through `reply' array. 114 | # 115 | # Could check if command `example' exists and set `unknown-token' 116 | # style instead of `command' 117 | __style=${FAST_THEME_NAME}command 118 | 119 | } || { 120 | # Following call, i.e. not the first one 121 | 122 | # Check if chroma should end – test if token is of type 123 | # "starts new command", if so pass-through – chroma ends 124 | [[ "$__arg_type" = 3 ]] && return 2 125 | 126 | if [[ "$__wrd" = -* ]]; then 127 | # Detected option, add style for it. 128 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 129 | __style=${FAST_THEME_NAME}single-hyphen-option 130 | else 131 | # Count non-option tokens 132 | (( FAST_HIGHLIGHT[chroma-example-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-example-counter] )) 133 | 134 | # Colorize 1..2 as builtin, 3.. as glob 135 | if (( FAST_HIGHLIGHT[chroma-example-counter] <= 2 )); then 136 | if [[ "$__wrd" = \"* ]]; then 137 | # Pass through, f-sy-h main code will do the highlight! 138 | return 1 139 | else 140 | __style=${FAST_THEME_NAME}builtin 141 | fi 142 | else 143 | __style=${FAST_THEME_NAME}globbing 144 | fi 145 | fi 146 | } 147 | 148 | # Add region_highlight entry (via `reply' array). 149 | # If 1 will be added to __start_pos, this will highlight "oken". 150 | # If 1 will be subtracted from __end_pos, this will highlight "toke". 151 | # $PREBUFFER is for specific situations when users does command \ 152 | # i.e. when multi-line command using backslash is entered. 153 | # 154 | # This is a common place of adding such entry, but any above code can do 155 | # it itself (and it does in other chromas) and skip setting __style to 156 | # this way disable this code. 157 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 158 | 159 | # We aren't passing-through, do obligatory things ourselves. 160 | # _start_pos=$_end_pos advainces pointers in command line buffer. 161 | (( this_word = next_word )) 162 | _start_pos=$_end_pos 163 | 164 | return 0 165 | ---- 166 | -------------------------------------------------------------------------------- /chroma/-ssh.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # Copyright (C) 2019 by Philippe Troin (F-i-f on GitHub) 5 | # 6 | # Tracks ssh command and emits message when one tries to pass port to hostspec. 7 | # 8 | # $1 - 0 or 1, denoting if it's first call to the chroma, or following one 9 | # 10 | # $2 - the current token, also accessible by $__arg from the above scope - 11 | # basically a private copy of $__arg; the token can be eg.: "grep" 12 | # 13 | # $3 - a private copy of $_start_pos, i.e. the position of the token in the 14 | # command line buffer, used to add region_highlight entry (see man), 15 | # because Zsh colorizes by *ranges* in command line buffer 16 | # 17 | # $4 - a private copy of $_end_pos from the above scope 18 | # 19 | 20 | builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace} 21 | builtin setopt extended_glob warn_create_global typeset_silent no_short_loops rc_quotes no_auto_pushd 22 | 23 | # This chroma guards that port number isn't passed in hostname (no :{port} occurs). 24 | 25 | (( next_word = 2 | 8192 )) 26 | 27 | local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" 28 | local __style check_port=0 host_start_offset host_style user_style possible_host 29 | local -a match mbegin mend completions_users completions_host 30 | 31 | # First call, i.e. command starts, i.e. "grep" token etc. 32 | (( __first_call )) && { 33 | FAST_HIGHLIGHT[chroma-ssh-counter]=0 34 | FAST_HIGHLIGHT[chroma-ssh-counter-all]=1 35 | FAST_HIGHLIGHT[chroma-ssh-message]="" 36 | FAST_HIGHLIGHT[chroma-ssh-skip-two]=0 37 | return 1 38 | } || { 39 | # Following call, i.e. not the first one. 40 | 41 | # Check if chroma should end – test if token is of type 42 | # "starts new command", if so pass-through – chroma ends 43 | [[ "$__arg_type" = 3 ]] && return 2 44 | 45 | if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then 46 | return 1 47 | fi 48 | 49 | (( FAST_HIGHLIGHT[chroma-ssh-counter-all] += 1 )) 50 | 51 | if [[ "$__wrd" = -* ]]; then 52 | # Detected option, add style for it. 53 | [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ 54 | __style=${FAST_THEME_NAME}single-hyphen-option 55 | if [[ "$__wrd" = (-b|-c|-D|-E|-e|-F|-I|-i|-J|-L|-l|-m|-O|-o|-p|Q|R|-S|-W|-w) ]]; then 56 | FAST_HIGHLIGHT[chroma-ssh-skip-two]=1 57 | fi 58 | else 59 | if (( FAST_HIGHLIGHT[chroma-ssh-skip-two] )); then 60 | FAST_HIGHLIGHT[chroma-ssh-skip-two]=0 61 | else 62 | # Count non-option tokens. 63 | (( FAST_HIGHLIGHT[chroma-ssh-counter] += 1 )) 64 | if [[ "${FAST_HIGHLIGHT[chroma-ssh-counter]}" -eq 1 ]]; then 65 | if [[ $__arg = (#b)(([^@]#)(@)|)(*) ]] 66 | then 67 | [[ -n $match[2] ]] \ 68 | && { 69 | user_style= 70 | () { 71 | # Zstyle clobbers reply for sure 72 | zstyle -a ":completion:*:users" users completions_users 73 | } 74 | if (( $#completions_users )); then 75 | [[ $match[2] = ${~${:-(${(j:|:)completions_users})}} ]] \ 76 | && user_style=${FAST_THEME_NAME}correct-subtle \ 77 | || user_style=${FAST_THEME_NAME}incorrect-subtle 78 | elif (( $#userdirs )); then 79 | [[ -n $userdirs[$match[2]] ]] \ 80 | && user_style=${FAST_THEME_NAME}correct-subtle \ 81 | || user_style=${FAST_THEME_NAME}incorrect-subtle 82 | fi 83 | [[ -n $user_style ]] \ 84 | && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}-(mend[5]-mend[2]), __start >= 0 )) \ 85 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$user_style]}") 86 | } 87 | [[ -n $match[3] ]] \ 88 | && (( __start=__start_pos-${#PREBUFFER}+(mbegin[3]-mbegin[1]), __end=__end_pos-${#PREBUFFER}-(mend[5]-mend[3]), __start >= 0 )) \ 89 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subtle-separator]}") 90 | 91 | host_style= 92 | case $match[4] in 93 | (<->|<0-255>.<0-255>.<0-255>.<0-255>) 94 | host_style=${FAST_THEME_NAME}mathnum 95 | check_port=1 96 | ;; 97 | (([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]) 98 | host_style=${FAST_THEME_NAME}mathnum 99 | ;; 100 | (*) 101 | check_port=1 102 | ;; 103 | esac 104 | possible_host=$match[4] 105 | (( host_start_offset = mbegin[4] - mbegin[1], host_end_offset = 0 )) 106 | 107 | if (( check_port )) && [[ $possible_host = (#b)(*)(:[0-9]##) ]]; then 108 | (( __start=__start_pos-${#PREBUFFER}+(host_start_offset+mbegin[2]-mbegin[1]), __end=__end_pos-host_end_offset-${#PREBUFFER}, __start >= 0, 109 | host_end_offset+=mend[2]-mend[1] )) \ 110 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") \ 111 | && possible_host=$match[1] \ 112 | && FAST_HIGHLIGHT[chroma-ssh-message]+="Format of hostname incorrect, use -p to pass port number" 113 | 114 | fi 115 | 116 | if [[ -z $host_style ]]; then 117 | () { 118 | # Zstyle clobbers reply for sure 119 | local mbegin mend match reply 120 | zstyle -a ":completion:*:hosts" hosts completions_host 121 | } 122 | (( ! $#completions_host && $+_cache_hosts )) && completions_host=($_cache_hosts[*]) 123 | if (( $#completions_host )); then 124 | [[ $possible_host = ${~${:-(${(j:|:)completions_host})}} ]] \ 125 | && host_style=${FAST_THEME_NAME}correct-subtle \ 126 | || host_style=${FAST_THEME_NAME}incorrect-subtle 127 | fi 128 | fi 129 | 130 | [[ -n $host_style ]] \ 131 | && (( __start=__start_pos-${#PREBUFFER}+host_start_offset, __end=__end_pos-${#PREBUFFER}-host_end_offset, __start >= 0 )) \ 132 | && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$host_style]}") 133 | else 134 | __style=${FAST_THEME_NAME}incorrect-subtle 135 | fi 136 | 137 | (( next_word = 1 )) 138 | 139 | fi 140 | fi 141 | fi 142 | 143 | if (( ${#${(z)BUFFER}} <= FAST_HIGHLIGHT[chroma-ssh-counter-all] )); then 144 | [[ -n "${FAST_HIGHLIGHT[chroma-ssh-message]}" ]] && zle -M "${FAST_HIGHLIGHT[chroma-ssh-message]}" 145 | fi 146 | } 147 | 148 | # Add region_highlight entry (via `reply' array). 149 | # 150 | # This is a common place of adding such entry, but any above code 151 | # can do it itself and skip setting __style to disable this code. 152 | [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") 153 | 154 | # We aren't passing-through (no return 1 occured), do obligatory things ourselves. 155 | (( this_word = next_word )) 156 | _start_pos=$_end_pos 157 | 158 | return 0 159 | -------------------------------------------------------------------------------- /share/parse/parse.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zsh 2 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 3 | # vim: ft=zsh sw=2 ts=2 et 4 | # 5 | # This file runs the highlighter on a specified file 6 | # i.e. parses the file with the highlighter. Outputs 7 | # running time (stderr) and resulting region_highlight 8 | # (file parse.out, or $2 if given). 9 | # 10 | # Can be also run in line-wise mode on own input (-o 11 | # option in $1), no region_highlight file then. 12 | 13 | 0="${ZERO:-${${0:#$ZSH_ARGZERO}:-${(%):-%N}}}" 14 | 0="${${(M)0:#/*}:-$PWD/$0}" 15 | 16 | ZSH_BIN="$(which zsh)" 17 | SET_FPATH="${0:h}/../../functions" 18 | [[ -z "$FAST_WORK_DIR" ]] && FAST_WORK_DIR="${0:h}" 19 | [[ -z "$ZSH_VERSION" ]] && exec $ZSH_BIN zsh -f -c "source \"$0\" \"$1\" \"$2\" \"$3\"" 20 | 21 | if [[ ! -e "$FAST_WORK_DIR/secondary_theme.zsh" ]]; then 22 | cp -f "${0:A:h}/../free_theme.zsh" "$FAST_WORK_DIR/secondary_theme.zsh" 23 | fi 24 | 25 | if [[ -e "$SET_FPATH/fast-highlight" ]]; then 26 | source "$SET_FPATH/fast-highlight" 27 | source "$SET_FPATH/fast-string-highlight" 28 | fpath+=( "$SET_FPATH" ) 29 | else 30 | print -u2 "Could not find fast-highlight, aborting" 31 | exit 1 32 | fi 33 | 34 | zmodload zsh/zprof 35 | autoload is-at-least chroma/-git.ch 36 | builtin setopt interactive_comments extended_glob typeset_silent no_short_loops rc_quotes no_auto_pushd 37 | 38 | # Own input? 39 | if [[ "$1" = "-o" || "$1" = "-oo" || "$1" = "-ooo" || "$1" = "-git" || "$1" = "-hue" || "$1" = "-hol" ]]; then 40 | typeset -a input 41 | input=() 42 | if [[ "$1" = "-o" ]]; then 43 | input+=( "./parse.zsh ../functions/fast-highlight parse2.out" ) 44 | input+=( "rm -f parse*.out" ) 45 | input+=( "./mh-parse.zsh ../functions/fast-highlight > out" ) 46 | input+=( "if [[ -o multibyte ]]; then echo multibyte is set; fi" ) 47 | input+=( "[[ \"a\" = *[[:alpha:]_-][[:alpha:]]# ]] && echo yes" ) 48 | input+=( 'git tag -a v0.98 -m "Syntax highlighting of the history entries"' ) 49 | input+=( 'func() { echo "a" >! phist2.db; echo "b" >>! phist2.db; fc -Rap "phist2.db"; list=( ${history[@]} ); echo "${history[1]}"; }' ) 50 | (( ${+ZSH_EXECUTION_STRING} == 0 )) && { print -zr "${(F)input}"; return 0; } 51 | elif [[ "$1" = "-oo" ]]; then 52 | input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' ) 53 | input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' ) 54 | input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' ) 55 | input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' ) 56 | input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' ) 57 | input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' ) 58 | input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' ) 59 | (( ${+ZSH_EXECUTION_STRING} == 0 )) && { print -zr "${(F)input}"; return 0; } 60 | elif [[ "$1" = "-ooo" ]]; then 61 | local in=' 62 | # This is an example code that is diverse and allows to test a theme 63 | text="An example quite long string $with variable in it" 64 | local param1="text $variable" param2='"'"'other $variable'"'"' 65 | math=$(( 10 + HISTSIZ + HISTSIZE + $SAVEHIST )) size=$(( 0 )) 66 | 67 | for (( ii = 1; ii <= size; ++ ii )); do 68 | if [[ "${cmds[ii]} string" = "| string" ]] 69 | then 70 | sidx=${buffer[(in:ii:)\$\(?#[^\\\\]\)]} # find opening $( 71 | (( sidx <= len )) && { 72 | eidx=${buffer[(b:sidx:ii)[^\\\\]\)]} # find closing ) 73 | } 74 | fi 75 | done' 76 | (( ${+ZSH_EXECUTION_STRING} == 0 )) && { print -zr "$in"; return 0; } 77 | input+=( "$in" ) 78 | input+=( "$in" ) 79 | elif [[ "$1" = "-git" ]]; then 80 | local in="git lp 81 | git push origin main 82 | git commit 83 | git add safari.ini zdharma.ini 84 | git st . 85 | git diff --cached 86 | git commit --allow-empty 87 | git checkout themes/zdharma.ini 88 | git commit --amend 89 | git commit -m \"Example commit message\" 90 | git tag -a 'v1.18' -m 'Here-string is highlighted, descriptor-variables passed to exec are correctly highlighted' 91 | git tag -l -n9 92 | git checkout cb66b11 93 | " 94 | (( ${+ZSH_EXECUTION_STRING} == 0 )) && { print -zr "$in"; return 0; } 95 | input+=( "$in" ) 96 | input+=( "$in" ) 97 | elif [[ "$1" = "-hue" ]]; then 98 | local in="var=\$other; local var=\$other 99 | () { eval \"\$var\"; } 100 | case \$other in 101 | \$var) 102 | ( echo OK; ) 103 | ;; 104 | esac 105 | sudo -i -s ls -1 /var/log 106 | () { ( eval \"command ls -1\" ); } argument" 107 | 108 | (( ${+ZSH_EXECUTION_STRING} == 0 )) && { print -zr "$in"; return 0; } 109 | 110 | input+=( "$in" "$in" ) 111 | elif [[ "$1" = "-hol" ]]; then 112 | local in="var=\$( other ) 113 | local var2=\$(( other + 1 )) 114 | () { eval \"\$var\"; } 115 | sudo -i -s ls -1 >/tmp/ls-log.txt /var/log 116 | IFS=\$'\\n' print -rl -- \$(command ls -1 | tee -a /tmp/ls-1.txt) 117 | var3=\$(( HISTSIZE + 10 + \$var )) 118 | local var4=\$( other command ) 119 | touch \$(( HISTSIZE + \$SAVEHIST + 10 )) 120 | case \$other in 121 | \$var) 122 | ( echo OK; ) 123 | ;; 124 | \$var3) 125 | ( if { true } { noglob echo yes } ) 126 | esac 127 | ( builtin cd /var/log; ls -1; noglob cd \"/var/log\" 'log' ) 128 | noglob cat <<<\"\$PATH\" | tr : \"\\n\" 129 | if [[ \"\$var\" -gt 10 ]]; then 130 | (( var = HISTSIZE + \$SAVEHIST )) 131 | fi 132 | /var/log 133 | sidx=\${buffer[(in:ii:)\\\$\\(?#[^\\\\\\\\]\\)]} # find opening cmd-subst 134 | { 135 | exec {MYFD}<&0 {MYFD2}>&1 136 | ( read <&\$MYFD line; echo \$line >&\$MYFD2 && { builtin print \${match[1]}Written. } ) 137 | } always { 138 | (( MYFD > 0 )) && { print -rl -- -myfd:\$MYFD >&\$MYFD2 && print \"Sent.\" '(to filedescriptor)'; } 139 | } 140 | command sleep \"\$(( \$a + b + \${cde} + \${(s::)fgh[ijk]} + \\\$l + \\m + \\\" ))\" 141 | for (( i = 0; i <= 2; ++ i )) { print \$i; } 142 | " 143 | 144 | (( ${+ZSH_EXECUTION_STRING} == 0 )) && { print -zr "$in"; return 0; } 145 | 146 | input+=( "$in" ) 147 | fi 148 | 149 | typeset -a long_input 150 | integer i 151 | for (( i=1; i<= 50; i ++ )); do 152 | long_input+=( "${input[@]}" ) 153 | done 154 | 155 | typeset -F SECONDS 156 | SECONDS=0 157 | 158 | local right_brace_is_recognised_everywhere 159 | integer path_dirs_was_set multi_func_def ointeractive_comments 160 | -fast-highlight-fill-option-variables 161 | 162 | local BUFFER 163 | for BUFFER in "${long_input[@]}"; do 164 | reply=( ) 165 | () { 166 | -fast-highlight-init 167 | -fast-highlight-process "" "$BUFFER" "0" 168 | -fast-highlight-string-process "" "$BUFFER" 169 | } 170 | done 171 | 172 | print "Running time: $SECONDS" 173 | zprof | head 174 | # File input? 175 | elif [[ -r "$1" ]]; then 176 | # Load from given file 177 | local BUFFER="$(<$1)" 178 | 179 | typeset -F SECONDS 180 | SECONDS=0 181 | 182 | reply=( ) 183 | -fast-highlight-init 184 | 185 | local right_brace_is_recognised_everywhere 186 | integer path_dirs_was_set multi_func_def ointeractive_comments 187 | -fast-highlight-fill-option-variables 188 | 189 | () { 190 | -fast-highlight-process "" "$BUFFER" "0" 191 | -fast-highlight-string-process "" "$BUFFER" 192 | } 193 | 194 | print "Running time: $SECONDS" 195 | zprof | head 196 | 197 | # This output can be diffed to detect changes in operation 198 | if [[ -z "$2" ]]; then 199 | print -rl -- "${reply[@]}" >! out.parse 200 | else 201 | print -rl -- "${reply[@]}" >! "$2" 202 | fi 203 | else 204 | if [[ -z "$1" ]]; then 205 | print -u2 "Usage: fast-parse {to-parse file} [region_highlight output file]" 206 | exit 2 207 | else 208 | print -u2 "Unreadable to-parse file \`$1', aborting" 209 | exit 3 210 | fi 211 | fi 212 | 213 | exit 0 214 | -------------------------------------------------------------------------------- /chroma/-zi.ch: -------------------------------------------------------------------------------- 1 | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- 2 | # vim: ft=zsh sw=2 ts=2 et 3 | # 4 | # Chroma function for command `zi'. It colorizes the part of command line that holds `zi' invocation. 5 | 6 | (( FAST_HIGHLIGHT[-zi.ch-chroma-def] )) && return 1 7 | 8 | FAST_HIGHLIGHT[-zi.ch-chroma-def]=1 9 | 10 | typeset -gA fsh__zi__chroma__def 11 | fsh__zi__chroma__def=( 12 | ## 13 | ## No subcommand 14 | ## 15 | ## {{{ 16 | 17 | subcmd:NULL "NULL_0_opt" 18 | NULL_0_opt "(-help|--help|-h) 19 | <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" 20 | "subcommands" "(help|subcmds|icemods|analytics|man|self-update|times|zstatus|load|light|unload|snippet|ls|ice||update|status|report|delete|loaded|list|cd|create|edit|glance|stress|changes|recently|clist|completions|cclear|cdisable|cenable|creinstall|cuninstall|csearch|compinit|dtrace|dstart|dstop|dunload|dreport|dclear|compile|uncompile|compiled|cdlist|cdreplay|cdclear|srv|recall|env-whitelist|bindkeys|module|add-fpath|run)" 21 | 22 | ## }}} 23 | 24 | # Generic actions 25 | NO_MATCH_\#_opt "* <<>> __style=\${FAST_THEME_NAME}incorrect-subtle // NO-OP" 26 | NO_MATCH_\#_arg "__style=\${FAST_THEME_NAME}incorrect-subtle // NO-OP" 27 | 28 | 29 | ## 30 | ## `ice' 31 | ## 32 | ## {{{ 33 | 34 | subcmd:ice "ICE_#_arg // NO_MATCH_#_opt" 35 | 36 | "ICE_#_arg" "NO-OP // ::chroma/-zi-check-ice-mod" 37 | 38 | ## 39 | ## `snippet' 40 | ## 41 | ## {{{ 42 | 43 | subcmd:snippet "SNIPPET_0_opt // SNIPPET_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 44 | 45 | SNIPPET_0_opt "(-h|--help|-f|--force|--command|-x) 46 | <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" 47 | 48 | SNIPPET_1_arg "NO-OP // ::chroma/-zi-verify-snippet" 49 | 50 | ## }}} 51 | 52 | ## 53 | ## `load' 54 | ## 55 | ## {{{ 56 | 57 | "subcmd:load" "LOAD_1_arg // LOAD_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 58 | 59 | LOAD_1_arg "NO-OP // ::chroma/-zi-verify-plugin" 60 | 61 | LOAD_2_arg "NO-OP // ::chroma/-zi-verify-plugin" 62 | 63 | ## }}} 64 | 65 | ## 66 | ## `compile|uncompile|stress|edit|glance|recall|status|cd|changes` 67 | ## 68 | ## {{{ 69 | 70 | "subcmd:(compile|uncompile|stress|edit|glance|recall|status|cd|changes)" 71 | "PLGSNP_1_arg // PLGSNP_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 72 | 73 | PLGSNP_1_arg "NO-OP // ::chroma/-zi-verify-plugin-or-snippet" 74 | 75 | PLGSNP_2_arg "NO-OP // ::chroma/-zi-verify-plugin-or-snippet" 76 | 77 | ## }}} 78 | 79 | ## 80 | ## `update' 81 | ## 82 | ## {{{ 83 | 84 | subcmd:update "UPDATE_0_opt // PLGSNP_1_arg // PLGSNP_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 85 | 86 | UPDATE_0_opt " 87 | (-L|--plugins|-s|--snippets|-p|--parallel|-a|--all|-q|--quiet|-r|--reset|-u|--urge|-n|--no-pager|-v|--verbose|-h|--help) 88 | <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" 89 | 90 | ## }}} 91 | 92 | ## 93 | ## `light' 94 | ## 95 | ## {{{ 96 | 97 | subcmd:light "LIGHT_0_opt // LOAD_1_arg // LOAD_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 98 | 99 | LIGHT_0_opt "-h|--help|-b 100 | <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" 101 | 102 | ## }}} 103 | 104 | ## 105 | ## `unload' 106 | ## 107 | ## {{{ 108 | 109 | subcmd:unload "UNLOAD_0_opt // UNLOAD_1_arg // UNLOAD_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 110 | 111 | UNLOAD_0_opt "-h|--help|-q|--quiet 112 | <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" 113 | 114 | UNLOAD_1_arg "NO-OP // ::chroma/-zi-verify-loaded-plugin" 115 | 116 | UNLOAD_2_arg "NO-OP // ::chroma/-zi-verify-loaded-plugin" 117 | 118 | ## }}} 119 | 120 | ## 121 | ## `report' 122 | ## 123 | ## {{{ 124 | 125 | subcmd:report "REPORT_0_opt // UNLOAD_1_arg // UNLOAD_2_arg // NO_MATCH_#_opt // 126 | NO_MATCH_#_arg" 127 | 128 | REPORT_0_opt "--all 129 | <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" 130 | 131 | ## }}} 132 | 133 | ## 134 | ## `delete' 135 | ## 136 | ## {{{ 137 | 138 | "subcmd:delete" 139 | "DELETE_0_opt // PLGSNP_1_arg // PLGSNP_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 140 | 141 | DELETE_0_opt " 142 | (-a|--all|-c|--clean|-y|--yes|-q|--quiet|-h|--help) 143 | <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" 144 | 145 | ## }}} 146 | 147 | ## 148 | ## `cenable' 149 | ## 150 | ## {{{ 151 | 152 | subcmd:cenable "COMPLETION_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 153 | 154 | COMPLETION_1_arg "NO-OP // ::chroma/-zi-verify-disabled-completion" 155 | 156 | ## }}} 157 | 158 | ## 159 | ## `cdisable' 160 | ## 161 | ## {{{ 162 | 163 | subcmd:cdisable "DISCOMPLETION_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 164 | 165 | DISCOMPLETION_1_arg "NO-OP // ::chroma/-zi-verify-completion" 166 | 167 | ## }}} 168 | 169 | 170 | ## 171 | ## `uncompile' 172 | ## 173 | ## {{{ 174 | 175 | subcmd:uncompile "UNCOMPILE_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" 176 | 177 | UNCOMPILE_1_arg "NO-OP // ::chroma/-zi-verify-compiled-plugin" 178 | 179 | ## }}} 180 | 181 | ## 182 | ## `*' 183 | ## 184 | ## {{{ 185 | 186 | "subcmd:*" "CATCH_ALL_#_opt" 187 | "CATCH_ALL_#_opt" "* <<>> NO-OP // ::chroma/main-chroma-std-aopt-SEMI-action" 188 | 189 | ## }}} 190 | ) 191 | 192 | #chroma/-zi-first-call() { 193 | # This is being done in the proper place - in -fast-highlight-process 194 | #FAST_HIGHLIGHT[chroma-zi-ice-elements-svn]=0 195 | #} 196 | 197 | chroma/-zi-verify-plugin() { 198 | local _scmd="$1" _wrd="$4" 199 | 200 | [[ -d "$_wrd" ]] && { __style=${FAST_THEME_NAME}correct-subtle; return 0; } 201 | 202 | typeset -a plugins 203 | plugins=( "${ZI[PLUGINS_DIR]}"/*(N:t) ) 204 | plugins=( "${plugins[@]//---//}" ) 205 | plugins=( "${plugins[@]:#_local/zi}" ) 206 | plugins=( "${plugins[@]:#custom}" ) 207 | 208 | [[ -n "${plugins[(r)$_wrd]}" ]] && __style=${FAST_THEME_NAME}correct-subtle || return 1 209 | #__style=${FAST_THEME_NAME}incorrect-subtle 210 | return 0 211 | } 212 | 213 | chroma/-zi-verify-plugin-or-snippet() { 214 | chroma/-zi-verify-plugin "$1" "" "" "$4" || chroma/-zi-verify-snippet "$1" "" "" "$4" 215 | return $? 216 | } 217 | 218 | chroma/-zi-verify-loaded-plugin() { 219 | local _scmd="$1" _wrd="$4" 220 | typeset -a plugins absolute1 absolute2 absolute3 normal 221 | plugins=( "${ZI_REGISTERED_PLUGINS[@]:#_local/zi}" ) 222 | normal=( "${plugins[@]:#%*}" ) 223 | absolute1=( "${(M)plugins[@]:#%*}" ) 224 | absolute1=( "${absolute1[@]/\%\/\//%/}" ) 225 | local hm="${HOME%/}" 226 | absolute2=( "${absolute1[@]/$hm/HOME}" ) 227 | absolute3=( "${absolute1[@]/\%/}" ) 228 | plugins=( $absolute1 $absolute2 $absolute3 $normal ) 229 | 230 | [[ -n "${plugins[(r)$_wrd]}" ]] && \ 231 | __style=${FAST_THEME_NAME}correct-subtle || \ 232 | return 1 233 | #__style=${FAST_THEME_NAME}incorrect-subtle 234 | 235 | return 0 236 | } 237 | 238 | chroma/-zi-verify-completion() { 239 | local _scmd="$1" _wrd="$4" 240 | # Find enabled completions 241 | typeset -a completions 242 | completions=( "${ZI[COMPLETIONS_DIR]}"/_*(N:t) ) 243 | completions=( "${completions[@]#_}" ) 244 | 245 | [[ -n "${completions[(r)${_wrd#_}]}" ]] && \ 246 | __style=${FAST_THEME_NAME}correct-subtle || \ 247 | return 1 248 | 249 | return 0 250 | } 251 | 252 | chroma/-zi-verify-disabled-completion() { 253 | local _scmd="$1" _wrd="$4" 254 | # Find enabled completions 255 | typeset -a completions 256 | completions=( "${ZI[COMPLETIONS_DIR]}"/[^_]*(N:t) ) 257 | 258 | [[ -n "${completions[(r)${_wrd#_}]}" ]] && \ 259 | __style=${FAST_THEME_NAME}correct-subtle || \ 260 | return 1 261 | 262 | return 0 263 | } 264 | 265 | chroma/-zi-verify-compiled-plugin() { 266 | local _scmd="$1" _wrd="$4" 267 | 268 | typeset -a plugins 269 | plugins=( "${ZI[PLUGINS_DIR]}"/*(N) ) 270 | 271 | typeset -a show_plugins p matches 272 | for p in "${plugins[@]}"; do 273 | matches=( $p/*.zwc(N) ) 274 | if [ "$#matches" -ne "0" ]; then 275 | p="${p:t}" 276 | [[ "$p" = (_local---zi|custom) ]] && continue 277 | p="${p//---//}" 278 | show_plugins+=( "$p" ) 279 | fi 280 | done 281 | 282 | [[ -n "${show_plugins[(r)$_wrd]}" ]] && \ 283 | { __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \ 284 | return 1 285 | } 286 | 287 | chroma/-zi-verify-snippet() { 288 | local _scmd="$1" url="$4" dirname local_dir 289 | url="${${url#"${url%%[! $'\t']*}"}%/}" 290 | id_as="${FAST_HIGHLIGHT[chroma-zi-ice-elements-id-as]:-${ZI_ICE[id-as]:-$url}}" 291 | 292 | filename="${${id_as%%\?*}:t}" 293 | dirname="${${id_as%%\?*}:t}" 294 | local_dir="${${${id_as%%\?*}:h}/:\/\//--}" 295 | [[ "$local_dir" = "." ]] && local_dir="" || local_dir="${${${${${local_dir#/}//\//--}//=/--EQ--}//\?/--QM--}//\&/--AMP--}" 296 | local_dir="${ZI[SNIPPETS_DIR]}${local_dir:+/$local_dir}" 297 | 298 | (( ${+ZI_ICE[svn]} || ${FAST_HIGHLIGHT[chroma-zi-ice-elements-svn]} )) && { 299 | # TODO: #11 handle the SVN path's specifics 300 | [[ -d "$local_dir/$dirname" ]] && \ 301 | { __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \ 302 | return 1 303 | } || { 304 | # TODO: #12 handle the non-SVN path's specifics 305 | [[ -d "$local_dir/$dirname" ]] && \ 306 | { __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \ 307 | return 1 308 | } 309 | } 310 | 311 | chroma/-zi-check-ice-mod() { 312 | local _scmd="$1" _wrd="$4" 313 | [[ "$_wrd" = (svn(\'|\")*|svn) ]] && FAST_HIGHLIGHT[chroma-zi-ice-elements-svn]=1 314 | [[ "$_wrd" = (#b)(id-as(:|)(\'|\")(*)(\'|\")|id-as:(*)|id-as(*)) ]] && \ 315 | FAST_HIGHLIGHT[chroma-zi-ice-elements-id-as]="${match[4]}${match[6]}${match[7]}" 316 | 317 | # .zi-recall 318 | local -a ice_order nval_ices ext_val_ices 319 | ext_val_ices=( ${(@)${(@Akons:|:u)${ZI_EXTS[ice-mods]//\'\'/}}/(#s)<->-/} ) 320 | 321 | ice_order=( 322 | ${${(s.|.)ZI[ice-list]}} 323 | # Include all additional ices – after stripping them from the possible: '' 324 | ${(@)${(@Akons:|:u)${ZI_EXTS[ice-mods]//\'\'/}}/(#s)<->-/} 325 | ) 326 | nval_ices=( 327 | ${(s.|.)ZI[nval-ice-list]} 328 | # Include only those additional ices, 329 | # don't have the '' in their name, i.e. aren't designed to hold value 330 | ${(@)${(@)${(@Akons:|:u)${ZI_EXTS[ice-mods]//\'\'/}}/(#s)<->-/}} 331 | # Must be last 332 | svn 333 | ) 334 | 335 | if [[ "$_wrd" = (#b)(${(~j:|:)${ice_order[@]:#(${(~j:|:)nval_ices[@]:#(${(~j:|:)ext_val_ices[@]})})}})(*) ]]; then 336 | reply+=("$(( __start )) $(( __start+${mend[1]} )) ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-hyphen-option]}") 337 | reply+=("$(( __start+${mbegin[2]} )) $(( __end )) ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}optarg-string]}") 338 | -fast-highlight-string 339 | return 0 340 | elif [[ "$_wrd" = (#b)(${(~j:|:)nval_ices[@]}) ]]; then 341 | __style=${FAST_THEME_NAME}single-hyphen-option 342 | return 0 343 | else 344 | __style=${FAST_THEME_NAME}incorrect-subtle 345 | return 1 346 | fi 347 | } 348 | 349 | return 0 350 | --------------------------------------------------------------------------------