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

Re: PATCH: first go at directory info in completion.



2009/8/18 Vincent Lefevre <vincent@xxxxxxxxxx>:
> On 2009-08-18 13:00:50 +0100, Peter Stephenson wrote:
>> Sometimes you have sets of directories with cryptic names, for example
>> named after bug records, in which you keep information to do with
>> it---anything vaguely database-related gives you this sort of
>> arrangement, in fact.  Rather than seeing completion lists like
>>
>> BUG0001  BUG0002  BUG0003 BUG0004
>>
>> you now create a one-line file (say .zshinfo) in each directory
>> describing the directory.  Then you can get completion lists looking
>> like
>>
>> BUG0001  # Light switch failed to illuminate room
>> BUG0002  # Light bulb in south east corner of room broken
>> BUG0003  # Wiring behind light switch worn
>> BUG0004  # Loose screw on diffusor in south west corner of room
>>
>> so when changing directory you no longer have to remember a set of
>> 4-digit numbers.
>
> This is nice. However I'd like to see this very configurable. For
> instance, as a Subversion user, I'd rather see such a description
> as a svn property (which would follow the file with "svn mv").
> I hope this would still be efficient enough (or some file like
> .zshinfo could be used as a cache).

I imagine you could make it use (an array of?) function hooks that
you can define yourself, like is done for precmd and friends. In the
meantime I made a quick hack to use xattrs via the z*attr commands I
added a while back.

I also noticed that when in this long list format, all coloring from
file types and etc is lost, is there any way to have both? (without
doing the fabled rewrite).

http://git.mika.l3ib.org/?p=zsh-cvs.git;a=commitdiff;h=97b96f4f1319288b44be00f74781d7e8def76750
(url since the following will probably be corrupted by gmail)

This is on top of pws' patch,

--- a/Completion/Unix/Type/_list_files
+++ b/Completion/Unix/Type/_list_files
@@ -8,7 +8,7 @@
 # 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 dirfile dirformat
+local stat f elt what dir dirfile dirformat reply dirprop
 local -a stylevals
 integer ok active

@@ -44,12 +44,17 @@ for elt in $stylevals; do
     dirfile=${~elt##dirinfo=}
     (( ok )) || (( ok = 2 ))
     ;;
+
+    (dirprop=*)
+    dirprop=${~elt##dirprop=}
+    (( ok )) || (( ok = 2 ))
+    ;;
   esac
 done

 (( ok )) || return 1

-if [[ -n $dirfile ]]; then
+if [[ -n $dirfile || -n $dirprop ]]; then
   zstyle -s ":completion:${curcontext}:" dirinfo-format dirformat ||
   dirformat="%f [%i]"
 fi
@@ -68,6 +73,19 @@ for f in ${(PQ)1}; do
     zformat -f what "$dirformat" d:$dir f:$f i:"$(<$dir$f/$dirfile)"
     listfiles+=("$what")
     (( active++ ))
+  elif [[ -n $dirprop ]]; then
+    zlistattr $dir$f reply >& /dev/null
+    if [[ ${${(0)reply}[(I)$dirprop]} -gt 0 ]]; then
+      zgetattr $dir$f $dirprop reply >& /dev/null
+      zformat -f what "$dirformat" d:$dir f:$f i:$reply
+      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
+    fi
   elif (( ok != 1 )); then
     listfiles+=("$f")
   else


(sorry about the copy of the elif+else, i was a bit lazy there :)


-- 
Mikael Magnusson



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