summaryrefslogtreecommitdiff
path: root/external
diff options
context:
space:
mode:
authorrrt <rrt@sc3d.org>2016-06-07 22:54:32 +0100
committerrrt <rrt@sc3d.org>2016-06-07 22:54:32 +0100
commit8d403d71ba2ccc50cb8786d6bfd1457ce1ecf2ca (patch)
tree3d1bda5799010fd8e249b2a139f66ecb537164b4 /external
parent0e7f6acac845699634625cc6d5d8865b0d6c88ab (diff)
downloadpygments-git-8d403d71ba2ccc50cb8786d6bfd1457ce1ecf2ca.tar.gz
autopygmentize: use hexdump on binary files
Not strictly using autopygmentize, but makes things more legible.
Diffstat (limited to 'external')
-rwxr-xr-xexternal/autopygmentize25
1 files changed, 16 insertions, 9 deletions
diff --git a/external/autopygmentize b/external/autopygmentize
index 07cfdaa9..9b030fac 100755
--- a/external/autopygmentize
+++ b/external/autopygmentize
@@ -66,19 +66,26 @@ if [[ "$lexer" == text ]]; then
esac
fi
+# Find a preprocessor for compressed files
+concat=cat
+case $(file $file_common_opts --mime-type "$file") in
+ application/x-gzip) concat=zcat;;
+ application/x-bzip2) concat=bzcat;;
+ application/x-xz) concat=xzcat;;
+esac
+
+# Find a reader: either a suitable lexer, or hd for binary files
+reader=""
encoding=$(file --mime-encoding --uncompress $file_common_opts "$file")
if [[ $encoding == "binary" ]]; then
- encoding="latin1"
+ reader=hd
+elif [[ -n "$lexer" ]]; then
+ reader="pygmentize -O inencoding=$encoding $PYGMENTIZE_OPTS $options -l $lexer"
fi
-if [[ -n "$lexer" ]]; then
- concat=cat
- case $(file $file_common_opts --mime-type "$file") in
- application/x-gzip) concat=zcat;;
- application/x-bzip2) concat=bzcat;;
- application/x-xz) concat=xzcat;;
- esac
- exec $concat "$file" | pygmentize -O inencoding=$encoding $PYGMENTIZE_OPTS $options -l $lexer
+# If we found a reader, run it
+if [[ -n "$reader" ]]; then
+ exec $concat "$file" | $reader
fi
exit 1