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

Re: Ordering of alternatives for menu completion



On Wed, 7 Mar 2012 14:24:43 +0100
Jesper Nygårds <jesper.nygards@xxxxxxxxx> wrote:
> _up() {
>   local myarray myindex revarray
>   myarray=( ${(s:/:)PWD} )
>   revarray=()
>   for myindex in {2..$(( $#myarray - 1 ))}; do
>       revarray=( $myarray[$myindex] $revarray[@] )
>   done
>   compadd - $revarray
> }
> This works fine, but when I use the completion like this: "up <tab>",
> the alternatives are cycled in alphabetical order. I want them to be
> suggested in the order of $revarray, i.e. with the closest parent
> first and the progressively higher up in the hierarchy, but some
> mechanism sorts the alternatives alphabetically.

You need to tell compadd by passing -V plus the name of a group of
matches.  I think

  compadd -V unsorted - $revarray

ought to be good enough.  While I'm at it,

  compadd -V unsorted -a revarray

is a little more efficient if the array is big.

(It's not too hard to make this use the usual tags mechanism to mix with
other completions but it doesn't sound like you actually need that.)

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