1#autoload 2 3# Helper function for _path_files to handle the file-list style. 4 5# arguments: 6# name of parameter containing file matches 7# directory prefix 8# Sets array listfiles to the display strings and the array 9# listopts appropriately to be added to the compadd command line. 10 11local stat f elt what dir 12local -a stylevals 13integer ok 14 15listfiles=() 16listopts=() 17 18zstyle -a ":completion:${curcontext}:" file-list stylevals || return 1 19 20# TODO: more flexible way of handling the following? e.g. use $compstate? 21case $WIDGETSTYLE in 22 (*complete*) 23 what=insert 24 ;; 25 26 (*) 27 what=list 28 ;; 29esac 30 31for elt in $stylevals; do 32 case $elt in 33 (*($what|all|true|1|yes)*=<->) 34 # use long format if no more than the given number of matches 35 (( ${(P)#1} <= ${elt##*=} )) && (( ok = 1 )) 36 break 37 ;; 38 39 (*($what|all|true|1|yes)[^=]#) 40 # always use long format 41 (( ok = 1 )) 42 break 43 ;; 44 esac 45done 46 47(( ok )) || return 1 48 49zmodload -F zsh/stat b:zstat 2>/dev/null || return 1 50 51dir=${2:+$2/} 52dir=${(Q)dir} 53 54for f in ${(PQ)1}; do 55 if [[ ! -e "$dir$f" ]]; then 56 listfiles+=("$dir$f") 57 continue 58 fi 59 60 # Borrowed from Functions/Example/zls 61 zstat -s -H stat -F "%b %e %H:%M" - "$dir$f" >/dev/null 2>&1 62 63 listfiles+=("$stat[mode] ${(l:3:)stat[nlink]} ${(r:8:)stat[uid]} \ 64 ${(r:8:)stat[gid]} ${(l:8:)stat[size]} $stat[mtime] $f") 65done 66 67(( ${#listfiles} )) && listopts=(-d listfiles -l -o) 68 69return 0 70