summaryrefslogtreecommitdiff
path: root/external
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
commit2283341da95c4b245b0c3862e137bd6190d63d77 (patch)
tree8ce5f54de068213f8eedb9a883fb52b71cf23335 /external
parent352f10d4f5802c8ed80a4062e1bc2f0986866b8a (diff)
parent8d403d71ba2ccc50cb8786d6bfd1457ce1ecf2ca (diff)
downloadpygments-git-2283341da95c4b245b0c3862e137bd6190d63d77.tar.gz
Merged birkenfeld/pygments-main into default
Diffstat (limited to 'external')
-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