34b5ff588bdd96970d63cc5763b9b391fd3199fc

Author
Aaron N. Brock <AaronNBrock@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

Merge pull request #1 from ProbstDJakob/colorize-chroma-support

Fix some issues

Diff

 1diff --git a/plugins/colorize/README.md b/plugins/colorize/README.md
 2index b6e27fd273fcb6eeea8e6fb1e1673a23080d6722..38d17dc76e9938869812bad0403ad46031d7e1d8 100644
 3--- a/plugins/colorize/README.md
 4+++ b/plugins/colorize/README.md
 5@@ -14,7 +14,7 @@ plugins=(... colorize)
 6 
 7 ### Colorize tool
 8 
 9-Colorize supports using either the `pygmentize` tool or the `chroma` tool.  By default colorize uses `pygmentize` unless it's not installed & `chroma` is installed.  However, you can override this with the `ZSH_COLORIZE_TOOL` environment variable:
10+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:
11 
12 ```
13 ZSH_COLORIZE_TOOL=chroma
14@@ -30,7 +30,7 @@ ZSH_COLORIZE_STYLE="colorful"
15 
16 ## Usage
17 
18-* `ccat  <file> [files]`: colorize the contents of the file (or files, if more than one are provided). 
19+* `ccat <file> [files]`: colorize the contents of the file (or files, if more than one are provided). 
20   If no arguments are passed it will colorize the standard input or stdin.
21 
22 * `cless <file> [files]`: colorize the contents of the file (or files, if more than one are provided) and
23diff --git a/plugins/colorize/colorize.plugin.zsh b/plugins/colorize/colorize.plugin.zsh
24index 051d2269ce73e9e8494a72e26054db1bb3b12d3d..ac826e44bd05950b415602a365ff0e0853db61c6 100644
25--- a/plugins/colorize/colorize.plugin.zsh
26+++ b/plugins/colorize/colorize.plugin.zsh
27@@ -3,11 +3,7 @@ alias ccat='colorize_via_pygmentize'
28 alias cless='colorize_via_pygmentize_less'
29 
30 colorize_via_pygmentize() {
31-    
32-    if [[ $ZSH_COLORIZE_TOOL != "chroma" && $ZSH_COLORIZE_TOOL != "pygmentize" ]]; then
33-        echo "ZSH_COLORIZE_TOOL not recognized.  Options are 'pygmentize' or 'chroma'"
34-        return 1
35-    fi
36+    local available_tools=("chroma" "pygmentize")
37 
38     if [ -z $ZSH_COLORIZE_TOOL ]; then
39         if (( $+commands[pygmentize] )); then
40@@ -15,12 +11,18 @@ colorize_via_pygmentize() {
41         elif (( $+commands[chroma] )); then
42             ZSH_COLORIZE_TOOL="chroma"
43         else
44-            echo "niether 'Pygments' nor 'chroma' is not installed!"
45+            echo "Neither 'pygments' nor 'chroma' is installed!"
46             return 1
47         fi
48     fi
49 
50-    echo "Tool: $ZSH_COLORIZE_TOOL"
51+    if [[ ${available_tools[(Ie)$ZSH_COLORIZE_TOOL]} -eq 0 ]]; then
52+        echo "ZSH_COLORIZE_TOOL '$ZSH_COLORIZE_TOOL' not recognized. Available options are 'pygmentize' and 'chroma'."
53+        return 1
54+    elif (( $+commands[$ZSH_COLORIZE_TOOL] )); then
55+        echo "Package '$ZSH_COLORIZE_TOOL' is not installed!"
56+        return 1
57+    fi
58 
59     # If the environment variable ZSH_COLORIZE_STYLE
60     # is set, use that theme instead. Otherwise,
61@@ -35,7 +37,6 @@ colorize_via_pygmentize() {
62         fi
63     fi
64 
65-    echo "color style: $ZSH_COLORIZE_STYLE"
66     # pygmentize stdin if no arguments passed
67     if [ $# -eq 0 ]; then
68         if [[ $ZSH_COLORIZE_TOOL == "pygmentize" ]]; then