* alias of completion
@ 2018-03-02 9:31 ` Pier Paolo Grassi
2018-03-02 10:51 ` Peter Stephenson
2018-03-02 12:08 ` m0viefreak
0 siblings, 2 replies; 7+ messages in thread
From: Pier Paolo Grassi @ 2018-03-02 9:31 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 1321 bytes --]
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!
--
Pier Paolo Grassi
email: pierpaolog@gmail.com
linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217
fondatore: https://www.meetup.com/it-IT/Machine-Learning-TO
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: alias of completion
2018-03-02 9:31 ` alias of completion Pier Paolo Grassi
@ 2018-03-02 10:51 ` Peter Stephenson
2018-03-02 12:00 ` Pier Paolo Grassi
2018-03-02 12:08 ` m0viefreak
1 sibling, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 2018-03-02 10:51 UTC (permalink / raw)
To: Pier Paolo Grassi, zsh-users
From: Peter Stephenson <p.stephenson@samsung.com>
To: Pier Paolo Grassi <pierpaolog@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: alias of completion
Date: Fri, 2 Mar 2018 10:47:34 +0000
X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu)
Organization: SCSC
On Fri, 2 Mar 2018 10:31:57 +0100
Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
> 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.
You need a bit of help from the completion function in
question to do this. The feature in question is "services": I just
looked at the docker completion and it does support this.
You'll need to do something like
compdef _docker mydockerwrapper=docker_service_complete_ls_filters
where the thing on the right of the "=" is an appropriate docker
completion function without the "_" (search for _$service for the code
in _docker supporting this).
pws
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: alias of completion
2018-03-02 10:51 ` Peter Stephenson
@ 2018-03-02 12:00 ` Pier Paolo Grassi
0 siblings, 0 replies; 7+ messages in thread
From: Pier Paolo Grassi @ 2018-03-02 12:00 UTC (permalink / raw)
To: Peter Stephenson; +Cc: zsh-users
[-- Attachment #1: Type: text/plain, Size: 2855 bytes --]
Hello Peter, thank you for your suggestion. Following it I was able to
write:
compdef _docker xy=_docker_image_commands
that kind of work for the first word, the problem is that the second word
is not completed correctly since it tries again to use _docker_image_commands
instead of whaterver it should have called.
The only functions defined inside the file that
/usr/share/zsh/vendor-completions/_docker match the word image are:
__docker_complete_images
__docker_complete_images_filters
__docker_image_commands
__docker_image_subcommand
so there isn't a more general completion function like _docker_image that
takes care of the completion for docker image [xx [yy]...], but there are
various functions called from __docker_subcommand inspecting the
array $words. What I would need, I think, is the ability to populate from
another completion function this array adding as first argument the value
"image", so that:
compadd _docker mydockerwrapper=docker
would make __docker_subcommand behave as if the command line contained
not only "docker" but "docker image", something like:
compadd _docker mydockerwrapper="docker image"
that is obviously wrong because "docker image" it is not a correct service
name, I wrote it just to illustrate my point
2018-03-02 11:51 GMT+01:00 Peter Stephenson <p.stephenson@samsung.com>:
> From: Peter Stephenson <p.stephenson@samsung.com>
> To: Pier Paolo Grassi <pierpaolog@gmail.com>
> Cc: zsh-users@zsh.org
> Subject: Re: alias of completion
> Date: Fri, 2 Mar 2018 10:47:34 +0000
> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu)
> Organization: SCSC
>
> On Fri, 2 Mar 2018 10:31:57 +0100
> Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
> > 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.
>
> You need a bit of help from the completion function in
> question to do this. The feature in question is "services": I just
> looked at the docker completion and it does support this.
>
> You'll need to do something like
>
> compdef _docker mydockerwrapper=docker_service_complete_ls_filters
>
> where the thing on the right of the "=" is an appropriate docker
> completion function without the "_" (search for _$service for the code
> in _docker supporting this).
>
> pws
>
--
Pier Paolo Grassi
email: pierpaolog@gmail.com
linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217
fondatore: https://www.meetup.com/it-IT/Machine-Learning-TO
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: alias of completion
2018-03-02 9:31 ` alias of completion Pier Paolo Grassi
2018-03-02 10:51 ` Peter Stephenson
@ 2018-03-02 12:08 ` m0viefreak
2018-03-02 12:15 ` Pier Paolo Grassi
2018-03-02 22:23 ` Joey Pabalinas
1 sibling, 2 replies; 7+ messages in thread
From: m0viefreak @ 2018-03-02 12:08 UTC (permalink / raw)
To: zsh-users; +Cc: Pier Paolo Grassi
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: alias of completion
2018-03-02 12:08 ` m0viefreak
@ 2018-03-02 12:15 ` Pier Paolo Grassi
2018-03-02 22:23 ` Joey Pabalinas
1 sibling, 0 replies; 7+ messages in thread
From: Pier Paolo Grassi @ 2018-03-02 12:15 UTC (permalink / raw)
To: m0viefreak; +Cc: zsh-users
[-- Attachment #1: Type: text/plain, Size: 2014 bytes --]
YES that does it! thank you! I knew it must have to be very simple, I just
was missing some information..
2018-03-02 13:08 GMT+01:00 m0viefreak <m0viefreak.cm@googlemail.com>:
>
>
> 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
>
>
--
Pier Paolo Grassi
email: pierpaolog@gmail.com
linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217
fondatore: https://www.meetup.com/it-IT/Machine-Learning-TO
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: alias of completion
2018-03-02 12:08 ` m0viefreak
2018-03-02 12:15 ` Pier Paolo Grassi
@ 2018-03-02 22:23 ` Joey Pabalinas
2018-03-03 6:41 ` Pier Paolo Grassi
1 sibling, 1 reply; 7+ messages in thread
From: Joey Pabalinas @ 2018-03-02 22:23 UTC (permalink / raw)
To: m0viefreak; +Cc: zsh-users, Pier Paolo Grassi
[-- Attachment #1: Type: text/plain, Size: 930 bytes --]
On Fri, Mar 02, 2018 at 01:08:09PM +0100, m0viefreak wrote:
> 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
Holy hell, you don't know how long I've been trying to figure out
exactly that (but with systemctl instead of docker). At one point
I even to screw up so badly that when I did `scrs <TAB>` my computer
simply rebooted itself. Dumbfounded, I immediately tested it again
as soon as my OS booted to make sure I wasn't going crazy and (as you
probably saw coming from a mile away) promptly rebooted my computer
with another fateful <Tab>.
But this works *perfectly*.
I didn't ask the original question, but nonetheless thank you!
--
Joey Pabalinas
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: alias of completion
2018-03-02 22:23 ` Joey Pabalinas
@ 2018-03-03 6:41 ` Pier Paolo Grassi
0 siblings, 0 replies; 7+ messages in thread
From: Pier Paolo Grassi @ 2018-03-03 6:41 UTC (permalink / raw)
To: Joey Pabalinas; +Cc: m0viefreak, zsh-users
[-- Attachment #1: Type: text/plain, Size: 1226 bytes --]
Joey that’s hilarious... I can’t even imagine what kind of tests you did,
but some voodoo must have been involved... XD
Il giorno ven 2 mar 2018 alle 23:23 Joey Pabalinas <joeypabalinas@gmail.com>
ha scritto:
> On Fri, Mar 02, 2018 at 01:08:09PM +0100, m0viefreak wrote:
> > 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
>
> Holy hell, you don't know how long I've been trying to figure out
> exactly that (but with systemctl instead of docker). At one point
> I even to screw up so badly that when I did `scrs <TAB>` my computer
> simply rebooted itself. Dumbfounded, I immediately tested it again
> as soon as my OS booted to make sure I wasn't going crazy and (as you
> probably saw coming from a mile away) promptly rebooted my computer
> with another fateful <Tab>.
>
> But this works *perfectly*.
>
> I didn't ask the original question, but nonetheless thank you!
>
> --
> Joey Pabalinas
>
--
Pier Paolo Grassi
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-03-03 6:41 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20180302093415epcas3p3d273c63fafad455cca7fec4072aeaea1@epcas3p3.samsung.com>
2018-03-02 9:31 ` alias of completion Pier Paolo Grassi
2018-03-02 10:51 ` Peter Stephenson
2018-03-02 12:00 ` Pier Paolo Grassi
2018-03-02 12:08 ` m0viefreak
2018-03-02 12:15 ` Pier Paolo Grassi
2018-03-02 22:23 ` Joey Pabalinas
2018-03-03 6:41 ` Pier Paolo Grassi
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).