diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2006-03-07 12:50:56 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2006-03-07 12:50:56 +0000 |
commit | e17fc5079394ce0c30dc0573676983e6f4a0a5bc (patch) | |
tree | 06981ab59bbc3b81d9d18cc8dd1daf8a7301ddad /Completion/Unix/Type/_list_files | |
parent | 1c06bba93159db354447d6edc31e76e5b1ae736c (diff) | |
download | zsh-e17fc5079394ce0c30dc0573676983e6f4a0a5bc.tar.gz zsh-e17fc5079394ce0c30dc0573676983e6f4a0a5bc.tar.xz zsh-e17fc5079394ce0c30dc0573676983e6f4a0a5bc.zip |
22328, modified: add -o option to compadd
add _list_files helper to handle new file-list style for _path_files
Diffstat (limited to 'Completion/Unix/Type/_list_files')
-rw-r--r-- | Completion/Unix/Type/_list_files | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/Completion/Unix/Type/_list_files b/Completion/Unix/Type/_list_files new file mode 100644 index 000000000..2166ac6cc --- /dev/null +++ b/Completion/Unix/Type/_list_files @@ -0,0 +1,66 @@ +#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 +local -a stylevals +integer ok + +listfiles=() +listopts=() + +zmodload -i zsh/stat 2>/dev/null || return 1 + +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 + +for f in ${(P)1}; do + if [[ ! -e "${2:+$2/}$f" ]]; then + listfiles+=("${2:+$2/}$f") + continue + fi + + # Borrowed from Functions/Example/zls + stat -s -H stat -F "%b %e %H:%M" - "${2:+$2/}$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 |