zsh-users
 help / color / mirror / code / Atom feed
* need help to convert final compctl!
@ 2001-03-22 19:05 John Cooper
  2001-03-22 20:59 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: John Cooper @ 2001-03-22 19:05 UTC (permalink / raw)
  To: zsh-users


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


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

* Re: need help to convert final compctl!
  2001-03-22 19:05 need help to convert final compctl! John Cooper
@ 2001-03-22 20:59 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2001-03-22 20:59 UTC (permalink / raw)
  To: John Cooper, zsh-users

On Mar 22,  7:05pm, John Cooper wrote:
} Subject: 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.
} 
} I wondered how I can achieve the same thing with the new system?

As far as I can tell, like this:

    _g() { compadd -U ${(M)dirs:#*$PREFIX$SUFFIX*} }
    compdef _g g

Or put in a file named _g somewhere in $fpath:

    #compdef g
    compadd -U ${(M)dirs:#*$PREFIX$SUFFIX*}

but it hardly seems worth a separate file.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

end of thread, other threads:[~2001-03-22 21:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-22 19:05 need help to convert final compctl! John Cooper
2001-03-22 20:59 ` Bart Schaefer

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