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.

72 lines
2.6 KiB

  1. # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
  2. # Copyright (c) 2018 Sebastian Gniazdowski
  3. #
  4. # Chroma function for `sh' shell. It colorizes string passed with -c option.
  5. #
  6. # $1 - 0 or 1, denoting if it's first call to the chroma, or following one
  7. # $2 - the current token, also accessible by $__arg from the above scope -
  8. # basically a private copy of $__arg
  9. # $3 - a private copy of $_start_pos, i.e. the position of the token in the
  10. # command line buffer, used to add region_highlight entry (see man),
  11. # because Zsh colorizes by *ranges* in command line buffer
  12. # $4 - a private copy of $_end_pos from the above scope
  13. #
  14. (( next_word = 2 | 8192 ))
  15. local __first_call=$1 __wrd=$2 __start_pos=$3 __end_pos=$4
  16. local __style
  17. integer __idx1 __idx2
  18. local -a __lines_list
  19. (( __first_call )) && {
  20. # Called for the first time - new command
  21. FAST_HIGHLIGHT[chrome-git-got-c]=0
  22. return 1
  23. } || {
  24. # Following call, i.e. not the first one
  25. # Check if chroma should end – test if token is of type
  26. # "starts new command", if so pass-through – chroma ends
  27. [[ $__arg_type = 3 ]] && return 2
  28. if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
  29. return 1
  30. fi
  31. __wrd=${${${(Q)__wrd}#[\"\']}%[\"\']}
  32. if [[ $__wrd = -* && $__wrd != -*c* ]]; then
  33. __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option}
  34. else
  35. if (( FAST_HIGHLIGHT[chrome-git-got-c] == 1 )); then
  36. for (( __idx1 = 1, __idx2 = 1; __idx2 <= __asize; ++ __idx1 )); do
  37. [[ ${__arg[__idx2]} = ${__wrd[__idx1]} ]] && break
  38. while [[ ${__arg[__idx2]} != ${__wrd[__idx1]} ]]; do
  39. (( ++ __idx2 ))
  40. (( __idx2 > __asize )) && { __idx2=0; break; }
  41. done
  42. (( __idx2 == 0 )) && break
  43. [[ ${__arg[__idx2]} = ${__wrd[__idx1]} ]] && break
  44. done
  45. FAST_HIGHLIGHT[chrome-git-got-c]=0
  46. (( _start_pos-__PBUFLEN >= 0 )) && \
  47. -fast-highlight-process "$PREBUFFER" "${__wrd}" "$(( __start_pos + __idx2 - 1 ))"
  48. elif [[ $__wrd = -*c* ]]; then
  49. FAST_HIGHLIGHT[chrome-git-got-c]=1
  50. else
  51. return 1
  52. fi
  53. fi
  54. }
  55. # Add region_highlight entry (via `reply' array)
  56. [[ -n $__style ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
  57. # We aren't passing-through, do obligatory things ourselves
  58. (( this_word = next_word ))
  59. _start_pos=$_end_pos
  60. return 0
  61. # vim:ft=zsh:et:sw=4