summaryrefslogtreecommitdiff
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
commit1996fd14d14b71a0cc336b3fed83c905fc63467c (patch)
tree6f975919c4a8869dab095152fcd7f88ccdec2c1b
parent1632edd8fbb7d824252bd12e52fe275234f45ec9 (diff)
downloadpygments-1996fd14d14b71a0cc336b3fed83c905fc63467c.tar.gz
autopygmentize: use hexdump on binary files
Not strictly using autopygmentize, but makes things more legible.
-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