Path: utzoo!utgpu!watmath!clyde!att!pacbell!well!pokey From: pokey@well.UUCP (Jef Poskanzer) Newsgroups: comp.sources.d Subject: Re: using curses from a script? Message-ID: <7756@well.UUCP> Date: 26 Nov 88 01:16:26 GMT References: <8812@dunkshot.mips.COM> Reply-To: Jef Poskanzer Organization: Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal Lines: 73 In the referenced message, dce@mips.COM (David Elliott) wrote: >Tput is quite useful. With it, I was able to rewrite the hgrep filter >posted to comp.sources.unix last week as a sed script: Yes, that's exactly what I was thinking of when I posted my query about curses from scripts. However, it turns out that the various script versions of hgrep are noticably slower than the C version. Oh well. By the way, if you want a script version that handles -i, see below. --- Jef Jef Poskanzer jef@rtsg.ee.lbl.gov ...well!pokey "SCIENCE!" #!/bin/csh -f # # hgrep - highlight results of grep # # By Jef Poskanzer - an elaboration of Amos Shapir's version. # Figure out which grep to use. set fname="$0" set name="${fname:t}" switch ( "$name" ) case hgrep: set grep=grep breaksw case hegrep: set grep=egrep breaksw case hfgrep: set grep=fgrep breaksw case hngrep: set grep=ngrep breaksw default: set grep=grep endsw # Scan args. foreach i ( $argv ) switch ( "$i" ) case -i: set iflag breaksw case -*: breaksw default: set word="$i" goto out endsw end out: # Case insensitive? if ( $?iflag ) then set word="`echo "$word" | sed -e 's/[Aa]/[Aa]/g' -e 's/[Bb]/[Bb]/g' -e 's/[Cc]/[Cc]/g' -e 's/[Dd]/[Dd]/g' -e 's/[Ee]/[Ee]/g' -e 's/[Ff]/[Ff]/g' -e 's/[Gg]/[Gg]/g' -e 's/[Hh]/[Hh]/g' -e 's/[Ii]/[Ii]/g' -e 's/[Jj]/[Jj]/g' -e 's/[Kk]/[Kk]/g' -e 's/[Ll]/[Ll]/g' -e 's/[Mm]/[Mm]/g' -e 's/[Nn]/[Nn]/g' -e 's/[Oo]/[Oo]/g' -e 's/[Pp]/[Pp]/g' -e 's/[Qq]/[Qq]/g' -e 's/[Rr]/[Rr]/g' -e 's/[Ss]/[Ss]/g' -e 's/[Tt]/[Tt]/g' -e 's/[Uu]/[Uu]/g' -e 's/[Vv]/[Vv]/g' -e 's/[Ww]/[Ww]/g' -e 's/[Xx]/[Xx]/g' -e 's/[Yy]/[Yy]/g' -e 's/[Zz]/[Zz]/g'`" endif # Here be terminal dependencies. set so="[7m" se="[m" # And do it. $grep ${argv[1-]} | sed -e "s/$word/$so&$se/g"