bzmore 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. # Bzmore wrapped for bzip2,
  3. # adapted from zmore by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
  4. PATH="/usr/bin:$PATH"; export PATH
  5. prog=`echo $0 | sed 's|.*/||'`
  6. case "$prog" in
  7. *less) more=less ;;
  8. *) more=more ;;
  9. esac
  10. if test "`echo -n a`" = "-n a"; then
  11. # looks like a SysV system:
  12. n1=''; n2='\c'
  13. else
  14. n1='-n'; n2=''
  15. fi
  16. oldtty=`stty -g 2>/dev/null`
  17. if stty -cbreak 2>/dev/null; then
  18. cb='cbreak'; ncb='-cbreak'
  19. else
  20. # 'stty min 1' resets eof to ^a on both SunOS and SysV!
  21. cb='min 1 -icanon'; ncb='icanon eof ^d'
  22. fi
  23. if test $? -eq 0 -a -n "$oldtty"; then
  24. trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15
  25. else
  26. trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15
  27. fi
  28. if test $# = 0; then
  29. if test -t 0; then
  30. echo usage: $prog files...
  31. else
  32. bzip2 -cdfq | eval $more
  33. fi
  34. else
  35. FIRST=1
  36. for FILE
  37. do
  38. if test $FIRST -eq 0; then
  39. echo $n1 "--More--(Next file: $FILE)$n2"
  40. stty $cb -echo 2>/dev/null
  41. ANS=`dd bs=1 count=1 2>/dev/null`
  42. stty $ncb echo 2>/dev/null
  43. echo " "
  44. if test "$ANS" = 'e' -o "$ANS" = 'q'; then
  45. exit
  46. fi
  47. fi
  48. if test "$ANS" != 's'; then
  49. echo "------> $FILE <------"
  50. bzip2 -cdfq "$FILE" | eval $more
  51. fi
  52. if test -t; then
  53. FIRST=0
  54. fi
  55. done
  56. fi