c7154e88396fec404edfc8b03899949a2ce284ba

Author
Jay Schwerberg <jason@schwerberg.com>
Committer
Jason Schwerberg <jason@schwerberg.com>
Date

Message

Add pygments style env var for colorized

Diff

 1diff --git a/plugins/colorize/colorize.plugin.zsh b/plugins/colorize/colorize.plugin.zsh
 2index b8790f2608250ff9b7961c35cea1784e0039d901..4e383867ae55130f65a559eef0b3cf300d4ef78b 100644
 3--- a/plugins/colorize/colorize.plugin.zsh
 4+++ b/plugins/colorize/colorize.plugin.zsh
 5@@ -1,6 +1,6 @@
 6 # easier alias to use the plugin
 7 alias ccat='colorize_via_pygmentize'
 8-alias cless='colorize_via_pygmentize_less'  
 9+alias cless='colorize_via_pygmentize_less'
10 
11 colorize_via_pygmentize() {
12     if ! (( $+commands[pygmentize] )); then
13@@ -8,36 +8,44 @@ colorize_via_pygmentize() {
14         return 1
15     fi
16 
17+    # If the environment varianle ZSH_COLORIZE_STYLE
18+    # is set, use that theme instead. Otherwise,
19+    # use the default.
20+    if [ -z $ZSH_COLORIZE_STYLE ]; then
21+        ZSH_COLORIZE_STYLE="default"
22+    fi
23+
24     # pygmentize stdin if no arguments passed
25     if [ $# -eq 0 ]; then
26-        pygmentize -g
27+        pygmentize -O style="$ZSH_COLORIZE_STYLE" -g
28         return $?
29     fi
30 
31     # guess lexer from file extension, or
32     # guess it from file contents if unsuccessful
33+
34     local FNAME lexer
35     for FNAME in "$@"
36     do
37         lexer=$(pygmentize -N "$FNAME")
38         if [[ $lexer != text ]]; then
39-            pygmentize -l "$lexer" "$FNAME"
40+            pygmentize -O style="$ZSH_COLORIZE_STYLE" -l "$lexer" "$FNAME"
41         else
42-            pygmentize -g "$FNAME"
43+            pygmentize -O style="$ZSH_COLORIZE_STYLE" -g "$FNAME"
44         fi
45     done
46 }
47 
48-colorize_via_pygmentize_less() (   
49+colorize_via_pygmentize_less() (
50     # this function is a subshell so tmp_files can be shared to cleanup function
51     declare -a tmp_files 
52-    
53+
54     cleanup () {
55         [[ ${#tmp_files} -gt 0 ]] && rm -f "${tmp_files[@]}"
56         exit
57     }
58     trap 'cleanup' EXIT HUP TERM INT
59-    
60+
61     while (( $# != 0 )); do     #TODO: filter out less opts
62         tmp_file="$(mktemp --tmpdir "tmp.colorize.XXXX.$(sed 's/\//./g' <<< "$1")")"
63         tmp_files+=("$tmp_file")