zsh-users
 help / color / mirror / code / Atom feed
* dump completion question
@ 2007-09-18 10:06 Andy Spiegl
  2007-09-18 14:46 ` dumb " Andy Spiegl
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Spiegl @ 2007-09-18 10:06 UTC (permalink / raw)
  To: zsh-users

Hi, I am trying do expand the completion function for cssh
so that it shows the defined clusters but I am too stupid. :-)

I read in the defined clusters like this:
 definedclusters=$(grep ^clusters ~/.csshrc | cut -d= -f2- 2>/dev/null)

But how do I make use of this variable now?

What I want is:
 % echo $definedclusters
 abc def ghi
 % cssh <TAB>
 - defined clusters -
 abc def ghi

 
Thanks,
 Andy.

-- 
 Do files get embarrassed when they get unzipped?


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

* Re: dumb completion question
  2007-09-18 10:06 dump completion question Andy Spiegl
@ 2007-09-18 14:46 ` Andy Spiegl
  2007-09-18 15:00   ` Peter Stephenson
  2007-09-18 15:14   ` Bart Schaefer
  0 siblings, 2 replies; 7+ messages in thread
From: Andy Spiegl @ 2007-09-18 14:46 UTC (permalink / raw)
  To: zsh-users

I tried a little more, dug further into the completion docs and
found a solution:

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
# compdef cssh crsh

local definedclusters
definedclusters=(all www fire db mail web rest)

_arguments \
  '-h[help]' \
...
  '*:cssh clusters:($definedclusters)'
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-

So far so good, but if I read in the variable dynamically
(which is what I want of course :-), like this:
 definedclusters="($(grep ^clusters $HOME/.csshrc | cut -d= -f2- 2>/dev/null))"

then I get _very_ strange results: after pressing TAB I don't see the contents
of the variable definedclusters but stuff from my .Xdefaults and .zsh.history!

Anyone can explain this strange behavior to me please?

Thanks,
 Andy.

-- 
 cogito ergo sum, bibo ergo sum, cogito ergo bib, bibo ergo bib?


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

* Re: dumb completion question
  2007-09-18 14:46 ` dumb " Andy Spiegl
@ 2007-09-18 15:00   ` Peter Stephenson
  2007-09-18 15:15     ` Andy Spiegl
  2007-09-18 15:14   ` Bart Schaefer
  1 sibling, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 2007-09-18 15:00 UTC (permalink / raw)
  To: zsh-users

Andy Spiegl wrote:
> # compdef cssh crsh
> 
> local definedclusters
> definedclusters=(all www fire db mail web rest)
> 
> _arguments \
>   '-h[help]' \
> ...
>   '*:cssh clusters:($definedclusters)'
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 
> So far so good, but if I read in the variable dynamically
> (which is what I want of course :-), like this:
>  definedclusters="($(grep ^clusters $HOME/.csshrc | cut -d= -f2- 2>/dev/null)
> )"
> 
> then I get _very_ strange results: after pressing TAB I don't see the content
> s
> of the variable definedclusters but stuff from my .Xdefaults and .zsh.history
> !

If you have extendedglob set, you need to qutoe '^clusters' or it will
expand to all files apart from one called clusters, so you will be
grepping all those files plus ~/.csshrc for the first file in the
directory.

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


.


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

* Re: dumb completion question
  2007-09-18 14:46 ` dumb " Andy Spiegl
  2007-09-18 15:00   ` Peter Stephenson
@ 2007-09-18 15:14   ` Bart Schaefer
  1 sibling, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2007-09-18 15:14 UTC (permalink / raw)
  To: Andy Spiegl, zsh-users

On Sep 18,  4:46pm, Andy Spiegl wrote:
}
} Anyone can explain this strange behavior to me please?

Use _complete_debug.

Instead of pressing TAB, press control-x question-mark.

You'll get rather a lot of output, stored in a temp file so you can
open it with your editor.  Search for definedclusters and look at the
commands that are executing around it.


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

* Re: dumb completion question
  2007-09-18 15:00   ` Peter Stephenson
@ 2007-09-18 15:15     ` Andy Spiegl
  2007-09-18 17:00       ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Spiegl @ 2007-09-18 15:15 UTC (permalink / raw)
  To: zsh-users

> If you have extendedglob set, you need to qutoe '^clusters' or it will
> expand to all files apart from one called clusters

aaaargh!

I didn't have it set but "setopt no_extendedglob" did help.

However, it still doesn't work correctly.

 % cssh <TAB>
 % cssh \(\ all\ www\ fire\ db\ mail\ web\ rest\)

I guess I have to split the output of
 grep '^clusters' $HOME/.csshrc | cut -d= -f2-
somehow, right?  Hm, isn't there even a more zsh-is way to read in
this specific line of ~/.csshrc?

Thanks again,
 Andy.

-- 
 A supercomputer is a machine, that runs an endless loop in just 2 seconds


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

* Re: dumb completion question
  2007-09-18 15:15     ` Andy Spiegl
@ 2007-09-18 17:00       ` Peter Stephenson
  2007-09-18 19:56         ` Andy Spiegl
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 2007-09-18 17:00 UTC (permalink / raw)
  To: zsh-users

Andy Spiegl wrote:
> > If you have extendedglob set, you need to qutoe '^clusters' or it will
> > expand to all files apart from one called clusters
> 
> aaaargh!
> 
> I didn't have it set but "setopt no_extendedglob" did help.

It's on by default in completion functions.  I would get used to having
it on and quote accordingly.  If you must turn it off, use
"setopt localoptions" or "emulate -L zsh" to prevent the change escaping
from the function.

> However, it still doesn't work correctly.
> 
>  % cssh <TAB>
>  % cssh \(\ all\ www\ fire\ db\ mail\ web\ rest\)

Now I look, the problem is another quoting problem:

 definedclusters="($(grep ^clusters $HOME/.csshrc | cut -d= -f2- 2>/dev/null))"

You're assigning the string starting "(" and ending ")", not an array.
In full, you want

 definedclusters=($(grep '^clusters' $HOME/.csshrc | cut -d= -f2- 2>/dev/null))

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


.


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

* Re: dumb completion question
  2007-09-18 17:00       ` Peter Stephenson
@ 2007-09-18 19:56         ` Andy Spiegl
  0 siblings, 0 replies; 7+ messages in thread
From: Andy Spiegl @ 2007-09-18 19:56 UTC (permalink / raw)
  To: zsh-users

> Now I look, the problem is another quoting problem:

Doooh!  Thanks a lot for finding this!

For the records, here is my new _cssh:
(may it'll make it into the CVS?)

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
#compdef cssh crsh

local definedclusters

definedclusters=($(grep '^clusters' $HOME/.csshrc | cut -d= -f2- 2>/dev/null))

_arguments \
  '-h[help]' \
  '-H[show man page]' \
  '-v[show version]' \
  '-d[enable basic debugging mode]' \
  '-D[enable extended debugging mode]' \
  '-q[enable automatic quit after last window is closed]' \
  '-Q[disable automatic quit after last window is closed]' \
  '-u[output configuration]' \
  '-g[enable window tiling]' \
  '-G[disable window tiling]' \
  '-c[use additional cluster file]:cluster file:_files' \
  '-l:username:_users' \
  '-T:window title prefix:' \
  '-o:arguments to ssh or rsh:' \
  '-t:arguments to terminals:' \
  '-i[ignore errors from unresolvable hostnames]' \
  '-e[evaluate arguments to identify potential errors]:userhostport:_user_at_host' \
  '*:cssh clusters:($definedclusters)'

# original, completing just user@host:
#  '*:userhostport: _alternative hosts:host:_hosts usersathosts:userathost:_user_at_host'
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.

Bye,
 Andy.

-- 
 The typewriting machine, when played with expression, is no more
 annoying than the piano when played by a sister or near relation.
                 -- Oscar Wilde


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

end of thread, other threads:[~2007-09-18 19:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-18 10:06 dump completion question Andy Spiegl
2007-09-18 14:46 ` dumb " Andy Spiegl
2007-09-18 15:00   ` Peter Stephenson
2007-09-18 15:15     ` Andy Spiegl
2007-09-18 17:00       ` Peter Stephenson
2007-09-18 19:56         ` Andy Spiegl
2007-09-18 15:14   ` 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).