about summary refs log tree commit diff
path: root/Functions
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-04-15 18:12:56 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-04-15 18:12:56 +0000
commit7a40d6c258ad87d147ee5d6839e746c33ebc0ac7 (patch)
treef1330b87515dca18f200b2ea435842de26ada0e9 /Functions
parent20d67907c95265356b51dbdce8ecc0c1ede9e66b (diff)
downloadzsh-7a40d6c258ad87d147ee5d6839e746c33ebc0ac7.tar.gz
zsh-7a40d6c258ad87d147ee5d6839e746c33ebc0ac7.tar.xz
zsh-7a40d6c258ad87d147ee5d6839e746c33ebc0ac7.zip
zsh-3.1.5-pws-6 zsh-3.1.5-pws-6
Diffstat (limited to 'Functions')
-rw-r--r--Functions/zless37
-rw-r--r--Functions/zls37
2 files changed, 64 insertions, 10 deletions
diff --git a/Functions/zless b/Functions/zless
new file mode 100644
index 000000000..809ce35c7
--- /dev/null
+++ b/Functions/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 $*
diff --git a/Functions/zls b/Functions/zls
index da6eff856..f2299903c 100644
--- a/Functions/zls
+++ b/Functions/zls
@@ -6,12 +6,13 @@ zmodload -i stat || return 1
 emulate -R zsh
 setopt localoptions
 
-local f stat opts='' L=L mod=: dirs list
+local f opts='' L=L mod=: dirs list
+typeset -A stat
 
 dirs=()
 list=()
 
-while getopts ailLFd f
+while getopts ailLFdtuc f
 do
     opts=$opts$f
     if [[ $f == '?' ]] then
@@ -25,24 +26,40 @@ shift OPTIND-1
 [[ $opts == *F* ]] && mod=T$mod
 [[ $opts == *a* ]] && setopt globdots
 
+local time=mtime tmod=m
+[[ $opts == *u* ]] && time=atime tmod=a
+[[ $opts == *c* ]] && time=ctime tmod=c
+
 if ((! ARGC)) then
-    set *
+    if [[ $opts = *t* ]]; then
+        set *(O$tmod)
+    else
+        set *
+    fi
     opts=d$opts
+elif [[ $opts = *t* && $ARGC -gt 1 ]]; then
+    # another glaringly obvious zsh trick:  reorder the argv list
+    # by time, without messing up metacharacters inside
+    local n='$1'
+    for (( f = 2; f <= $ARGC; f++ )); do
+	n="$n|\$$f"
+    done
+    eval "argv=(($n)(O$tmod))"
 fi
 
 for f in $*
 do
-    stat -s$L -A stat -F "%b %e %H:%M" - $f || continue
-    if [[ $opts != *d* && $stat[3] == d* ]] then
+    stat -s$L -H stat -F "%b %e %H:%M" - $f || continue
+    if [[ $opts != *d* && $stat[mode] == d* ]] then
 	dirs=( $dirs $f )
     elif [[ $opts == *l* ]] then
-	[[ $opts == *i* ]] && print -n "${(l:7:)stat[2]} "
-	[[ -n $stat[14] ]] && f=( $f '->' $stat[14] ) || f=( $f($mod) )
-	print -r -- "$stat[3] ${(l:3:)stat[4]} ${(r:8:)stat[5]} " \
-		    "${(r:8:)stat[6]} ${(l:8:)stat[8]} $stat[10] $f"
+	[[ $opts == *i* ]] && print -n "${(l:7:)stat[inode]} "
+	[[ -n $stat[link] ]] && f=( $f '->' $stat[link] ) || f=( $f($mod) )
+	print -r -- "$stat[mode] ${(l:3:)stat[nlink]} ${(r:8:)stat[uid]} " \
+		    "${(r:8:)stat[gid]} ${(l:8:)stat[size]} $stat[$time] $f"
     else
 	f=( $f($mod) )
-	list=( "$list[@]" "${${(M)opts:%*i*}:+${(l:7:)stat[2]} }$f" )
+	list=( "$list[@]" "${${(M)opts:%*i*}:+${(l:7:)stat[inode]} }$f" )
     fi
 done
 (($#list)) && print -cr -- "$list[@]"