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

need help to convert final compctl!



With the old compctl system, I used the functions below to be able to complete
*arbitrary substrings* from a list of commonly used directories.  For example,
typing the following:

$ `g pd<TAB>' 

.. would yield:

$ g module/pd
module/pd       module/pd/encrypt module/pd/rframe

from which I could complete further or accept the choice with RET.

(the `g' command doesn't _require_ completion; typing `g clip' automatically
tries to find a matching directory from the dirs list (and in this case will
change directory to $JICA/module/vd/clipboard)).


I've now switched to the new completion system and this is my only remaining
compctl, so I wondered how I can achieve the same thing with the new system?

Thanks,

    --- John

dirs=(
     ui/applet ui/application module/vd/printer module/td/tcp browse module
     module/pd module/pd/encrypt module/pd/rframe module/td module/td/SOCKS
     module/vd module/vd/ProgramNeighborhood module/vd/audio module/vd/ccm
     module/vd/clipboard module/vd/printer/LprStream module/vd/printer/lpr
     module/vd/thinwire module/wd module/wd/ica30 pn pn/UI pn/UI/AWT widgets
     pn/UI/AWT/customwidgets pn/help ui ui/application/cui ui/application/cutil
     ui/application/gjt ui/application/help ui/test capability
     )

# function for matching above directories from an arbitrary substring.
g () {
  destination=$dirs[(r)*$1*]
  cd $JICA/client/$destination
  ls
}

# Completion function for the above
function dirCompleter () {
  typeset -i count=1

  elt=$dirs[(n:count:r)*$1$2*]
  reply=($elt)

  until [ "$elt" = "" ]
  do
    count=$count+1
    elt=$dirs[(n:count:r)*$1$2*]
    reply=($reply $elt)
  done
}

compctl -U -K dirCompleter g



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