Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: 3.1.5-pws-5 + glob ordering: zls
- X-seq: zsh-workers 5054
- From: Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx (Zsh hackers list)
- Subject: PATCH: 3.1.5-pws-5 + glob ordering: zls
- Date: Wed, 27 Jan 1999 11:07:43 +0100
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
Here's a modification of the shell function zls to do two things: it
uses Phil's -H option to assign to an assoc array for clarity, and it
handles the -t option, together with -u and -c, using Sven's O
glob qualifier. I think the way I got it to reorder an existing
argument list by time, as ls does with -t, works even when there are
funny characters in the file name. I should have done that to reorder
the list by name without -t, but I didn't have the heart.
--- Functions/zls.t Thu Jun 12 01:50:17 1997
+++ Functions/zls Wed Jan 27 11:02:44 1999
@@ -6,12 +6,13 @@
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 @@
[[ $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[@]"
--
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx> Tel: +39 050 844536
WWW: http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy
Messages sorted by:
Reverse Date,
Date,
Thread,
Author