]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
xzless: Use ||- in LESSOPEN with with "less" 451 and newer.
authorLasse Collin <lasse.collin@tukaani.org>
Fri, 9 Feb 2024 21:21:01 +0000 (23:21 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Fri, 9 Feb 2024 21:21:01 +0000 (23:21 +0200)
src/scripts/xzless.in

index 93a415d7a92650d8bcec42b00b8608e886d4726b..53650ef1bea7bcd19a421c5d71694ab524286c62 100644 (file)
@@ -48,7 +48,14 @@ if test "${LESSMETACHARS+set}" != set; then
 fi
 
 VER=$(less -V | { read _ ver _ && echo ${ver%%.*}; })
-if test "$VER" -ge 429; then
+if test "$VER" -ge 451; then
+       # less 451 or later: If the compressed file is valid but has
+       # zero bytes of uncompressed data, using two vertical bars ||- makes
+       # "less" check the exit status of xz and if it is zero then display
+       # an empty file. With a single vertical bar |- and no output from xz,
+       # "less" would attempt to display the raw input file instead.
+       LESSOPEN="||-$xz -cdfqQ -- %s"
+elif test "$VER" -ge 429; then
        # less 429 or later: LESSOPEN pipe will be used on
        # standard input if $LESSOPEN begins with |-.
        LESSOPEN="|-$xz -cdfqQ -- %s"