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

Re: alias of completion




On 02.03.2018 10:31, Pier Paolo Grassi wrote:
> Hello guys, I just joined the list but I have been a zsh enthusiast for 15
> years and since I discovered it it's always been the best work enviroment I
> ever had.
> One thing I was never been able to accomplish though, is: what if I want a
> custom function, say:
> 
> mydockerwrapper(){}
> 
> behave, for completion's sake, like, let's say:
> 
> docker ls
> 
> so that if I try to complete after
> 
> mydockerwrapper <TAB>
> 
> I get the same suggestion that I would get after docker ls, and if I have
> 
> mydockerwrapper xx <TAB>
> 
> I get the same completion that I would get after  docker ls xx, and so on.
> 
> -what I tried-
> 
> I know that the completion function for the docker command is _docker, and
> that I could associate my function to this completion function with
> 
> compdef _docker mydockerwrapper
> 
> but it doesn't seem possibile to pass one default argument to the
> completion function in this way.
> 
> So I tried defining my own completion function, and add one argument and
> pass it to the _docker function, but I got stuck on this one.
> 
> I'm sure this must be very easy to do in zsh, I just can't figure out how..
> maybe someone can help me out?
> 
> thanks, happy coding everyone!
> 
> 

You could modify CURRENT and words in a custom completion function and
then just call _normal ("docker ls" is one word more than
"mydockerwrapper"):

_mydockerwrapper() {
  ((CURRENT++))
  words=(docker ls "${words[@]:1}")
  _normal
}
compdef _mydockerwrapper mydockerwrapper



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