bash (and I belive tcsh) have programmable completion that does exactly
what you are asking for.  Maybe a look into their source code helps.

see here for a description of the bash feature
http://www.gnu.org/manual/bash/html_mono/bashref.html#SEC110

Regards

    robert


"Zachary P. Landau" <kapheine / hypa.net> schrieb im Newsbeitrag
news:e81e52a8.0306121638.1c1eac15 / posting.google.com...
> Hello,
>
> I am running into a lot of trouble trying to find a good way to
> implement my interactive console program. Here is the idea. You are
> given a prompt (let's get creative and use "prompt> "). There are,
> lets say, two commands. "add" and "delete". When a user types "add",
> enters a space, and then hit tabs, the tab completion should return a
> list of files in the current directory. When the user types delete,
> space, and then tab, however, the user should get a list of
> directories that have already been selected with add.
>
> The problem with using the readline extension for this, as some as you
> may know, is it does not allow you to get any text before the last
> space (which is crucial, since that is where my command is). Someone
> did submit a patch to ruby-talk to fix  this problem, but it breaks
> backwards compatability (well, that and for some reason it wasn't
> working quite right for me :P)
>
> I was wondering if anyone had a good solution to this. I guess the
> least desirable option would be writing a new readline-like interface.
> If someone has a better idea, though, or has alreayd done this, please
> let me know. Thanks.