public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] Using less with compressed docs -- tip!
@ 2001-09-08 15:44 Ben Beuchler
  2001-09-08 17:02 ` Morgan Christiansson
  2001-09-09 10:22 ` Karl Trygve Kalleberg
  0 siblings, 2 replies; 3+ messages in thread
From: Ben Beuchler @ 2001-09-08 15:44 UTC (permalink / raw
  To: Gentoo Dev List

Gentoo, by default, compresses any documetation installed by a program.  Or so
it appears, anyway.  Viewing these files transparently is pretty easy.  First,
create a script like this:

----------
#!/bin/sh

case "$1" in
    *.gz) gunzip -c $1 2>/dev/null
    ;;
esac
----------

And put it somewhere easily accessible, like /usr/local/bin/lesspipe.sh.

Now do this:

export LESSOPEN="|/usr/local/bin/lesspipe.sh %s" 

You'll probably want to stick that in /etc/profile or something.  Now if you
try to use less top open a .gz file, it will work transparently.

-Ben

-- 
Ben Beuchler                                           There is no spoon.
insyte@emt-p.org                                            -- The Matrix



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gentoo-dev] Using less with compressed docs -- tip!
  2001-09-08 15:44 [gentoo-dev] Using less with compressed docs -- tip! Ben Beuchler
@ 2001-09-08 17:02 ` Morgan Christiansson
  2001-09-09 10:22 ` Karl Trygve Kalleberg
  1 sibling, 0 replies; 3+ messages in thread
From: Morgan Christiansson @ 2001-09-08 17:02 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 1201 bytes --]

Redhat has a shell-script called /usr/bin/zless:

#!/bin/sh
/bin/zcat "$@" | /usr/bin/less

(zcat is hard-linked to gzip and gunzip)

/usr/bin/zmore also exists and is the same but has a much more 
complicated shell script.

It sets some terminal options and stuff.

I attached some files there are a bunch more too.

These are the executables in redhats gzip package.

/bin/gunzip
/bin/gzip
/bin/zcat
/usr/bin/gunzip
/usr/bin/gzexe
/usr/bin/gzip
/usr/bin/zcmp
/usr/bin/zdiff
/usr/bin/zegrep
/usr/bin/zfgrep
/usr/bin/zforce
/usr/bin/zgrep
/usr/bin/zless
/usr/bin/zmore
/usr/bin/znew



Ben Beuchler wrote:

>Gentoo, by default, compresses any documetation installed by a program.  Or so
>it appears, anyway.  Viewing these files transparently is pretty easy.  First,
>create a script like this:
>
>----------
>#!/bin/sh
>
>case "$1" in
>    *.gz) gunzip -c $1 2>/dev/null
>    ;;
>esac
>----------
>
>And put it somewhere easily accessible, like /usr/local/bin/lesspipe.sh.
>
>Now do this:
>
>export LESSOPEN="|/usr/local/bin/lesspipe.sh %s" 
>
>You'll probably want to stick that in /etc/profile or something.  Now if you
>try to use less top open a .gz file, it will work transparently.
>
>-Ben
>



[-- Attachment #2: zless --]
[-- Type: text/plain, Size: 41 bytes --]

#!/bin/sh
/bin/zcat "$@" | /usr/bin/less

[-- Attachment #3: zmore --]
[-- Type: text/plain, Size: 1077 bytes --]

#!/bin/sh

PATH="/bin:$PATH"; export PATH
if test "`echo -n a`" = "-n a"; then
  # looks like a SysV system:
  n1=''; n2='\c'
else
  n1='-n'; n2=''
fi
oldtty=`stty -g 2>/dev/null`
if stty -cbreak 2>/dev/null; then
  cb='cbreak'; ncb='-cbreak'
else
  # 'stty min 1' resets eof to ^a on both SunOS and SysV!
  cb='min 1 -icanon'; ncb='icanon eof ^d'
fi
if test $? -eq 0 -a -n "$oldtty"; then
   trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15
else
   trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15
fi

if test $# = 0; then
    if test -t 0; then
	echo usage: zmore files... 1>&2
	exit 1
    else
	gzip -cdfq | eval ${PAGER-more}
    fi
else
    FIRST=1
    for FILE
    do
	if test $FIRST -eq 0; then
		echo $n1 "--More--(Next file: $FILE)$n2"
		stty $cb -echo 2>/dev/null
		ANS=`dd bs=1 count=1 2>/dev/null` 
		stty $ncb echo 2>/dev/null
		echo " "
		if test "$ANS" = 'e' -o "$ANS" = 'q'; then
			exit
		fi
	fi
	if test "$ANS" != 's'; then
		echo "------> $FILE <------"
		gzip -cdfq "$FILE" | eval ${PAGER-more}
	fi
	if test -t; then
		FIRST=0
	fi
    done
fi

[-- Attachment #4: zgrep --]
[-- Type: text/plain, Size: 1417 bytes --]

#!/bin/sh

# zgrep -- a wrapper around a grep program that decompresses files as needed
# Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>

PATH="/bin:$PATH"; export PATH

prog=`echo $0 | sed 's|.*/||'`
case "$prog" in
	*egrep)	grep=${EGREP-egrep}	;;
	*fgrep)	grep=${FGREP-fgrep}	;;
	*)	grep=${GREP-grep}	;;
esac
pat=""
while test $# -ne 0; do
  case "$1" in
  -e | -f) opt="$opt $1"; shift; pat="$1"
           if test "$grep" = grep; then  # grep is buggy with -e on SVR4
             grep=egrep
           fi;;
  -A | -B) opt="$opt $1 $2"; shift;;
  -*)	   opt="$opt $1";;
   *)      if test -z "$pat"; then
	     pat="$1"
	   else
	     break;
           fi;;
  esac
  shift
done

if test -z "$pat"; then
  echo "grep through gzip files" 1>&2
  echo "usage: $prog [grep_options] pattern [files]" 1>&2
  exit 1
fi

list=0
silent=0
op=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
case "$op" in
  *l*) list=1
esac
case "$op" in
  *h*) silent=1
esac

if test $# -eq 0; then
  gzip -cdfq | $grep $opt "$pat"
  exit $?
fi

res=0
trap break SIGPIPE
for i do
  if test $list -eq 1; then
    gzip -cdfq "$i" | $grep $opt "$pat" > /dev/null && echo $i
    r=$?
  elif test $# -eq 1 -o $silent -eq 1; then
    gzip -cdfq "$i" | $grep $opt "$pat"
    r=$?
  else
    gzip -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${i}:|"
    r=$?
  fi
  test "$r" -ne 0 && res="$r"
  echo
done
trap - SIGPIPE
exit $res

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gentoo-dev] Using less with compressed docs -- tip!
  2001-09-08 15:44 [gentoo-dev] Using less with compressed docs -- tip! Ben Beuchler
  2001-09-08 17:02 ` Morgan Christiansson
@ 2001-09-09 10:22 ` Karl Trygve Kalleberg
  1 sibling, 0 replies; 3+ messages in thread
From: Karl Trygve Kalleberg @ 2001-09-09 10:22 UTC (permalink / raw
  To: gentoo-dev

Alternatively, you could run most, which is way cooler than less anyway ;)

Karl T



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-09-09 16:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-09-08 15:44 [gentoo-dev] Using less with compressed docs -- tip! Ben Beuchler
2001-09-08 17:02 ` Morgan Christiansson
2001-09-09 10:22 ` Karl Trygve Kalleberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox