aboutsummaryrefslogtreecommitdiff
path: root/src/scripts/xzless.in
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2009-08-09 13:22:12 -0500
committerLasse Collin <lasse.collin@tukaani.org>2009-08-09 22:27:22 +0300
commit1d314b81aa5b0c4530638ffabd4e0edb52e5362c (patch)
treef3e478912cf18aa0d58a7ec72d641c3cf0b55987 /src/scripts/xzless.in
parentGPLv2+ not GPLv2 for Doxyfile.in is probably OK. (diff)
downloadxz-1d314b81aa5b0c4530638ffabd4e0edb52e5362c.tar.xz
xzless: Support compressed standard input
It can be somewhat confusing that less < some_file.txt works fine, whereas xzless < some_file.txt.xz does not. Since version 429, ‘less’ allows a filter specified in the LESSOPEN environment variable to preprocess its input even if it comes from standard input, if $LESSOPEN begins with ‘|-’. So set $LESSOPEN to take advantage of this feature. Check less’s version at runtime so xzless can continue to work with older versions.
Diffstat (limited to '')
-rw-r--r--src/scripts/xzless.in8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/scripts/xzless.in b/src/scripts/xzless.in
index 6639943a..a3da697c 100644
--- a/src/scripts/xzless.in
+++ b/src/scripts/xzless.in
@@ -46,7 +46,13 @@ if test "${LESSMETACHARS+set}" != set; then
LESSMETACHARS="$space$tab$nl'"';*?"()<>[|&^`#\$%=~'
fi
-LESSOPEN="|$xz -cdfq -- %s"
+if test "$(less -V | { read ver && echo ${ver#less }; })" -ge 429; then
+ # less 429 or later: LESSOPEN pipe will be used on
+ # standard input if $LESSOPEN begins with |-.
+ LESSOPEN="|-$xz -cdfq -- %s"
+else
+ LESSOPEN="|$xz -cdfq -- %s"
+fi
export LESSMETACHARS LESSOPEN
exec less "$@"