From a8b19f5d7ec7e442f0a55a12f4afe6afbf32f006 Mon Sep 17 00:00:00 2001 From: Anton Bobov Date: Sat, 7 Nov 2020 23:05:23 +0500 Subject: Add lessfilter ability to format XML with python, use python3 if available. --- files/.lessfilter.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'files/.lessfilter.sh') diff --git a/files/.lessfilter.sh b/files/.lessfilter.sh index 8c18600..e3c01d1 100755 --- a/files/.lessfilter.sh +++ b/files/.lessfilter.sh @@ -4,16 +4,22 @@ case $1 in *.xml) if [ -x "$(command -v xmlstarlet)" ]; then exec xmlstarlet fo "$1" + elif [ -x "$(command -v python3)" ] ; then + exec python3 -c 'import sys; import xml.dom.minidom as xml; sys.stdout.write(xml.parse(sys.argv[1]).toprettyxml())' "$1" + elif [ -x "$(command -v python)" ] ; then + exec python -c 'import sys; import xml.dom.minidom as xml; sys.stdout.write(xml.parse(sys.argv[1]).toprettyxml())' "$1" fi ;; *.json) if [ -x "$(command -v jq)" ]; then exec jq -C . "$1" + elif [ -x "$(command -v python3)" ] ; then + exec python3 -m json.tool "$1" elif [ -x "$(command -v python)" ] ; then exec python -m json.tool "$1" fi ;; - *.md) + *.md|*.html) if [ -x "$(command -v pandoc)" ]; then exec pandoc -t plain "$1" fi -- cgit v1.2.3