about summary refs log tree commit diff
path: root/Functions/Misc/zless
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-06-08 09:26:01 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-06-08 09:26:01 +0000
commitfcd7cd1cfa2ba286f4bf73da7a60116cd3912629 (patch)
treed2aa5a9369bf3af8841d3abde69f52bd483f5526 /Functions/Misc/zless
parentb39cafaa22ad7efc2ac4b64a5eeac8f49bc80e00 (diff)
downloadzsh-fcd7cd1cfa2ba286f4bf73da7a60116cd3912629.tar.gz
zsh-fcd7cd1cfa2ba286f4bf73da7a60116cd3912629.tar.xz
zsh-fcd7cd1cfa2ba286f4bf73da7a60116cd3912629.zip
Initial revision
Diffstat (limited to 'Functions/Misc/zless')
-rw-r--r--Functions/Misc/zless37
1 files changed, 37 insertions, 0 deletions
diff --git a/Functions/Misc/zless b/Functions/Misc/zless
new file mode 100644
index 000000000..809ce35c7
--- /dev/null
+++ b/Functions/Misc/zless
@@ -0,0 +1,37 @@
+#!/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
+# Modified by Bart Schaefer.
+# 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 . =(...)
+#
+# 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.
+#
+
+emulate -R zsh
+setopt localoptions
+
+[[ $# -ge 1 ]] || return
+local lessopts
+set -A lessopts
+integer i=1 loi=1
+while ((i <= $#))
+do
+  case $argv[i] in
+  -zforce) argv[i,i+2]=("=($argv[i+1] \"$argv[i+2]\")"); ((++i));;
+  -*) lessopts[loi++]=\"$argv[i]\"; argv[i]=(); continue;;
+  *.(gz|Z)) argv[i]="=(zcat \"$argv[i]\")";;
+  *.bz2) argv[i]="=(bzip2 -dc \"$argv[i]\")";;
+  *.bz) argv[i]="=(bzip -dc \"$argv[i]\")";;
+  esac
+  ((++i))
+done
+eval command less $lessopts $*