1# zls () { 2# simple internal ls using the stat module 3 4zmodload -F zsh/stat b:zstat || return 1 5 6emulate -R zsh 7setopt localoptions 8 9local f opts='' L=L mod=: dirs list 10typeset -A stat 11 12dirs=() 13list=() 14 15while getopts ailLFdtuc f 16do 17 opts=$opts$f 18 if [[ $f == '?' ]] then 19 echo Usage: $0 [ -ailLFd ] [ filename ... ] 20 return 1 21 fi 22done 23shift OPTIND-1 24 25[[ $opts == *L* ]] && L='' 26[[ $opts == *F* ]] && mod=T$mod 27[[ $opts == *a* ]] && setopt globdots 28 29local time=mtime tmod=m 30[[ $opts == *u* ]] && time=atime tmod=a 31[[ $opts == *c* ]] && time=ctime tmod=c 32 33if ((! ARGC)) then 34 if [[ $opts = *t* ]]; then 35 set *(o$tmod) 36 else 37 set * 38 fi 39 opts=d$opts 40elif [[ $opts = *t* && $ARGC -gt 1 ]]; then 41 # another glaringly obvious zsh trick: reorder the argv list 42 # by time, without messing up metacharacters inside 43 local n='$1' 44 for (( f = 2; f <= $ARGC; f++ )); do 45 n="$n|\$$f" 46 done 47 eval "argv=(($n)(o$tmod))" 48fi 49 50for f in $* 51do 52 zstat -s$L -H stat -F "%b %e %H:%M" - $f || continue 53 if [[ $opts != *d* && $stat[mode] == d* ]] then 54 dirs=( $dirs $f ) 55 elif [[ $opts == *l* ]] then 56 [[ $opts == *i* ]] && print -n "${(l:7:)stat[inode]} " 57 [[ -n $stat[link] ]] && f=( $f '->' $stat[link] ) || f=( $f($mod) ) 58 print -r -- "$stat[mode] ${(l:3:)stat[nlink]} ${(r:8:)stat[uid]} " \ 59 "${(r:8:)stat[gid]} ${(l:8:)stat[size]} $stat[$time] $f" 60 else 61 f=( $f($mod) ) 62 list=( "$list[@]" "${${(M)opts:%*i*}:+${(l:7:)stat[inode]} }$f" ) 63 fi 64done 65(($#list)) && print -cr -- "$list[@]" 66while (($#dirs)) do 67 ((ARGC > $#dirs)) && echo 68 ((ARGC > 1)) && echo $dirs[1]: 69 (cd $dirs[1] && $0 -d$opts) 70 shift dirs 71done 72# } 73