forked from n8gray/QLColorCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolorize.sh
More file actions
executable file
·63 lines (54 loc) · 1.73 KB
/
colorize.sh
File metadata and controls
executable file
·63 lines (54 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/zsh
# This code is licensed under the GPL v2. See LICENSE.txt for details.
# colorize.sh
# QLColorCode
#
# Created by Nathaniel Gray on 11/27/07.
# Copyright 2007 Nathaniel Gray. All rights reserved.
# Expects $1 = path to resources dir of bundle
# $2 = name of file to colorize
#
# Produces HTML on stdout with exit code 0 on success
# Fail immediately on failure of sub-command
setopt err_exit
rsrcDir=$1
target=$2
thumb=$3
thumblines=50
export PYTHONPATH=$rsrcDir/pygments
pyg=$rsrcDir/pygments/pygmentize
# Styles: manni, perldoc, borland, colorful, default, murphy, trac, fruity, autumn,
# emacs, pastie, friendly, native
# dark styles: native, fruity
# autumn is almost nice, except that the comments are too light
# don't like: murphy
pygOpts=(-f html -O outencoding=UTF-8,full=True,style=autumn -P "cssstyles=font-size: small")
font=Monaco
case $target in
*.plist )
if [ $thumb = "1" ]; then
filter=(head -n $thumblines)
else
filter=cat
fi
/usr/bin/plutil -convert xml1 -o - $target | $filter | $pyg -l xml $pygOpts \
| sed "s/pre *{/pre { font-family: $font; /"
;;
* )
{
if [ $thumb = "1" ]; then
#echo "making thumbnail: $thumb" >> ~/qlcc-debug.txt
tmpDir=`mktemp -d -t qlcolorcode-XXXXXX`
tgtBase="`basename $target`"
head -n $thumblines $target > $tmpDir/$tgtBase
target=$tmpDir/$tgtBase
fi
$pyg $pygOpts $target \
| sed "s/pre *{/pre { font-family: $font; /"
} always {
if [ $thumb = "1" ]; then
rm -rf $tmpDir
fi
}
;;
esac