diff --git a/.lessfilter b/.lessfilter index 203c52a..483c037 100644 --- a/.lessfilter +++ b/.lessfilter @@ -1,5 +1,5 @@ #!/bin/bash -# uses Pygments v2.13.0 for syntax highlighting on applicable file types +# uses Pygments v2.14.0 for syntax highlighting on applicable file types for path in "$@"; do # match by known filenames filename=$(basename "$path") @@ -31,15 +31,15 @@ for path in "$@"; do .1p|.3pm|.6pl|.6pm|.ABAP|.ASM|.BAS|.C|.CBL|.COB|.CPP|.CPY|.F|\ .F03|.F90|.G|.H|.ICON|.MIPS|.P|.PRG|.R|.Rd|.Rout|.S|.SAS|.VBS|\ .[1-9]|.[gs]sed|.abap|.abnf|.ada|.adb|.adl|.adlf|.adls|.adlx|\ - .ado|.ads|.aes|.agda|.aheui|.ahk|.ahkl|.aj|.als|.ans|.apl|\ - .aplc|.aplf|.apli|.apln|.aplo|.applescript|.arexx|.art|.arw|\ - .as|.asax|.asc|.ascx|.ashx|.asm|.asmx|.aspx|.asy|.at|.au3|\ - .aug|.automount|.aux|.awk|.axd|.b|.bare|.bas|.bash|.bat|.bb|\ - .bbc|.bc|.be|.befunge|.bf|.bib|.bmx|.bnf|.boa|.boo|.bpl|.bro|\ - .bst|.bug|.bzl|.c|.c++|.c++-objdump|.c-objdump|.cadl|.camkes|\ - .capnp|.cbl|.cc|.cddl|.cdf|.cdl|.ceylon|.cf|.cfc|.cfg|.cfm|\ - .cfml|.chai|.chpl|.ci|.cirru|.cjs|.cl|.clay|.clj|.cljc|.cljs|\ - .cls|.cmake|.cmd|.cml|.cob|.coffee|.comal|.cp|.cpl|.cpp|\ + .ado|.ads|.aes|.agda|.aheui|.ahk|.ahkl|.aj|.alg|.als|.ans|\ + .apl|.aplc|.aplf|.apli|.apln|.aplo|.applescript|.arexx|.art|\ + .arw|.as|.asax|.asc|.ascx|.ashx|.asm|.asmx|.aspx|.asy|.at|\ + .au3|.aug|.automount|.aux|.awk|.axd|.b|.bare|.bas|.bash|.bat|\ + .bb|.bbc|.bc|.be|.befunge|.bf|.bib|.bmx|.bnf|.boa|.boo|.bpl|\ + .bro|.bst|.bug|.bzl|.c|.c++|.c++-objdump|.c-objdump|.cadl|\ + .camkes|.capnp|.cbl|.cc|.cddl|.cdf|.cdl|.ceylon|.cf|.cfc|.cfg|\ + .cfm|.cfml|.chai|.chpl|.ci|.cirru|.cjs|.cl|.clay|.clj|.cljc|\ + .cljs|.cls|.cmake|.cmd|.cml|.cob|.coffee|.comal|.cp|.cpl|.cpp|\ .cpp-objdump|.cps|.cpsa|.cpy|.cr|.crmsh|.croc|.cry|.cs|.csd|\ .csh|.css|.css.in|.css.j2|.css.jinja2|.cssul4|.cu|.cuh|.cw|\ .cxx|.cxx-objdump|.cyp|.cypher|.d|.d-objdump|.darcspatch|\ @@ -50,7 +50,7 @@ for path in "$@"; do .erl-sh|.es|.escript|.evoque|.ex|.exec|.exheres-0|.exlib|.exs|\ .exw|.ezt|.f|.f03|.f90|.factor|.fan|.fancypack|.fc|.feature|\ .fhtml|.fif|.fish|.flo|.flx|.flxh|.fnl|.frag|.frt|.fs|.fsi|\ - .fst|.fsti|.fun|.func|.fut|.fy|.g|.gap|.gcode|.gd|.gdc|\ + .fst|.fsti|.fsx|.fun|.func|.fut|.fy|.g|.gap|.gcode|.gd|.gdc|\ .gemspec|.geo|.gi|.go|.golo|.gradle|.graph|.groovy|.gs|.gsp|\ .gsql|.gst|.gsx|.gv|.h|.h++|.haml|.handlebars|.hbs|.hdp|.hh|\ .hlsl|.hlsli|.hpp|.hrl|.hs|.hsail|.htm|.htm.j2|.htm.jinja2|\ @@ -63,46 +63,47 @@ for path in "$@"; do .kt|.kts|.lagda|.lasso|.lasso[89]|.lcry|.lean|.leex|.less|\ .lgt|.lhs|.libsonnet|.lid|.lidr|.liquid|.lisp|.ll|.load|\ .logtalk|.lpad|.ls|.lsl|.lsp|.lua|.ly|.m|.m2|.ma|.mac|.mak|\ - .man|.mao|.maql|.markdown|.mask|.max|.mc|.mcfunction|.md|\ - .mhtml|.mi|.mips|.mir|.mjs|.mk|.ml|.mli|.mll|.mly|.mm|.mo|\ - .mod|.monkey|.moo|.moon|.mos|.mount|.mq4|.mq5|.mqh|.ms|.msc|\ - .mt|.mu|.mxml|.myt|.n|.nb|.nbp|.nc|.ncl|.ng2|.ni|.nim|.nimrod|\ - .nit|.nix|.nl|.nqp|.ns2|.nsh|.nsi|.nt|.objdump|.objdump-intel|\ - .odin|.ooc|.opa|.orc|.p|.p6|.p6l|.p6m|.pan|.pas|.patch|.path|\ - .pc|.pcmk|.peg|.pem|.perl|.php|.php[345]|.phtml|.pidl|.pig|\ - .pike|.pl|.pl6|.plot|.plt|.pm|.pm6|.pmod|.po|.pony|.pot|.pov|\ - .pp|.praat|.prg|.pro|.proc|.prolog|.promql|.properties|.proto|\ - .ps|.ps1|.psc|.psi|.psl|.psm1|.ptls|.pug|.pwn|.pxd|.pxi|.py|\ - .py2tb|.py3tb|.pyi|.pypylog|.pytb|.pyul4|.pyw|.pyx|.q|.qbs|\ - .qml|.qvs|.qvto|.qvw|.r|.r3|.rake|.raku|.rakudoc|.rakumod|\ - .rakutest|.rb|.rbw|.rbx|.re|.reb|.red|.reds|.reg|.rei|\ - .resource|.rest|.rex|.rexx|.rhtml|.ride|.rita|.rkt|.rktd|\ - .rktl|.rl|.rnc|.robot|.rpf|.rq|.rql|.rs|.rs.in|.rsl|.rss|.rst|\ - .rts|.run|.rvt|.rx|.s|.sage|.sarl|.sas|.sass|.savi|.sbl|.sc|\ - .scala|.scaml|.scd|.scdoc|.sce|.sci|.scm|.sco|.scope|.scss|\ - .sed|.service|.sgf|.sh|.sh-session|.shell-session|.shen|.shex|\ - .sieve|.sig|.sil|.siv|.sl|.sla|.slice|.slim|.sls|.smali|\ - .smithy|.sml|.smv|.snbt|.snobol|.socket|.sol|.sp|.sparql|\ - .spec|.spice|.spt|.sql|.sql.j2|.sql.jinja2|.sqlite3-console|\ - .ss|.ssp|.st|.stan|.sv|.svh|.swap|.swg|.swift|.t|.tac|.tal|\ - .tap|.target|.tasm|.tcl|.tcsh|.tea|.teal|.tex|.tf|.thrift|\ - .thy|.ti|.tid|.timer|.tlb|.tmpl|.tnt|.toc|.todotxt|.toml|.tpl|\ - .tpp|.treetop|.ts|.tst|.tt|.ttl|.twig|.txt|.typoscript|.u|.u1|\ - .u2|.udo|.ul4|.usd|.usda|.v|.vala|.vapi|.vark|.vb|.vbs|.vcl|\ - .vert|.vhd|.vhdl|.vim|.vm|.vpr|.wast|.wat|.wdiff|.webidl|\ - .weechatlog|.whiley|.wlua|.wsdl|.wsf|.x|.x10|.x[bp]m|.xhtml|\ - .xhtml.j2|.xhtml.jinja2|.xi|.xm|.xmi|.xml|.xml.j2|.xml.jinja2|\ - .xmlul4|.xpl|.xq|.xql|.xqm|.xquery|.xqy|.xsd|.xsl|.xslt|\ - .xtend|.xtm|.xul.in|.yaml|.yaml.j2|.yaml.jinja2|.yang|.yml|\ - .yml.j2|.yml.jinja2|.zeek|.zep|.zig|.zsh|Config.in*) + .man|.mao|.maql|.markdown|.mask|.max|.mc|.mcfunction|\ + .mcschema|.md|.mhtml|.mi|.mips|.mir|.mjs|.mk|.ml|.mli|.mll|\ + .mly|.mm|.mo|.mod|.monkey|.moo|.moon|.mos|.mount|.mq4|.mq5|\ + .mqh|.ms|.msc|.mt|.mu|.mxml|.myt|.n|.nasm|.nb|.nbp|.nc|.ncl|\ + .ng2|.ni|.nim|.nimrod|.nit|.nix|.nl|.nqp|.ns2|.nsh|.nsi|.nt|\ + .objdump|.objdump-intel|.odin|.ooc|.opa|.orc|.p|.p6|.p6l|.p6m|\ + .pan|.pas|.patch|.path|.pc|.pcmk|.peg|.pem|.perl|.php|\ + .php[345]|.phtml|.pidl|.pig|.pike|.pl|.pl6|.plot|.plt|.pm|\ + .pm6|.pmod|.po|.pony|.portugol|.pot|.pov|.pp|.praat|.prg|.pro|\ + .proc|.prolog|.promql|.properties|.proto|.ps|.ps1|.psc|.psi|\ + .psl|.psm1|.ptls|.pug|.pwn|.pxd|.pxi|.py|.py2tb|.py3tb|.pyi|\ + .pypylog|.pytb|.pyul4|.pyw|.pyx|.q|.qbs|.qml|.qvs|.qvto|.qvw|\ + .r|.r3|.rake|.raku|.rakudoc|.rakumod|.rakutest|.rb|.rbw|.rbx|\ + .re|.reb|.red|.reds|.reg|.rei|.resource|.rest|.rex|.rexx|\ + .rhtml|.ride|.rita|.rkt|.rktd|.rktl|.rl|.rnc|.robot|.rpf|.rq|\ + .rql|.rs|.rs.in|.rsl|.rss|.rst|.rts|.run|.rvt|.rx|.s|.sage|\ + .sarl|.sas|.sass|.savi|.sbl|.sc|.scala|.scaml|.scd|.scdoc|\ + .sce|.sci|.scm|.sco|.scope|.scss|.sed|.service|.sgf|.sh|\ + .sh-session|.shell-session|.shen|.shex|.sieve|.sig|.sil|.siv|\ + .sl|.sla|.slice|.slim|.sls|.smali|.smithy|.sml|.smv|.snbt|\ + .snobol|.socket|.sol|.sp|.sparql|.spec|.spice|.spt|.sql|\ + .sql.j2|.sql.jinja2|.sqlite3-console|.ss|.ssp|.st|.stan|.sv|\ + .svh|.swap|.swg|.swift|.t|.tac|.tal|.tap|.target|.tasm|.tcl|\ + .tcsh|.tea|.teal|.tex|.tf|.thrift|.thy|.ti|.tid|.timer|.tlb|\ + .tmpl|.tnt|.toc|.todotxt|.toml|.tpl|.tpp|.treetop|.ts|.tst|\ + .tt|.ttl|.twig|.txt|.typoscript|.u|.u1|.u2|.udo|.ul4|.usd|\ + .usda|.v|.vala|.vapi|.vark|.vb|.vbs|.vcl|.vert|.vhd|.vhdl|\ + .vim|.vm|.vpr|.wast|.wat|.wdiff|.webidl|.weechatlog|.whiley|\ + .wlua|.wren|.wsdl|.wsf|.x|.x10|.x[bp]m|.xhtml|.xhtml.j2|\ + .xhtml.jinja2|.xi|.xm|.xmi|.xml|.xml.j2|.xml.jinja2|.xmlul4|\ + .xpl|.xq|.xql|.xqm|.xquery|.xqy|.xsd|.xsl|.xslt|.xtend|.xtm|\ + .xul.in|.yaml|.yaml.j2|.yaml.jinja2|.yang|.yml|.yml.j2|\ + .yml.jinja2|.zeek|.zep|.zig|.zsh|Config.in*|Spec.hs) # extension recognized pygmentize -f 256 -O style="$PYGMENTIZE_STYLE" "$path" ;; *) # unrecognized filename/extension # attempt to parse the lexer from the shebang if it exists - lexer=$(head -n 1 "$path" |grep "^#\!" |awk -F" " \ -'match($1, /\/(\w*)$/, a) {if (a[1]!="env") {print a[1]} else {print $2}}') + lexer=$(head -n 1 "$path" | grep '^#\!' | awk -F" " \ +'{ if (/env/) { print $2 } else { sub( /.*\//, ""); print $1;} }') case "$lexer" in node|nodejs) # workaround for lack of Node.js lexer alias diff --git a/README.md b/README.md index f71bda0..b57014a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ for supported file types. The `.lessfilter` is generated by parsing the Pygment ### 1. Install Pygments & gawk Ensure that you have the latest version of Pygments installed by using [pip](https://pypi.org/project/pip/), as your -distro's packaged version is likely outdated. You'll also need `gawk`. +distro's packaged version is likely outdated. You'll also need `awk`. ```shell # remove any installed packaged versions sudo apt autoremove python-pygments python3-pygments @@ -15,7 +15,7 @@ sudo apt autoremove python-pygments python3-pygments # install latest version sudo pip install Pygments --upgrade -# install gawk +# install some implementation of `awk` sudo apt install gawk ``` @@ -49,7 +49,7 @@ export LESSOPEN='|~/.lessfilter %s' ### 4. Create ~/.lessfilter Run [main.py](main.py) to generate the latest `.lessfilter` file and place it in your home directory. -Or you can download a pre-generated [.lessfilter](.lessfilter) which is currently at version `2.13.0`. +Or you can download a pre-generated [.lessfilter](.lessfilter) which is currently at version `2.14.0`. Check your program version by running `pygmentize -V` to ensure that it is this version or newer. ### 5. Make ~/.lessfilter executable diff --git a/main.py b/main.py index a8b5c48..c059d10 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,6 @@ from typing import List, Iterable import re import requests -import os from lxml import html from lxml.html import HtmlElement from lxml.cssselect import CSSSelector diff --git a/template.lessfilter.sh b/template.lessfilter.sh index 77ac1d6..94bbbb4 100644 --- a/template.lessfilter.sh +++ b/template.lessfilter.sh @@ -22,8 +22,8 @@ for path in "$@"; do *) # unrecognized filename/extension # attempt to parse the lexer from the shebang if it exists - lexer=$(head -n 1 "$path" |grep "^#\!" |awk -F" " \ -'match($1, /\/(\w*)$/, a) {if (a[1]!="env") {print a[1]} else {print $2}}') + lexer=$(head -n 1 "$path" | grep '^#\!' | awk -F" " \ +'{ if (/env/) { print $2 } else { sub( /.*\//, ""); print $1;} }') case "$lexer" in node|nodejs) # workaround for lack of Node.js lexer alias