xzless 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. # Copyright (C) 1998, 2002, 2006, 2007 Free Software Foundation
  3. # The original version for gzip was written by Paul Eggert.
  4. # Modified for XZ Utils by Andrew Dudman and Lasse Collin.
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #SET_PATH - This line is a placeholder to ease patching this script.
  14. # Instead of unsetting XZ_OPT, just make sure that xz will use file format
  15. # autodetection. This way memory usage limit and thread limit can be
  16. # specified via XZ_OPT.
  17. xz='xz --format=auto'
  18. version='xzless (XZ Utils) 5.4.2'
  19. usage="Usage: ${0##*/} [OPTION]... [FILE]...
  20. Like 'less', but operate on the uncompressed contents of xz compressed FILEs.
  21. Options are the same as for 'less'.
  22. Report bugs to <xz@tukaani.org>."
  23. case $1 in
  24. --help) printf '%s\n' "$usage" || exit 2; exit;;
  25. --version) printf '%s\n' "$version" || exit 2; exit;;
  26. esac
  27. if test "${LESSMETACHARS+set}" != set; then
  28. # Work around a bug in less 394 and earlier;
  29. # it mishandles the metacharacters '$%=~'.
  30. space=' '
  31. tab=' '
  32. nl='
  33. '
  34. LESSMETACHARS="$space$tab$nl'"';*?"()<>[|&^`#\$%=~'
  35. fi
  36. if test "$(less -V | { read _ ver _ && echo ${ver%%.*}; })" -ge 429; then
  37. # less 429 or later: LESSOPEN pipe will be used on
  38. # standard input if $LESSOPEN begins with |-.
  39. LESSOPEN="|-$xz -cdfqQ -- %s"
  40. else
  41. LESSOPEN="|$xz -cdfqQ -- %s"
  42. fi
  43. export LESSMETACHARS LESSOPEN
  44. exec less "$@"