Skip to content

Commit e040aa7

Browse files
committed
autopygmentize: support more file types, use xdg-mime
Use xdg-mime instead of file. Includes new languages; in particular, allow application/foo or text/foo for scripting languages.
1 parent 48c0af9 commit e040aa7

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

external/autopygmentize

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,46 @@ options=${@:1:$(($#-1))} # handle others args as options to pass to pygmentize
1313

1414
file_common_opts="--brief --dereference"
1515

16-
case $(file --mime-type --uncompress $file_common_opts "$file") in
16+
# Old command: file --mime-type --uncompress $file_common_opts
17+
case $(xdg-mime query filetype "$file") in
1718
application/xml|image/svg+xml) lexer=xml;;
1819
application/javascript) lexer=javascript;;
1920
application/json) lexer=json;;
2021
text/html) lexer=html;;
2122
text/troff) lexer=nroff;;
2223
text/x-asm) lexer=nasm;;
23-
text/x-awk) lexer=awk;;
24-
text/x-c) lexer=c;;
25-
text/x-c++) lexer=cpp;;
26-
text/x-clojure) lexer=clojure;;
24+
*/x-awk) lexer=awk;;
25+
text/x-c|text/x-csrc|text/x-chdr) lexer=c;;
26+
text/x-c++|text/x-c++src) lexer=cpp;;
27+
*/x-clojure) lexer=clojure;;
2728
text/x-crystal) lexer=crystal;;
2829
text/x-diff) lexer=diff;;
29-
text/x-execline) lexer=execline;;
30+
*/x-execline) lexer=execline;;
3031
text/x-forth) lexer=forth;;
3132
text/x-fortran) lexer=fortran;;
32-
text/x-gawk) lexer=gawk;;
33+
*/x-gawk) lexer=gawk;;
3334
text/x-java) lexer=java;;
34-
text/x-lisp) lexer=common-lisp;;
35-
text/x-lua|text/x-luatex) lexer=lua;;
35+
*/x-lisp) lexer=common-lisp;;
36+
*/x-emacs-lisp) lexer=emacs-lisp;;
37+
*/x-lua|*/x-luatex) lexer=lua;;
3638
text/x-makefile) lexer=make;;
37-
text/x-msdos-batch) lexer=bat;;
38-
text/x-nawk) lexer=nawk;;
39+
*/x-msdos-batch) lexer=bat;;
40+
*/x-nawk) lexer=nawk;;
3941
text/x-objective-c) lexer=objective-c;;
40-
text/x-pascal) lexer=pascal;;
41-
text/x-perl) lexer=perl;;
42-
text/x-php) lexer=php;;
43-
text/x-po) lexer=po;;
44-
text/x-python) lexer=python;;
45-
text/x-ruby) lexer=ruby;;
46-
text/x-script.python) lexer=python;;
47-
text/x-shellscript) lexer=sh;;
48-
text/x-tcl) lexer=tcl;;
42+
*/x-pascal) lexer=pascal;;
43+
*/x-perl) lexer=perl;;
44+
*/x-php) lexer=php;;
45+
*/x-po) lexer=po;;
46+
*/x-python*) lexer=python;;
47+
*/x-ruby) lexer=ruby;;
48+
*/x-script.python) lexer=python;;
49+
*/x-shellscript) lexer=sh;;
50+
# Workaround for TypeScript: mimetype doesn't recognize it.
51+
text/vnd.trolltech.linguist) lexer=typescript;;
52+
*/x-tcl) lexer=tcl;;
4953
text/x-tex|text/x-texinfo) lexer=latex;; # FIXME: texinfo really needs its own lexer
54+
*/x-ursa) lexer=ursa;;
55+
*/x-vala) lexer=vala;;
5056
text/xml) lexer=xml;;
5157
text/vnd.graphviz) lexer=graphviz;;
5258

0 commit comments

Comments
 (0)