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

Re: Filename expansion within a completion widget



On Wed, 3 Nov 2004, DervishD wrote:

> >     compset -P '*/'
> > 
> >     Well, it handles both relative and absolute directories
> > correctly, but doesn't handle named directories :(( I don't
> > understand why because if I type 'cd ~X<TAB>' the named dir should be
> > expanded, shouldn't it?

"Expanded" would mean that ~X was replaced by the path it represents.  
Yet later you say this isn't the behavior you want.  If the variable is 
really $X11, for example, then converting ~X to ~X11 is not "expanding", 
it's "completing", at least in zsh's terminology (e.g., for purposes of 
the widget "expand-or-complete").

And if you've written your own completion widget, you have to do the
completing yourself, right?

>     Of course, adding something like 'PREFIX=$~PREFIX' just before
> the compset call solves the problem, but then the named dir is
> 'translated', which I don't want

Just because you're not using zsh's completion system functions doesn't 
mean you can't look at them for hints.  Completion/Unix/Type/_tilde_files 
would be a good place to start; note in particular the case statement on
$PREFIX.

> There is surely another way of doing this...

The short answer is that if there is not a slash in the string yet, you 
remove the tilde from consideration with compset -P, and then you compadd 
the userdirs and/or nameddirs arrays from the zsh/parameter module.  If 
there is a slash in the string, you have to manipulate IPREFIX and then 
use compadd -W.



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