# 2021-01-23
# A complete re-write eliminating the use of filenames to determine how to
# process a file. --SY
+exec 2>/dev/null
lesspipe()
{
- case $(file -L --mime-type "$1"|awk '{print $2}') in
- application/x-tar) tar tvvf "$1" 2>/dev/null ;;
+ case $(file -Lb --mime-type "$1") in
+ application/x-tar) tar tvvf "$1" ;;
application/x-bzip2)
- case $(bzip2 -dc "$1"|file --mime-type -|awk '{print $2}') in
- application/x-tar) tar tvvf "$1" 2>/dev/null ;;
- text/troff) bzip2 -dc "$1"|nroff -S -mandoc- ;;
- *) bzip2 -dc "$1" 2>/dev/null ;;
+ case $(bzip2 -dc "$1"|file -b --mime-type -) in
+ application/x-tar) tar tvvf "$1" ;;
+ text/troff) bzip2 -dc "$1"|nroff -S -mandoc - ;;
+ *) bzip2 -dc "$1" ;;
esac ;;
application/gzip)
- case $(gzip -dc "$1"|file --mime-type -|awk '{print $2}') in
- application/x-tar) tar tvvf "$1" 2>/dev/null ;;
- text/troff) gzip -dc "$1"|nroff -S -mandoc- ;;
- *) gzip -dc "$1" 2>/dev/null ;;
+ case $(gzip -dc "$1"|file -b --mime-type -) in
+ application/x-tar) tar tvvf "$1" ;;
+ text/troff) gzip -dc "$1"|nroff -S -mandoc - ;;
+ *) gzip -dc "$1" ;;
esac ;;
application/x-lzip)
- case $(lzip -dc "$1"|file --mime-type -|awk '{print $2}') in
- application/x-tar) tar tvvf "$1" 2>/dev/null ;;
- text/troff) lzip -dc "$1"|nroff -S -mandoc- ;;
- *) lzip -dc "$1" 2>/dev/null ;;
+ case $(lzip -dc "$1"|file -b --mime-type -) in
+ application/x-tar) tar tvvf "$1" ;;
+ text/troff) lzip -dc "$1"|nroff -S -mandoc - ;;
+ *) lzip -dc "$1" ;;
esac ;;
application/x-lzma)
- case $(lzma -dc "$1"|file --mime-type -|awk '{print $2}') in
- application/x-tar) tar tvvf "$1" 2>/dev/null ;;
- text/troff) lzma -dc "$1"|nroff -S -mandoc- ;;
- *) lzma -dc "$1" 2>/dev/null ;;
+ case $(lzma -dc "$1"|file -b --mime-type -) in
+ application/x-tar) tar tvvf "$1" ;;
+ text/troff) lzma -dc "$1"|nroff -S -mandoc - ;;
+ *) lzma -dc "$1" ;;
esac ;;
application/x-xz)
- case $(xz -dc "$1"|file --mime-type -|awk '{print $2}') in
- application/x-tar) tar tvvf "$1" 2>/dev/null ;;
- text/troff) xz -dc "$1"|nroff -S -mandoc- ;;
- *) xz -dc "$1" 2>/dev/null ;;
+ case $(xz -dc "$1"|file -b --mime-type -) in
+ application/x-tar) tar tvvf "$1" ;;
+ text/troff) xz -dc "$1"|nroff -S -mandoc - ;;
+ *) xz -dc "$1" ;;
esac ;;
application/zstd)
- case $(zstd -dc "$1"|file --mime-type -|awk '{print $2}') in
- application/x-tar) tar tvvf "$1" 2>/dev/null ;;
- text/troff) zstd -dc "$1"|nroff -S -mandoc- ;;
- *) zstd -dc "$1" 2>/dev/null ;;
+ case $(zstd -dc "$1"|file -b --mime-type -) in
+ application/x-tar) tar tvvf "$1" ;;
+ text/troff) zstd -dc "$1"|nroff -S -mandoc - ;;
+ *) zstd -dc "$1" ;;
esac ;;
- application/zip) unzip -l "$1" 2>/dev/null ;;
- application/*debian*) ar -tv "$1" 2>/dev/null ;;
- text/troff) nroff -S -mandoc "$1" 2>/dev/null ;;
+ application/x-rar) type unrar 1>/dev/null && unrar v "$1" ;;
+ application/x-rpm) type rpm 1>/dev/null && rpm -qpvl "$1" ;;
+ application/zip) unzip -l "$1" ;;
+ application/*debian*) ar -tv "$1" ;;
+ text/troff) nroff -S -mandoc "$1" ;;
+ text/html) lynx -dump "$1" ;;
+ text/xml) head "$1"|grep -q ' html'&& lynx -dump "$1" ;;
# Lastly, if it is an ELF file, use readelf(1)
- *) file -L "$1"|grep -q ' ELF '&& readelf --all "$1" 2>/dev/null ;;
+ *) file -L "$1"|grep -q ' ELF '&& readelf --all "$1" ;;
esac
}
-
-
lesspipe "$1"
+
+### End lesspipe.sh