zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: PATCH: 3.1.5-pws-5 + glob ordering: zls
Date: Wed, 27 Jan 1999 11:07:43 +0100	[thread overview]
Message-ID: <9901271007.AA13314@ibmth.df.unipi.it> (raw)

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@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


                 reply	other threads:[~1999-01-27 10:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=9901271007.AA13314@ibmth.df.unipi.it \
    --to=pws@ibmth.df.unipi.it \
    --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).