summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReuben Thomas <rrt@sc3d.org>2016-06-20 22:39:57 +0100
committerReuben Thomas <rrt@sc3d.org>2016-06-20 22:39:57 +0100
commit4623290607e796456d3c56a6bc7e87430ba9ae62 (patch)
tree32f4303ef0e5f139615c7b39a741b3baed8cfec7
parent421263e90981c08119640d280af96550e9f5fd05 (diff)
parent1996fd14d14b71a0cc336b3fed83c905fc63467c (diff)
downloadpygments-4623290607e796456d3c56a6bc7e87430ba9ae62.tar.gz
Merged birkenfeld/pygments-main into default
-rwxr-xr-xexternal/autopygmentize29
1 files changed, 18 insertions, 11 deletions
diff --git a/external/autopygmentize b/external/autopygmentize
index f18cac09..9b030fac 100755
--- a/external/autopygmentize
+++ b/external/autopygmentize
@@ -1,6 +1,6 @@
#!/bin/bash
# Best effort auto-pygmentization with transparent decompression
-# by Reuben Thomas 2008-2015
+# by Reuben Thomas 2008-2016
# This program is in the public domain.
# Strategy: first see if pygmentize can find a lexer; if not, ask file; if that finds nothing, fail
@@ -25,6 +25,7 @@ if [[ "$lexer" == text ]]; then
text/x-awk) lexer=awk;;
text/x-c) lexer=c;;
text/x-c++) lexer=cpp;;
+ text/x-crystal) lexer=crystal;;
text/x-diff) lexer=diff;;
text/x-fortran) lexer=fortran;;
text/x-gawk) lexer=gawk;;
@@ -40,7 +41,6 @@ if [[ "$lexer" == text ]]; then
text/x-po) lexer=po;;
text/x-python) lexer=python;;
text/x-ruby) lexer=ruby;;
- text/x-crystal) lexer=crystal;;
text/x-shellscript) lexer=sh;;
text/x-tcl) lexer=tcl;;
text/x-tex|text/x-texinfo) lexer=latex;; # FIXME: texinfo really needs its own lexer
@@ -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