zsh-workers
 help / color / mirror / code / Atom feed
From: Phil Pennock <comet@fysh.org>
To: Zsh Development Workers <zsh-workers@sunsite.auc.dk>
Subject: Example function
Date: Tue, 26 Jan 1999 18:42:00 +0000	[thread overview]
Message-ID: <19990126184200.B27794@fysh.org> (raw)

Hi,

      
A couple of months back zefram decided that he wanted one of my sicker
zsh shell functions for the examples.  I gave it to him then.  Here it  
is again for inclusion.

      
It's a zless which automatically determines from the file extension
which decompressor to use.  The comments explain it.  This has evolved
over about a year and a half, hence my needing help sorting out the
array bit.

Uhm, have fun or whatever.  Peter, any chance of this going in your next
sub-distrib?

Thanks

PS: Note that the last line is 108 chars long; your mailer may
interfere?

-----------------------------< cut here >-------------------------------
#!/usr/bin/zsh -f
#
# zsh function script to run less on various inputs, decompressing as required.
# Author: Phil Pennock.  zsh-hacks@athenaeum.demon.co.uk
# Thanks to zefram@fysh.org for a great deal of help in sorting this out,
# ie wrt syntax for unsetting members of arrays and eval "$(...)" when I
# asked for something better than . =(...)
# Other than that the whole sick beauty is mine.
#
# Use -zforce to pass through a display-formatting command
#  zless -zforce 'bzip2 -dc' foo-no-dotbz2
#  zless -zforce 'od -hc' foo-binfile
#
# If you can understand all of this without reference to zshexpn(1)
# and zshparam(1) then you either have a photographic memory or you
# need to get out more.
#

[[ $# -ge 1 ]] || return
local -i i loi max
local dispfunc lessopts
set -A dispfunc
set -A lessopts
loi=1 
max=$[$#+1]
for ((i=1; i != $max ; ++i))
do
	dispfunc[i]='<' 
	[[ $argv[i] = \-zforce ]] && {
		dispfunc[i+2]="$argv[i+1]"
		argv[i,i+1]=()
		dispfunc[i,i+1]=()
		let max-=2
		continue
	}
	[[ $argv[i] = \-* ]] && {
		lessopts[loi++]="$argv[i]" 
		argv[i,i]=()
		dispfunc[i,i]=()
		let max-=1
		let i-=1
		continue
	}
	[[ $argv[i] = *.gz ]] && dispfunc[i]=zcat 
	[[ $argv[i] = *.bz2 ]] && dispfunc[i]='bzip2 -dc' 
	[[ $argv[i] = *.Z ]] && dispfunc[i]=zcat 
	[[ $argv[i] = *.bz ]] && dispfunc[i]='bzip -dc' 
done
eval "$(print command less "${(@)lessopts}" "=($dispfunc[i=1] \"${(@Nej:\") =($dispfunc[++i] \":)argv}\")")"
-----------------------------< cut here >-------------------------------
-- 
--> Phil Pennock ; GAT d- s+:+ a23 C++(++++) UL++++/I+++/S+++/B++/H+$ P++@$
L+++ E-@ W(+) N>++ o !K w--- O>+ M V !PS PE Y+ PGP+ t-- 5++ X+ R !tv b++>+++
DI+ D+ G+ e+ h* r y?


             reply	other threads:[~1999-01-26 18:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-01-26 18:42 Phil Pennock [this message]
1999-01-27  0:25 ` Bart Schaefer
1999-01-27  0:37   ` Bart Schaefer
1999-02-01 10:48 Sven Wischnowsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19990126184200.B27794@fysh.org \
    --to=comet@fysh.org \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).