zsh-workers
 help / color / mirror / code / Atom feed
* Completion alias
@ 2007-03-22 22:51 ` Jörg Sommer
  2007-03-23  0:01   ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Jörg Sommer @ 2007-03-22 22:51 UTC (permalink / raw)
  To: zsh-workers

Hi,

is it possible to tell the completion system, that two commands are the
same? mutt and mutt-ng take the same arguments, but the completion for
mutt-ng arguments is not enabled. I also want to write something like
this:

agi()
{
    nice -n 4 agt-get install $@
    ret=$?
    do_something_else
    return $ret
}

and the argument completion for agi should be the same as for apt-get
install. Currently I use alias agi='nice -n 4 apt-get install', but I
don't know, how to append the do_something_else command.

Bye, Jörg.
-- 
Life can only be understood backwards, but it must be lived forwards.
                                             (Soren Kierkegaard)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Completion alias
  2007-03-22 22:51 ` Completion alias Jörg Sommer
@ 2007-03-23  0:01   ` Peter Stephenson
  2007-03-23 10:44     ` Jörg Sommer
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 2007-03-23  0:01 UTC (permalink / raw)
  To: zsh-workers

=?UTF-8?Q?J=C3=B6rg?= Sommer wrote:
> is it possible to tell the completion system, that two commands are the
> same? mutt and mutt-ng take the same arguments, but the completion for
> mutt-ng arguments is not enabled.

compdef mutt-ng=mutt

This is documented a bit obscurely (in the description of compdef in
zshcompsys.1):

     Alternatively, all the arguments may have the form `CMD=SERVICE'.
     Here SERVICE should already have been defined by `CMD1=SERVICE'
     lines in #compdef files, as described above.  The argument for CMD
     will be completed in the same way as SERVICE.

Actually, it doesn't matter how the "service" was defined, it just has
to be registered as a completion, so the "CMD1=SERVICE" is a bit
of a red herring, unless I'm missing something.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Completion alias
  2007-03-23  0:01   ` Peter Stephenson
@ 2007-03-23 10:44     ` Jörg Sommer
  2007-03-23 12:29       ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Jörg Sommer @ 2007-03-23 10:44 UTC (permalink / raw)
  To: zsh-workers

Hallo Peter,

Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> =?UTF-8?Q?J=C3=B6rg?= Sommer wrote:
>> is it possible to tell the completion system, that two commands are the
>> same? mutt and mutt-ng take the same arguments, but the completion for
>> mutt-ng arguments is not enabled.
>
> compdef mutt-ng=mutt

Cool. This is what I've thought of.

> Actually, it doesn't matter how the "service" was defined, it just has
> to be registered as a completion, so the "CMD1=SERVICE" is a bit
> of a red herring, unless I'm missing something.

But how can I use this for a completion of a command with an argument,
i.e. agi should have the same completion as 'agt-get install'

Bye, Jörg.
-- 
Die meisten Menschen wollen lieber durch Lob ruiniert
als durch Kritik gerettet werden.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Completion alias
  2007-03-23 10:44     ` Jörg Sommer
@ 2007-03-23 12:29       ` Peter Stephenson
  2007-03-23 15:54         ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 2007-03-23 12:29 UTC (permalink / raw)
  To: zsh-workers

=?UTF-8?Q?J=C3=B6rg?= Sommer wrote:
> But how can I use this for a completion of a command with an argument,
> i.e. agi should have the same completion as 'agt-get install'

That would require some rewriting of _apt.  It's easy to specify
that a function should behave like apt-get:

compdef agi=apt-get

but without support in _apt there's no way of telling it to behave
as if the "install" argument is present.

I came up with a way of doing this for the Perforce completion:

  compdef _perforce p4cvsmap=p4-files

says that "p4cvsmap ..." behaves like "p4 files ...".  However, it's
not trivial to bolt this method onto an existing completion unless
it already has separate despatchers for subcommands.  Furthermore,
_apt uses the regex handling which makes it even more difficult.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Completion alias
  2007-03-23 12:29       ` Peter Stephenson
@ 2007-03-23 15:54         ` Bart Schaefer
  2007-03-30 11:14           ` Jörg Sommer
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2007-03-23 15:54 UTC (permalink / raw)
  To: zsh-workers

On Mar 23, 12:29pm, Peter Stephenson wrote:
} Subject: Re: Completion alias
}
} =?UTF-8?Q?J=C3=B6rg?= Sommer wrote:
} > But how can I use this for a completion of a command with an argument,
} > i.e. agi should have the same completion as 'agt-get install'
} 
} That would require some rewriting of _apt.

In this specific instance, if "agi" really is just shorthand for the
entirely equivalent "apt-get install", then:

    alias agi='apt-get install'
    unsetopt complete_aliases

I think it should also work to do

    _agi () {
	shift words
	service=apt-get
	words=(apt-get install $words) 
	((CURRENT++))                    
	_apt
    }
    compdef _agi agi

However, there may be something else that needs to be twaddled as well
as service= and words= to guarantee that this works properly.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Completion alias
  2007-03-23 15:54         ` Bart Schaefer
@ 2007-03-30 11:14           ` Jörg Sommer
  2007-03-30 16:03             ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Jörg Sommer @ 2007-03-30 11:14 UTC (permalink / raw)
  To: zsh-workers

Hello Bart,

Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Mar 23, 12:29pm, Peter Stephenson wrote:
> } Subject: Re: Completion alias
> }
> } =?UTF-8?Q?J=C3=B6rg?= Sommer wrote:
> } > But how can I use this for a completion of a command with an argument,
> } > i.e. agi should have the same completion as 'agt-get install'
> } 
> } That would require some rewriting of _apt.
>
> I think it should also work to do
>
>     _agi () {
> 	shift words
> 	service=apt-get
> 	words=(apt-get install $words) 
> 	((CURRENT++))                    
> 	_apt

Why you don't call _apt-get directly?

>     }
>     compdef _agi agi
>
> However, there may be something else that needs to be twaddled as well
> as service= and words= to guarantee that this works properly.

Yes, you are right. The completion of long and short options (--help
and -h) doesn't work. But it works for the packages and this is a big
help for the first time.

Bye, Jörg.
-- 
Es ist außerdem ein weit verbreiteter Irrtum das USENET ‚helfen‘ soll.
Tatsächlich wurde USENET nachweislich zur persönlichen Belustigung
seiner Erfinder geschaffen.
Jörg Klemenz <joerg@gmx.net>, <b4ai4o$1u8vmt$2@ID-21915.news.dfncis.de>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Completion alias
  2007-03-30 11:14           ` Jörg Sommer
@ 2007-03-30 16:03             ` Bart Schaefer
  0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2007-03-30 16:03 UTC (permalink / raw)
  To: zsh-workers

On Mar 30, 11:14am, Joerg Somer wrote:
} Subject: Re: Completion alias
}
} Why you don't call _apt-get directly?

It's not autoloaded.  It only gets defined the first time _apt is called.

} > However, there may be something else that needs to be twaddled as well
} > as service= and words= to guarantee that this works properly.
} 
} Yes, you are right. The completion of long and short options (--help
} and -h) doesn't work.

I'm no further help there, I'm afraid -- I don't use apt or Debian, so
once completion reaches the point of calling the programs to ask what the
options are, everything breaks for me.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-03-30 16:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <joerg@alea.gnuu.de>
2007-03-22 22:51 ` Completion alias Jörg Sommer
2007-03-23  0:01   ` Peter Stephenson
2007-03-23 10:44     ` Jörg Sommer
2007-03-23 12:29       ` Peter Stephenson
2007-03-23 15:54         ` Bart Schaefer
2007-03-30 11:14           ` Jörg Sommer
2007-03-30 16:03             ` Bart Schaefer

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).