2009-07-05 19:25:17 +00:00
|
|
|
#!@POSIX_SHELL@
|
|
|
|
|
|
|
|
# Copyright (C) 1998, 2002, 2006, 2007 Free Software Foundation
|
|
|
|
|
2009-07-19 08:09:31 +00:00
|
|
|
# The original version for gzip was written by Paul Eggert.
|
2009-07-05 19:25:17 +00:00
|
|
|
# Modified for XZ Utils by Andrew Dudman and Lasse Collin.
|
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
#SET_PATH - This line is a placeholder to ease patching this script.
|
|
|
|
|
|
|
|
# Instead of unsetting XZ_OPT, just make sure that xz will use file format
|
|
|
|
# autodetection. This way memory usage limit and thread limit can be
|
|
|
|
# specified via XZ_OPT.
|
|
|
|
xz='@xz@ --format=auto'
|
|
|
|
|
|
|
|
version='xzless (@PACKAGE_NAME@) @VERSION@'
|
|
|
|
|
|
|
|
usage="Usage: ${0##*/} [OPTION]... [FILE]...
|
|
|
|
Like 'less', but operate on the uncompressed contents of xz compressed FILEs.
|
|
|
|
|
|
|
|
Options are the same as for 'less'.
|
|
|
|
|
|
|
|
Report bugs to <@PACKAGE_BUGREPORT@>."
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
--help) echo "$usage" || exit 2; exit;;
|
|
|
|
--version) echo "$version" || exit 2; exit;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if test "${LESSMETACHARS+set}" != set; then
|
|
|
|
# Work around a bug in less 394 and earlier;
|
|
|
|
# it mishandles the metacharacters '$%=~'.
|
|
|
|
space=' '
|
|
|
|
tab=' '
|
|
|
|
nl='
|
|
|
|
'
|
|
|
|
LESSMETACHARS="$space$tab$nl'"';*?"()<>[|&^`#\$%=~'
|
|
|
|
fi
|
|
|
|
|
xzless: Make "less -V" parsing more robust
In v4.999.9beta~30 (xzless: Support compressed standard input,
2009-08-09), xzless learned to parse ‘less -V’ output to figure out
whether less is new enough to handle $LESSOPEN settings starting
with “|-”. That worked well for a while, but the version string from
‘less’ versions 448 (June, 2012) is misparsed, producing a warning:
$ xzless /tmp/test.xz; echo $?
/usr/bin/xzless: line 49: test: 456 (GNU regular expressions): \
integer expression expected
0
More precisely, modern ‘less’ lists the regexp implementation along
with its version number, and xzless passes the entire version number
with attached parenthetical phrase as a number to "test $a -gt $b",
producing the above confusing message.
$ less-444 -V | head -1
less 444
$ less -V | head -1
less 456 (no regular expressions)
So relax the pattern matched --- instead of expecting "less <number>",
look for a line of the form "less <number>[ (extra parenthetical)]".
While at it, improve the behavior when no matching line is found ---
instead of producing a cryptic message, we can fall back on a LESSPIPE
setting that is supported by all versions of ‘less’.
The implementation uses "awk" for simplicity. Hopefully that’s
portable enough.
Reported-by: Jörg-Volker Peetz <jvpeetz@web.de>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2012-11-19 08:10:10 +00:00
|
|
|
less_ver=$(less -V | awk '/^less ([0-9]+)( \(.*\))?$/ { print $2; exit }')
|
|
|
|
if test -n "$less_ver" && test "$less_ver" -ge 429; then
|
2009-08-09 18:22:12 +00:00
|
|
|
# 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
|
2009-07-05 19:25:17 +00:00
|
|
|
export LESSMETACHARS LESSOPEN
|
|
|
|
|
|
|
|
exec less "$@"
|