Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: first go at directory info in completion.



This is work in progress, which won't be committed, so I'm interested in
comments about tweaks (I am not interested in comments about wholesale
rewrites and upgrades of the
wouldn't-it-be-great-if-everything-were-much-much-better variety in this
thread; that's not going to happen).

The file-list style can now take a value dirinfo=<filename>.  If
<filename> exists in a directory, then completion lists show the
contents of <filename> together with the directory.  The style
dirinfo-format can be used to change the display:  %f is the base
filename of the directory, %d is the path to the directory (the bit
usually stripped in completion lists), %i is the contents of
<filename>.

The main problem at the moment seems to be that whenever you have a
directory with information the formatting of the entire completion list
becomes one-per-line.  Grouping would improve this.  However, I'm a bit
worried that this happens at too low a level to add a completion group
(i.e. a different compadd with a different -J or -V option) at this
point consistent with existing tags and labels, which is why I've
stopped at this point for now.

Index: Completion/Unix/Type/_list_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_list_files,v
retrieving revision 1.7
diff -u -r1.7 _list_files
--- Completion/Unix/Type/_list_files	3 Jun 2008 09:30:58 -0000	1.7
+++ Completion/Unix/Type/_list_files	18 Aug 2009 10:18:27 -0000
@@ -8,9 +8,9 @@
 # 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 stat f elt what dir dirfile dirformat
 local -a stylevals
-integer ok
+integer ok active
 
 listfiles=()
 listopts=()
@@ -33,19 +33,27 @@
     (*($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
+    ;;
+
+    (dirinfo=*)
+    dirfile=${~elt##dirinfo=}
+    (( ok )) || (( ok = 2 ))
     ;;
   esac
 done
 
 (( ok )) || return 1
 
+if [[ -n $dirfile ]]; then
+  zstyle -s ":completion:${curcontext}:" dirinfo-format dirformat ||
+  dirformat="%f [%i]"
+fi
+
 zmodload -F zsh/stat b:zstat 2>/dev/null || return 1
 
 dir=${2:+$2/}
@@ -56,14 +64,26 @@
     listfiles+=("$dir$f")
     continue
   fi
+  if [[ -n $dirfile && -f "$dir$f/$dirfile" ]]; then
+    zformat -f what "$dirformat" d:$dir f:$f i:"$(<$dir$f/$dirfile)"
+    listfiles+=("$what")
+    (( active++ ))
+  elif (( ok != 1 )); then
+    listfiles+=("$f")
+  else
+    # Borrowed from Functions/Example/zls
+    zstat -s -H stat -F "%b %e %H:%M" - "$dir$f" >/dev/null 2>&1
 
-  # Borrowed from Functions/Example/zls
-  zstat -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]} \
+    listfiles+=("$stat[mode] ${(l:3:)stat[nlink]} ${(r:8:)stat[uid]} \
  ${(r:8:)stat[gid]} ${(l:8:)stat[size]} $stat[mtime] $f")
+    (( active++ ))
+  fi
 done
 
+# Something to display either if we're using long format
+# or we're displaying directory information.
+(( active )) || return 1
+
 (( ${#listfiles} )) && listopts=(-d listfiles -l -o)
 
 return 0


'member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom'



Messages sorted by: Reverse Date, Date, Thread, Author