mirror of https://git.tukaani.org/xz.git
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.
This commit is contained in:
parent
a7f5d2fe48
commit
1d314b81aa
|
@ -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 "$@"
|
||||
|
|
Loading…
Reference in New Issue