feaee0446468798b9a9411dc5ea5f957c19b87a0

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Resolving conflict in README after recent updates for colorize plugin

Diff

  1diff --git a/plugins/colorize/README.md b/plugins/colorize/README.md
  2index 036724a1acf51ab4c3578e23488c2f7bb6b58943..d374430116d26f3332dfb109e37c581c10827d6e 100644
  3--- a/plugins/colorize/README.md
  4+++ b/plugins/colorize/README.md
  5@@ -8,24 +8,39 @@ is found it will just cat the file normally, without syntax highlighting.
  6 
  7 ## Setup
  8 
  9-To use it, add colorize to the plugins array of your zshrc file:
 10+To use it, add colorize to the plugins array of your `~/.zshrc` file:
 11 ```
 12 plugins=(... colorize)
 13 ```
 14 
 15+## Configuration
 16+
 17 ### Requirements
 18 
 19-This plugin requires that Pygments be installed: [pygments.org](https://pygments.org/)
 20+This plugin requires that either of the following tools be installed:
 21+
 22+* Chroma: [https://github.com/alecthomas/chroma](https://github.com/alecthomas/chroma)
 23+* Pygments be installed: [pygments.org](https://pygments.org/)
 24+
 25+### Colorize tool
 26 
 27-## Styles
 28+Colorize supports `pygmentize` and `chroma` as syntax highlighter. By default colorize uses `pygmentize` unless it's not installed and `chroma` is. This can be overridden by the `ZSH_COLORIZE_TOOL` environment variable:
 29+
 30+```
 31+ZSH_COLORIZE_TOOL=chroma
 32+```
 33+
 34+### Styles
 35 
 36 Pygments offers multiple styles. By default, the `default` style is used, but you can choose another theme by setting the `ZSH_COLORIZE_STYLE` environment variable:
 37 
 38-`ZSH_COLORIZE_STYLE="colorful"`
 39+```
 40+ZSH_COLORIZE_STYLE="colorful"
 41+```
 42 
 43 ## Usage
 44 
 45-* `ccat  <file> [files]`: colorize the contents of the file (or files, if more than one are provided). 
 46+* `ccat <file> [files]`: colorize the contents of the file (or files, if more than one are provided).
 47   If no arguments are passed it will colorize the standard input or stdin.
 48 
 49 * `cless <file> [files]`: colorize the contents of the file (or files, if more than one are provided) and
 50diff --git a/plugins/colorize/colorize.plugin.zsh b/plugins/colorize/colorize.plugin.zsh
 51index a006a7828bed29ab3a8ba1c518155529ff8e082f..3e91a9f4671d28bb13689fa0fd630a0f7fac3e8a 100644
 52--- a/plugins/colorize/colorize.plugin.zsh
 53+++ b/plugins/colorize/colorize.plugin.zsh
 54@@ -3,21 +3,42 @@ alias ccat='colorize_via_pygmentize'
 55 alias cless='colorize_via_pygmentize_less'
 56 
 57 colorize_via_pygmentize() {
 58-    if ! (( $+commands[pygmentize] )); then
 59-        echo "package 'Pygments' is not installed!"
 60+    local available_tools=("chroma" "pygmentize")
 61+
 62+    if [ -z "$ZSH_COLORIZE_TOOL" ]; then
 63+        if (( $+commands[pygmentize] )); then
 64+            ZSH_COLORIZE_TOOL="pygmentize"
 65+        elif (( $+commands[chroma] )); then
 66+            ZSH_COLORIZE_TOOL="chroma"
 67+        else
 68+            echo "Neither 'pygments' nor 'chroma' is installed!" >&2
 69+            return 1
 70+        fi
 71+    fi
 72+
 73+    if [[ ${available_tools[(Ie)$ZSH_COLORIZE_TOOL]} -eq 0 ]]; then
 74+        echo "ZSH_COLORIZE_TOOL '$ZSH_COLORIZE_TOOL' not recognized. Available options are 'pygmentize' and 'chroma'." >&2
 75+        return 1
 76+    elif (( $+commands["$ZSH_COLORIZE_TOOL"] )); then
 77+        echo "Package '$ZSH_COLORIZE_TOOL' is not installed!" >&2
 78         return 1
 79     fi
 80 
 81-    # If the environment varianle ZSH_COLORIZE_STYLE
 82+    # If the environment variable ZSH_COLORIZE_STYLE
 83     # is set, use that theme instead. Otherwise,
 84     # use the default.
 85-    if [ -z $ZSH_COLORIZE_STYLE ]; then
 86-        ZSH_COLORIZE_STYLE="default"
 87+    if [ -z "$ZSH_COLORIZE_STYLE" ]; then
 88+        # Both pygmentize & chroma support 'emacs'
 89+        ZSH_COLORIZE_STYLE="emacs"
 90     fi
 91 
 92     # pygmentize stdin if no arguments passed
 93     if [ $# -eq 0 ]; then
 94-        pygmentize -O style="$ZSH_COLORIZE_STYLE" -g
 95+        if [[ "$ZSH_COLORIZE_TOOL" == "pygmentize" ]]; then
 96+            pygmentize -O style="$ZSH_COLORIZE_STYLE" -g
 97+        else
 98+            chroma --style="$ZSH_COLORIZE_STYLE"
 99+        fi
100         return $?
101     fi
102 
103@@ -27,11 +48,15 @@ colorize_via_pygmentize() {
104     local FNAME lexer
105     for FNAME in "$@"
106     do
107-        lexer=$(pygmentize -N "$FNAME")
108-        if [[ $lexer != text ]]; then
109-            pygmentize -O style="$ZSH_COLORIZE_STYLE" -l "$lexer" "$FNAME"
110+        if [[ "$ZSH_COLORIZE_TOOL" == "pygmentize" ]]; then
111+            lexer=$(pygmentize -N "$FNAME")
112+            if [[ $lexer != text ]]; then
113+                pygmentize -O style="$ZSH_COLORIZE_STYLE" -l "$lexer" "$FNAME"
114+            else
115+                pygmentize -O style="$ZSH_COLORIZE_STYLE" -g "$FNAME"
116+            fi
117         else
118-            pygmentize -O style="$ZSH_COLORIZE_STYLE" -g "$FNAME"
119+            chroma --style="$ZSH_COLORIZE_STYLE" "$FNAME"
120         fi
121     done
122 }