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

Re: Using another command's completion function with an alias



On Thu, 12 Nov 2009, Stephane Chazelas wrote:

> 2009-11-12 14:00:56 -0500, Benjamin R. Haskell:
> [...]
> > alias noagent='env -u SSH_AGENT_PID -u SSH_AUTH_SOCK'
> > 
> > But, compdef noagent=-command-  doesn't have the desired effect.  I 
> > instead get the completion for 'env':
> > 
> > $ noagent <C-x><h>
> > tags in context :completion::complete:-u::
> >     all-files  (_files _default (eval))
> > tags in context :completion::complete:env::
> >     argument-rest  (_arguments _env (eval))
> > 
> > Obviously my completion-fu is still in its infancy.  Is there something 
> > simple to fix the 'alias' version?
> [...]
> 
> I don't have the answer to that exact question, but I think that
> if you used a function instead of an alias, your compdef trick
> would work. Like:
> 
> noagent() env -u SSH_AGENT_PID -u SSH_AUTH_SOCK "$@"
> compdef noagent=-command-

Hmm.  Interesting.  Thanks.


> BTW:
> 
> Manual> 6.7 Aliasing
> Manual> ============
> Manual>
> Manual> Every token in the shell input is checked to see if there
> Manual> is an alias defined for it.  If so, it is replaced by the
> Manual> text of the alias if it is in command position (if it
> Manual> could be the first word of a simple command), or if the
> Manual> alias is global.  If the text ends with a space, the next
>                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Manual> word in the shell input is treated as though it were in
>         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Manual> command position for purposes of alias expansion.
>         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> So you may prefer:
> 
> alias noagent='env -u SSH_AGENT_PID -u SSH_AUTH_SOCK '

Also interesting.  On first read, I too thought this might help.  But, the 
problem is 'for purposes of alias expansion'.

I.e. that section allows:

$ alias A='echo foo' 
$ alias B='echo foo '
$ A A
foo A
$ B B
foo echo foo

Best,
Ben



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