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

Re: Command completion slowness? (And PATH order possible?)



On Thu, 13 Oct 2011 06:56:55 +0000
Daniel <quite@xxxxxxxx> wrote:
> Moreover, can I have command completion in PATH order? Specifically I have
> $USER/bin first in my PATH, and would really like first hit partial matches
> from that directory, and later from others.

Hmmm...

Here's a style path-tags that splits up commands into tags based on
the position in the path.  The tags are command-<index>-<name> to allow
you to match on tags in clever ways.  It definitely won't help your
speed problems.

You can then set an appropriate tag-order style, although if you use
group names,

zstyle ':completion:*:complete:*' path-tags true
zstyle ':completion:*' group-name ''
zstyle ':completion:*' format 'Completing %d'

in combination with menu selection you'll get the effect of ordering.

I'm not sure if there's a clever way with tag-order to get command-<->-*
to sort appropriately, but if there isn't there probably ought to be.
(I haven't zero-filled the number so if you had more than 10 entries in
$path you'd need the effect of numericglobsort to get the ordering.)

Doesn't work with the extra-verbose style, though I can't say I have
*that* much sympathy.

Index: Completion/Unix/Type/_path_commands
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_commands,v
retrieving revision 1.6
diff -p -u -r1.6 _path_commands
--- Completion/Unix/Type/_path_commands	2 Nov 2008 14:12:30 -0000	1.6
+++ Completion/Unix/Type/_path_commands	13 Oct 2011 14:34:00 -0000
@@ -80,7 +80,19 @@ if [[ -n $need_desc ]]; then
     compadd "$@" -ld descs -a dcmds && ret=0
   _wanted commands expl 'external command' compadd "$@" -a cmds && ret=0
 else
-  _wanted commands expl 'external command' compadd "$@" -k commands && ret=0
+  if zstyle -t ":completion:${curcontext}:" path-tags; then
+    integer i
+    local -a path_commands
+    for (( i = 1; i <= ${#path}; i++ )); do
+      path_commands=(${${commands:#^$path[i]/*}:t})
+      if (( ${#path_commands} )); then
+	_wanted commands-$i-${path[i]} expl "external command [${path[i]}]" \
+	  compadd "$@" -k path_commands
+      fi
+    done
+  else
+    _wanted commands expl 'external command' compadd "$@" -k commands && ret=0
+  fi
 fi
 
 return $ret

-- 
Peter Stephenson <pws@xxxxxxx>            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
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog



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