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

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



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-

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 '

-- 
Stephane



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