diff options
author | Paul Ackersviller <packersv@users.sourceforge.net> | 2007-12-03 02:31:49 +0000 |
---|---|---|
committer | Paul Ackersviller <packersv@users.sourceforge.net> | 2007-12-03 02:31:49 +0000 |
commit | b32f902ba598c851196b037178233477c2411876 (patch) | |
tree | b7cbfbe7ef82be75804f4a1c1800506208b7d489 /Completion/Unix/Type/_list_files | |
parent | 79a0a88e660f0b4027a75d374efb7ffba3011adc (diff) | |
download | zsh-b32f902ba598c851196b037178233477c2411876.tar.gz zsh-b32f902ba598c851196b037178233477c2411876.tar.xz zsh-b32f902ba598c851196b037178233477c2411876.zip |
Bring various .distfiles up to date and merge any extra completions onto 4.2 branch.
Diffstat (limited to 'Completion/Unix/Type/_list_files')
-rw-r--r-- | Completion/Unix/Type/_list_files | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/Completion/Unix/Type/_list_files b/Completion/Unix/Type/_list_files new file mode 100644 index 000000000..5e745d9d1 --- /dev/null +++ b/Completion/Unix/Type/_list_files @@ -0,0 +1,69 @@ +#autoload + +# Helper function for _path_files to handle the file-list style. + +# arguments: +# name of parameter containing file matches +# directory prefix +# Sets array listfiles to the display strings and the array +# listopts appropriately to be added to the compadd command line. + +local stat f elt what dir +local -a stylevals +integer ok + +listfiles=() +listopts=() + +zstyle -a ":completion:${curcontext}:" file-list stylevals || return 1 + +# TODO: more flexible way of handling the following? e.g. use $compstate? +case $WIDGETSTYLE in + (*complete*) + what=insert + ;; + + (*) + what=list + ;; +esac + +for elt in $stylevals; do + case $elt in + (*($what|all|true|1|yes)*=<->) + # use long format if no more than the given number of matches + (( ${(P)#1} <= ${elt##*=} )) && (( ok = 1 )) + break + ;; + + (*($what|all|true|1|yes)[^=]#) + # always use long format + (( ok = 1 )) + break + ;; + esac +done + +(( ok )) || return 1 + +zmodload -i zsh/stat 2>/dev/null || return 1 + +dir=${2:+$2/} +dir=${(Q)dir} + +for f in ${(PQ)1}; do + if [[ ! -e "$dir$f" ]]; then + listfiles+=("$dir$f") + continue + fi + + # Borrowed from Functions/Example/zls + stat -s -H stat -F "%b %e %H:%M" - "$dir$f" >/dev/null 2>&1 + + listfiles+=("$stat[mode] ${(l:3:)stat[nlink]} ${(r:8:)stat[uid]} \ + ${(r:8:)stat[gid]} ${(l:8:)stat[size]} $stat[mtime] $f") +done + +(( ${#listfiles} )) && listopts=(-d listfiles -l -o) + +return 0 |