zsh-users
 help / color / mirror / code / Atom feed
* Completion on simple commande
@ 2010-08-12  9:11 Michel
  2010-08-12  9:56 ` Peter Stephenson
  2010-08-12  9:56 ` Frank Terbeck
  0 siblings, 2 replies; 4+ messages in thread
From: Michel @ 2010-08-12  9:11 UTC (permalink / raw)
  To: zsh-users

Hi,

I use an zsh function to launch the graphical application. But I don't
know how have the completion on my function.

My function is :
function start (){
    $@ > /dev/null 2> /dev/null &
}

And I want can type :
start fire<tab>

To launch firefox. In bash I know the "complete" commande but I don't
know the zsh metode.

Can you help me, please ?
_____________________
Michel BARRET


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

* Re: Completion on simple commande
  2010-08-12  9:11 Completion on simple commande Michel
@ 2010-08-12  9:56 ` Peter Stephenson
  2010-08-12 11:24   ` Michel
  2010-08-12  9:56 ` Frank Terbeck
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2010-08-12  9:56 UTC (permalink / raw)
  To: zsh-users

On Thu, 12 Aug 2010 11:11:11 +0200
Michel <michel.barret@gmail.com> wrote:
> I use an zsh function to launch the graphical application. But I don't
> know how have the completion on my function.
> 
> My function is :
> function start (){
>     $@ > /dev/null 2> /dev/null &
> }
> 
> And I want can type :
> start fire<tab>

"man zshcompsys" is the place to start, but working that way it'll take a
while before you get to the point where you can answer questions like this.

First you'll need to start the completion system; it's not clear if you've done
that.  If you haven't, put this in your ~/.zshrc:

autoload -Uz compinit
compinit

Then the simplest answer to the immediate question is to add the following
line:

compdef _precommand start

That makes "start" behave like other command words that take a complete
command line following.

By the way, you might want to put the $@ in double quotes:

function start (){
    "$@" > /dev/null 2> /dev/null &
}

The difference is that this won't remove any zero-length arguments to the
command, e.g. a '' on the command line.  That's not a typical problem with
the sort of use you have, however.

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


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


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

* Re: Completion on simple commande
  2010-08-12  9:11 Completion on simple commande Michel
  2010-08-12  9:56 ` Peter Stephenson
@ 2010-08-12  9:56 ` Frank Terbeck
  1 sibling, 0 replies; 4+ messages in thread
From: Frank Terbeck @ 2010-08-12  9:56 UTC (permalink / raw)
  To: Michel; +Cc: zsh-users

Michel wrote:
> I use an zsh function to launch the graphical application. But I don't
> know how have the completion on my function.
>
> My function is :
> function start (){
>     $@ > /dev/null 2> /dev/null &
> }

You probably want to use "$@" (double-quoted) here.

> And I want can type :
> start fire<tab>
>
> To launch firefox. In bash I know the "complete" commande but I don't
> know the zsh metode.

compdef _precommand start

That will make the command-specific version work, too.

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925


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

* Re: Completion on simple commande
  2010-08-12  9:56 ` Peter Stephenson
@ 2010-08-12 11:24   ` Michel
  0 siblings, 0 replies; 4+ messages in thread
From: Michel @ 2010-08-12 11:24 UTC (permalink / raw)
  To: zsh-users

2010/8/12 Peter Stephenson <Peter.Stephenson@csr.com>:
> On Thu, 12 Aug 2010 11:11:11 +0200
> Michel <michel.barret@gmail.com> wrote:
>> I use an zsh function to launch the graphical application. But I don't
>> know how have the completion on my function.
>>
>> My function is :
>> function start (){
>>     $@ > /dev/null 2> /dev/null &
>> }
>>
>> And I want can type :
>> start fire<tab>
>
> "man zshcompsys" is the place to start, but working that way it'll take a
> while before you get to the point where you can answer questions like this.
>
> First you'll need to start the completion system; it's not clear if you've done
> that.  If you haven't, put this in your ~/.zshrc:
>
> autoload -Uz compinit
> compinit

This configuration is already applied.

> Then the simplest answer to the immediate question is to add the following
> line:
>
> compdef _precommand start

Thanks it's exactly that !

> That makes "start" behave like other command words that take a complete
> command line following.
>
> By the way, you might want to put the $@ in double quotes:
>
> function start (){
>    "$@" > /dev/null 2> /dev/null &
> }
>
> The difference is that this won't remove any zero-length arguments to the
> command, e.g. a '' on the command line.  That's not a typical problem with
> the sort of use you have, however.

Ok I make this modification thanks you and Frank Terbeck.


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

end of thread, other threads:[~2010-08-12 11:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-12  9:11 Completion on simple commande Michel
2010-08-12  9:56 ` Peter Stephenson
2010-08-12 11:24   ` Michel
2010-08-12  9:56 ` Frank Terbeck

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