zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: first go at directory info in completion.
@ 2009-08-18 10:33 Peter Stephenson
  2009-08-18 11:51 ` Nikolai Weibull
  2013-03-21 17:33 ` Mikael Magnusson
  0 siblings, 2 replies; 8+ messages in thread
From: Peter Stephenson @ 2009-08-18 10:33 UTC (permalink / raw)
  To: Zsh hackers list

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'


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: PATCH: first go at directory info in completion.
  2009-08-18 10:33 PATCH: first go at directory info in completion Peter Stephenson
@ 2009-08-18 11:51 ` Nikolai Weibull
  2009-08-18 12:00   ` Peter Stephenson
  2013-03-21 17:33 ` Mikael Magnusson
  1 sibling, 1 reply; 8+ messages in thread
From: Nikolai Weibull @ 2009-08-18 11:51 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On Tue, Aug 18, 2009 at 12:33, Peter Stephenson<pws@csr.com> wrote:
> 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).

I won’t make any such comment and I have no tweak to mention, I just
have a wish for a use case for this addition.  I don’t see the
immediate use for it.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: PATCH: first go at directory info in completion.
  2009-08-18 11:51 ` Nikolai Weibull
@ 2009-08-18 12:00   ` Peter Stephenson
  2009-08-18 14:55     ` Vincent Lefevre
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2009-08-18 12:00 UTC (permalink / raw)
  To: Zsh hackers list

Nikolai Weibull wrote:
> On Tue, Aug 18, 2009 at 12:33, Peter Stephenson<pws@csr.com> wrote:
> > 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).
> 
> I won't make any such comment and I have no tweak to mention, I just
> have a wish for a use case for this addition.  I don't see the
> immediate use for it.

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.

The main problem at the moment is that while it's fine when every
completion is in that form, it's quite confusing if there are a mixture
of types.

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


'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'


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: PATCH: first go at directory info in completion.
  2009-08-18 12:00   ` Peter Stephenson
@ 2009-08-18 14:55     ` Vincent Lefevre
  2009-08-22 16:55       ` Mikael Magnusson
  0 siblings, 1 reply; 8+ messages in thread
From: Vincent Lefevre @ 2009-08-18 14:55 UTC (permalink / raw)
  To: Zsh hackers list

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).

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: PATCH: first go at directory info in completion.
  2009-08-18 14:55     ` Vincent Lefevre
@ 2009-08-22 16:55       ` Mikael Magnusson
  2009-08-24  8:43         ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Mikael Magnusson @ 2009-08-22 16:55 UTC (permalink / raw)
  To: Zsh hackers list

2009/8/18 Vincent Lefevre <vincent@vinc17.org>:
> 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: PATCH: first go at directory info in completion.
  2009-08-22 16:55       ` Mikael Magnusson
@ 2009-08-24  8:43         ` Peter Stephenson
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 2009-08-24  8:43 UTC (permalink / raw)
  To: Zsh hackers list

Mikael Magnusson wrote:
> 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.

Generic functions for directory information shouldn't be a big deal.
They can then use any available caching mechanism they feel like.

> 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).

I think it will have to split the arguments to "compadd" into two,
passing the dirinfo parts with the -J or -V replaced appropriately.  To
do this with a minimum of duplication it would probably be best to make
_list_files responsible for running compadd by passing the compadd
arguments down.  It can then run it twice when necessary.

(This is the sort of addition rewriting won't help you with unless you
explicitly make sure it does, which is why I'm suspicious of the idea of
a rewrite as some kind of panacea for everything.  It would make it more
maintainable, but that's basically all.)

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


'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'


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: PATCH: first go at directory info in completion.
  2009-08-18 10:33 PATCH: first go at directory info in completion Peter Stephenson
  2009-08-18 11:51 ` Nikolai Weibull
@ 2013-03-21 17:33 ` Mikael Magnusson
  2013-03-24 18:01   ` Peter Stephenson
  1 sibling, 1 reply; 8+ messages in thread
From: Mikael Magnusson @ 2013-03-21 17:33 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh workers

Hi,

I was just curious if you've fiddled with this any more since you
posted it. I found it commented out in my .zshrc earlier today and
realized that while it's a bit annoying to keep on at all times, it's
quite useful to have bound to another key. eg,

zstyle ':completion:dirprop:*' file-list dirprop=user.notes # with my
follow-up patch
zstyle ':completion:dirprop:*' dirinfo-format '%f '${(%):-%F{11}}%i${(%):-%f}
zle -C dirprop complete-word _generic
bindkey "^_^V"    dirprop

On 18 August 2009 12:33, Peter Stephenson <pws@csr.com> wrote:
> 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.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: PATCH: first go at directory info in completion.
  2013-03-21 17:33 ` Mikael Magnusson
@ 2013-03-24 18:01   ` Peter Stephenson
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 2013-03-24 18:01 UTC (permalink / raw)
  To: zsh workers

On Thu, 21 Mar 2013 18:33:05 +0100
Mikael Magnusson <mikachu@gmail.com> wrote:
> I was just curious if you've fiddled with this any more since you
> posted it.

No, I don't think I've gone near it since.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-03-24 18:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-18 10:33 PATCH: first go at directory info in completion Peter Stephenson
2009-08-18 11:51 ` Nikolai Weibull
2009-08-18 12:00   ` Peter Stephenson
2009-08-18 14:55     ` Vincent Lefevre
2009-08-22 16:55       ` Mikael Magnusson
2009-08-24  8:43         ` Peter Stephenson
2013-03-21 17:33 ` Mikael Magnusson
2013-03-24 18:01   ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).