Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Re: Call for neat examples



On Tue, Mar 03, 1998 at 09:13:40PM -0500, Timothy J Luoma wrote:
> 	Author:        Sven Guckes <guckes@xxxxxxxxxxxxxxxxx>
> 	Original-Date: Mon, 2 Mar 1998 18:02:51 +0100
> 	Message-ID:    <19980302180251.10544@xxxxxxxxxxxxxxxxx>
> 
> > How will you make it available?  Perhaps on a webpage?
> 
> Sure.  I'm "maintaining" the ZSH web pages as it is...
> 
> But people have to submit some first :-)
> 
> So far I haven't gotten a single entry.

	i've thought about this a lot, and i don't know if it will work, or at 
least, if it will work and still be a "zsh" page.  most of the functionality 
that my on functions provide, at least, are only somewhat zsh-specific; zsh 
makes it much easier to do things, but most of the times (in my functions) it 
doesn't do everything itself, or in a zsh-specific way.
	
	for example, here's a quick (well, not so quick, because I was making a 
really stupid mistake) function called nobrs that i just wrote for myself:
	
#!/usr/local/bin/zsh
nobrs () {

case ${1} in 
   -[0-9]*) lines=${1#-} ; shift ;;
    *) lines=2 ;;
esac ;

while [[ -n ${1} ]] ; do
   awkstring="awk 'BEGIN {count = 0;} /^$/ {count++; if (count < ${lines}) 
print; next;} {print \$0; count = 0;}' ${1}" ;
   shift ;
   eval ${awkstring} ;
done ;

}

	nobrs by default removes any newlines more than 2 from whatever file(s) 
it gets on the command-line; if the first argument is a hyphen followed by any 
digits, it sets the maximum number of consecutive linebreaks to the number 
formed by those digits.  most of the work, however, is done by an awk 
command-line.  (tangentially, is there any way to get rid of that awk line and 
do this all in zsh?)  the while...done and case...esac loops are shell tricks, 
but aren't zsh-specific; ditto for the ${1#-}.  really, this is a ksh script 
that happens to be a zsh function because i use zsh.
	while this would have been something i would have loved to have seen 
when i was first scripting, then, it wouldn't have been something i would have 
looked for as a "zsh script", or expected to have found as such.  there are, of 
course, examples that would use zsh-specific features, but in most cases, i 
think that those features would be used minimally in comparison to the more 
general parts of the function.
	i guess my question is, are you envisioning this as a example-based 
guide to zsh features, or just as a collection of cool functions used by people 
who use zsh?  i'd love the former, of course, since i know that i definitely 
underuse zsh features, but have a feeling that it would turn into the latter.
	not that there's anything wrong with that, of course; i would also love 
to just get a look at some nifty scripts in general.
	
	does anyone else have any input on this?
	
	-- sweth.
-- 
"Countin' on a remedy I've counted on before
Goin' with a cure that's never failed me
What you call the disease
I call the remedy"  -- The Mighty Mighty Bosstones



Messages sorted by: Reverse Date, Date, Thread, Author