You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

378 lines
11 KiB

  1. # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
  2. # Copyright (c) 2018-2019 Sebastian Gniazdowski
  3. #
  4. # Chroma function for command `git'. It colorizes the part of command
  5. # line that holds `git' invocation.
  6. (( FAST_HIGHLIGHT[-zinit.ch-chroma-def] )) && return 1
  7. FAST_HIGHLIGHT[-zinit.ch-chroma-def]=1
  8. typeset -gA fsh__zinit__chroma__def
  9. fsh__zinit__chroma__def=(
  10. ##
  11. ## No subcommand
  12. ##
  13. ## {{{
  14. subcmd:NULL "NULL_0_opt"
  15. NULL_0_opt "(-help|--help|-h)
  16. <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
  17. "subcommands" "(help|man|self-update|cd|times|zstatus|load|light|unload|snippet|ls|ice|<ice|specification>|update|status|report|delete|loaded|list|cd|create|edit|glance|stress|changes|recently|clist|completions|cdisable|cname|cenable|cname|creinstall|cuninstall|csearch|compinit|dtrace|dstart|dstop|dunload|dreport|dclear|compile|uncompile|compiled|cdlist|cdreplay|cdclear|srv|recall|env-whitelist|bindkeys|module)"
  18. ## }}}
  19. # Generic actions
  20. NO_MATCH_\#_opt "* <<>> __style=\${FAST_THEME_NAME}incorrect-subtle // NO-OP"
  21. NO_MATCH_\#_arg "__style=\${FAST_THEME_NAME}incorrect-subtle // NO-OP"
  22. ##
  23. ## `ice'
  24. ##
  25. ## {{{
  26. subcmd:ice "ICE_#_arg // NO_MATCH_#_opt"
  27. "ICE_#_arg" "NO-OP // ::→chroma/-zinit-check-ice-mod"
  28. ## }}}
  29. ##
  30. ## `snippet'
  31. ##
  32. ## {{{
  33. subcmd:snippet "SNIPPET_0_opt // SNIPPET_1_arg // NO_MATCH_#_opt //
  34. NO_MATCH_#_arg"
  35. SNIPPET_0_opt "(-f|--command)
  36. <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
  37. SNIPPET_1_arg "NO-OP // ::→chroma/-zinit-verify-snippet"
  38. ## }}}
  39. ##
  40. ## `load'
  41. ##
  42. ## {{{
  43. "subcmd:load"
  44. "LOAD_1_arg // LOAD_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg"
  45. LOAD_1_arg "NO-OP // ::→chroma/-zinit-verify-plugin"
  46. LOAD_2_arg "NO-OP // ::→chroma/-zinit-verify-plugin"
  47. ## }}}
  48. ##
  49. ## `compile|uncompile|stress|edit|glance|recall|status|cd|changes`
  50. ##
  51. ## {{{
  52. "subcmd:(compile|uncompile|stress|edit|glance|recall|status|cd|changes)"
  53. "PLGSNP_1_arg // PLGSNP_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg"
  54. PLGSNP_1_arg "NO-OP // ::→chroma/-zinit-verify-plugin-or-snippet"
  55. PLGSNP_2_arg "NO-OP // ::→chroma/-zinit-verify-plugin-or-snippet"
  56. ## }}}
  57. ##
  58. ## `update'
  59. ##
  60. ## {{{
  61. subcmd:update "UPDATE_0_opt // PLGSNP_1_arg // PLGSNP_2_arg //
  62. NO_MATCH_#_opt // NO_MATCH_#_arg"
  63. UPDATE_0_opt "
  64. (--all|-r|--reset|-q|--quiet|-p|--parallel)
  65. <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
  66. ## }}}
  67. ##
  68. ## `light'
  69. ##
  70. ## {{{
  71. subcmd:light "LIGHT_0_opt // LOAD_1_arg // LOAD_2_arg // NO_MATCH_#_opt //
  72. NO_MATCH_#_arg"
  73. LIGHT_0_opt "-b
  74. <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
  75. ## }}}
  76. ##
  77. ## `unload'
  78. ##
  79. ## {{{
  80. subcmd:unload "UNLOAD_0_opt // UNLOAD_1_arg // UNLOAD_2_arg // NO_MATCH_#_opt //
  81. NO_MATCH_#_arg"
  82. UNLOAD_0_opt "-q
  83. <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
  84. UNLOAD_1_arg "NO-OP // ::→chroma/-zinit-verify-loaded-plugin"
  85. UNLOAD_2_arg "NO-OP // ::→chroma/-zinit-verify-loaded-plugin"
  86. ## }}}
  87. ##
  88. ## `report'
  89. ##
  90. ## {{{
  91. subcmd:report "REPORT_0_opt // UNLOAD_1_arg // UNLOAD_2_arg // NO_MATCH_#_opt //
  92. NO_MATCH_#_arg"
  93. REPORT_0_opt "--all
  94. <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
  95. ## }}}
  96. ##
  97. ## `delete'
  98. ##
  99. ## {{{
  100. "subcmd:delete"
  101. "DELETE_0_opt // PLGSNP_1_arg // PLGSNP_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg"
  102. DELETE_0_opt "
  103. (--all|--clean|-y|--yes|-q|--quiet)
  104. <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action"
  105. ## }}}
  106. ##
  107. ## `cenable'
  108. ##
  109. ## {{{
  110. subcmd:cenable "COMPLETION_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg"
  111. COMPLETION_1_arg "NO-OP // ::→chroma/-zinit-verify-disabled-completion"
  112. ## }}}
  113. ##
  114. ## `cdisable'
  115. ##
  116. ## {{{
  117. subcmd:cdisable "DISCOMPLETION_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg"
  118. DISCOMPLETION_1_arg "NO-OP // ::→chroma/-zinit-verify-completion"
  119. ## }}}
  120. ##
  121. ## `light'
  122. ##
  123. ## {{{
  124. subcmd:uncompile "UNCOMPILE_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg"
  125. UNCOMPILE_1_arg "NO-OP // ::→chroma/-zinit-verify-compiled-plugin"
  126. ## }}}
  127. ##
  128. ## `*'
  129. ##
  130. ## {{{
  131. "subcmd:*" "CATCH_ALL_#_opt"
  132. "CATCH_ALL_#_opt" "* <<>> NO-OP // ::→chroma/main-chroma-std-aopt-SEMI-action"
  133. ## }}}
  134. )
  135. #→chroma/-zinit-first-call() {
  136. # This is being done in the proper place - in -fast-highlight-process
  137. #FAST_HIGHLIGHT[chroma-zinit-ice-elements-svn]=0
  138. #}
  139. →chroma/-zinit-verify-plugin() {
  140. local _scmd="$1" _wrd="$4"
  141. [[ -d "$_wrd" ]] && \
  142. { __style=${FAST_THEME_NAME}correct-subtle; return 0; }
  143. typeset -a plugins
  144. plugins=( "${ZINIT[PLUGINS_DIR]}"/*(N:t) )
  145. plugins=( "${plugins[@]//---//}" )
  146. plugins=( "${plugins[@]:#_local/zinit}" )
  147. plugins=( "${plugins[@]:#custom}" )
  148. [[ -n "${plugins[(r)$_wrd]}" ]] && \
  149. __style=${FAST_THEME_NAME}correct-subtle || \
  150. return 1
  151. #__style=${FAST_THEME_NAME}incorrect-subtle
  152. return 0
  153. }
  154. →chroma/-zinit-verify-plugin-or-snippet() {
  155. →chroma/-zinit-verify-plugin "$1" "" "" "$4" || \
  156. →chroma/-zinit-verify-snippet "$1" "" "" "$4"
  157. return $?
  158. }
  159. →chroma/-zinit-verify-loaded-plugin() {
  160. local _scmd="$1" _wrd="$4"
  161. typeset -a plugins absolute1 absolute2 absolute3 normal
  162. plugins=( "${ZINIT_REGISTERED_PLUGINS[@]:#_local/zinit}" )
  163. normal=( "${plugins[@]:#%*}" )
  164. absolute1=( "${(M)plugins[@]:#%*}" )
  165. absolute1=( "${absolute1[@]/\%\/\//%/}" )
  166. local hm="${HOME%/}"
  167. absolute2=( "${absolute1[@]/$hm/HOME}" )
  168. absolute3=( "${absolute1[@]/\%/}" )
  169. plugins=( $absolute1 $absolute2 $absolute3 $normal )
  170. [[ -n "${plugins[(r)$_wrd]}" ]] && \
  171. __style=${FAST_THEME_NAME}correct-subtle || \
  172. return 1
  173. #__style=${FAST_THEME_NAME}incorrect-subtle
  174. return 0
  175. }
  176. →chroma/-zinit-verify-completion() {
  177. local _scmd="$1" _wrd="$4"
  178. # Find enabled completions
  179. typeset -a completions
  180. completions=( "${ZINIT[COMPLETIONS_DIR]}"/_*(N:t) )
  181. completions=( "${completions[@]#_}" )
  182. [[ -n "${completions[(r)${_wrd#_}]}" ]] && \
  183. __style=${FAST_THEME_NAME}correct-subtle || \
  184. return 1
  185. return 0
  186. }
  187. →chroma/-zinit-verify-disabled-completion() {
  188. local _scmd="$1" _wrd="$4"
  189. # Find enabled completions
  190. typeset -a completions
  191. completions=( "${ZINIT[COMPLETIONS_DIR]}"/[^_]*(N:t) )
  192. [[ -n "${completions[(r)${_wrd#_}]}" ]] && \
  193. __style=${FAST_THEME_NAME}correct-subtle || \
  194. return 1
  195. return 0
  196. }
  197. →chroma/-zinit-verify-compiled-plugin() {
  198. local _scmd="$1" _wrd="$4"
  199. typeset -a plugins
  200. plugins=( "${ZINIT[PLUGINS_DIR]}"/*(N) )
  201. typeset -a show_plugins p matches
  202. for p in "${plugins[@]}"; do
  203. matches=( $p/*.zwc(N) )
  204. if [ "$#matches" -ne "0" ]; then
  205. p="${p:t}"
  206. [[ "$p" = (_local---zinit|custom) ]] && continue
  207. p="${p//---//}"
  208. show_plugins+=( "$p" )
  209. fi
  210. done
  211. [[ -n "${show_plugins[(r)$_wrd]}" ]] && \
  212. { __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \
  213. return 1
  214. }
  215. →chroma/-zinit-verify-snippet() {
  216. local _scmd="$1" url="$4" dirname local_dir
  217. url="${${url#"${url%%[! $'\t']*}"}%/}"
  218. id_as="${FAST_HIGHLIGHT[chroma-zinit-ice-elements-id-as]:-${ZINIT_ICE[id-as]:-$url}}"
  219. filename="${${id_as%%\?*}:t}"
  220. dirname="${${id_as%%\?*}:t}"
  221. local_dir="${${${id_as%%\?*}:h}/:\/\//--}"
  222. [[ "$local_dir" = "." ]] && local_dir="" || local_dir="${${${${${local_dir#/}//\//--}//=/--EQ--}//\?/--QM--}//\&/--AMP--}"
  223. local_dir="${ZINIT[SNIPPETS_DIR]}${local_dir:+/$local_dir}"
  224. (( ${+ZINIT_ICE[svn]} || ${FAST_HIGHLIGHT[chroma-zinit-ice-elements-svn]} )) && {
  225. # TODO: handle the SVN path's specifics
  226. [[ -d "$local_dir/$dirname" ]] && \
  227. { __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \
  228. return 1
  229. } || {
  230. # TODO: handle the non-SVN path's specifics
  231. [[ -d "$local_dir/$dirname" ]] && \
  232. { __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \
  233. return 1
  234. }
  235. }
  236. →chroma/-zinit-check-ice-mod() {
  237. local _scmd="$1" _wrd="$4"
  238. [[ "$_wrd" = (svn(\'|\")*|svn) ]] && \
  239. FAST_HIGHLIGHT[chroma-zinit-ice-elements-svn]=1
  240. [[ "$_wrd" = (#b)(id-as(:|)(\'|\")(*)(\'|\")|id-as:(*)|id-as(*)) ]] && \
  241. FAST_HIGHLIGHT[chroma-zinit-ice-elements-id-as]="${match[4]}${match[6]}${match[7]}"
  242. # Copy from zinit-autoload.zsh / -zplg-recall
  243. local -a ice_order nval_ices ext_val_ices
  244. ext_val_ices=( ${(@)${(@Ms.|.)ZINIT_EXTS[ice-mods]:#*\'\'*}//\'\'/} )
  245. ice_order=(
  246. svn proto from teleid bindmap cloneopts id-as depth if wait load
  247. unload blockf pick bpick src as ver silent lucid notify mv cp
  248. atinit atclone atload atpull nocd run-atpull has cloneonly make
  249. service trackbinds multisrc compile nocompile nocompletions
  250. reset-prompt wrap-track reset sh \!sh bash \!bash ksh \!ksh csh
  251. \!csh aliases countdown ps-on-unload ps-on-update trigger-load
  252. light-mode is-snippet atdelete pack git verbose on-update-of
  253. subscribe param extract
  254. # Include all additional ices – after
  255. # stripping them from the possible: ''
  256. ${(@s.|.)${ZINIT_EXTS[ice-mods]//\'\'/}}
  257. )
  258. nval_ices=(
  259. blockf silent lucid trackbinds cloneonly nocd run-atpull
  260. nocompletions sh \!sh bash \!bash ksh \!ksh csh \!csh
  261. aliases countdown light-mode is-snippet git verbose
  262. # Include only those additional ices,
  263. # don't have the '' in their name, i.e.
  264. # aren't designed to hold value
  265. ${(@)${(@s.|.)ZINIT_EXTS[ice-mods]}:#*\'\'*}
  266. # Must be last
  267. svn
  268. )
  269. if [[ "$_wrd" = (#b)(${(~j:|:)${ice_order[@]:#(${(~j:|:)nval_ices[@]:#(${(~j:|:)ext_val_ices[@]})})}})(*) ]]; then
  270. reply+=("$(( __start )) $(( __start+${mend[1]} )) ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-hyphen-option]}")
  271. reply+=("$(( __start+${mbegin[2]} )) $(( __end )) ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}optarg-string]}")
  272. -fast-highlight-string
  273. return 0
  274. elif [[ "$_wrd" = (#b)(${(~j:|:)nval_ices[@]}) ]]; then
  275. __style=${FAST_THEME_NAME}single-hyphen-option
  276. return 0
  277. else
  278. __style=${FAST_THEME_NAME}incorrect-subtle
  279. return 1
  280. fi
  281. }
  282. return 0
  283. # vim:ft=zsh:et:sw=4