zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: Re: sudo completion problem
@ 2000-05-08  9:00 Sven Wischnowsky
  2000-05-08  9:44 ` optional argument? Sven Wischnowsky
  2000-05-08 15:25 ` PATCH: Re: sudo completion problem Tanaka Akira
  0 siblings, 2 replies; 20+ messages in thread
From: Sven Wischnowsky @ 2000-05-08  9:00 UTC (permalink / raw)
  To: zsh-workers


Zefram wrote:

> ...
> 
> If we can determine that a particular command is processing options in
> this way, it would be nice to complet options accordingly.  However,
> by default options should only be completed before the first non-option
> argument.  In either case, options should never be completed after a "--".

I don't buy this. There *may* be commands or shell functions which
take `--' to, e.g.,  separate different sets of options and arguments.

_arguments is intended to be general enough to generate sensible
completions even for user-written shell functions, after all.

Please lets not make _arguments treat any string from the line special 
like this. Lets add it to:

> I envision _arguments first of all deciding whether the command allows
> options everywhere or not.  This should be under the control of the
> caller, via options to _arguments; possible values are "everywhere",
> "only before first argument", "autodetect GNU getopt" (if possible).

So wo would have these plus these combined with `and no options after --'.

Ok?

> _arguments must also check for a "--" argument, and not do option
> completion (regardless of option style) if the cursor is after the "--".
> All of this then lets it decide whether to complete options or not;
> non-option arguments are always a possibility, though we might want to
> be clever about handling arguments that start with "-".

No patch yet, but adding an option to comparguments (the builtin) for
the second (i.e. "only before first argument" the first would still be
the default, _arguments could use a different default, I don't care
that much about it for now) should be easy. And another option for the 
"no options after `--'" would be easy, too.

But before I start writing it: should the default for _arguments be
changed? And would someone be willing to check all uses of _arguments
and add the option to the calls that need them? Oh, and does anyone
have an idea how to test for GNU-getopts. Reliably?

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: PATCH: Re: sudo completion problem
@ 2000-05-04 13:40 Sven Wischnowsky
  2000-05-04 20:12 ` Tanaka Akira
  0 siblings, 1 reply; 20+ messages in thread
From: Sven Wischnowsky @ 2000-05-04 13:40 UTC (permalink / raw)
  To: zsh-workers


Tanaka Akira wrote:

> ...
> 
> My idea is already implemented: _regex_arguments.  Although currently
> there are only three completion functions - _apt, _xwit and _xset -
> which use _regex_arguments because it cannot use _arguments,  I think
> there are more completion  functions which can be written bit more
> simple if _regex_arguments is used.  Maybe, _xauth (and _cvs?).

Personally I find _arguments a whole lot more readable than
_regex_arguments. If that could be improved, I'd be glad.

Although I always wonder why people find _cvs difficult...

> ...
> 
> > And I'd like repeat once more - currently, when _arguments is using
> > lexical structure to describe semantic, it is hard to add something. If
> > we had flags ... (not suggesting breaking compatibility - but just for
> > future use).
> 
> _regex_arguments handle only parsing of arguments.  So other stuff
> handled by _arguments such as descriptions, exclusive options must be
> implemented by completion function writer.  It's bit hard task but we
> can implement special feature easily.

I would be *very* glad if _regex_arguments could at least handle the
tags, tag-labels and descriptions. I had lots of problems trying to
work those changes into the functions using _regex_arguments and since 
I don't know any of those commands I still don't know if I've got it
right.

Either in _regex_arguments or in a convenience wrapper function around 
it, of course.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: PATCH: Re: sudo completion problem
@ 2000-05-04  8:03 Sven Wischnowsky
  0 siblings, 0 replies; 20+ messages in thread
From: Sven Wischnowsky @ 2000-05-04  8:03 UTC (permalink / raw)
  To: zsh-workers


Zefram wrote:

> Andrej Borsenkow wrote:
> >I think, it was the result of change for find (do not have article
> >handy) - in ``find /tmp -user'' -user was not recognised as option
> >because /tmp already was argument. So, this change made options be found
> >everywhere, even after arguments :-)
> 
> That's the wrong way to do it.  In the find command line, `-user' is not
> an option, it's an expression (or part thereof).  The expression starts
> with the first argument that starts with `-' and continues to the end
> of the line; the directory arguments must appear before the expression.
> Actual options are handled as dummy predicates, which is confusing to
> the user, but from our point of view means that they must be treated as
> part of the expression.
> 
> find has a unique syntax, with no options having the usual option syntax.
> Therefore it shouldn't be handled by the standard option completion
> function; it needs a dedicated find-expression completion function.

I don't think we really need this. Especially since it works quite
well for most cases where one would want to complete. We could change
_find to complete normal arguments with a `->foo' action and there
decide if directories or only \!, \( and \) should be completed
(depending on there being an `opion' on the line or not). In that case 
it should do the right thing in every case even if the -* things
aren't really options.

> The standard option completion function should, as is standard syntax,
> process options only before the first non-option argument.

It's a simple `(-)' for the first argument and allows us to use
_arguments both for things like _find *and* for commands with options
after sub-commands (cvs, etc.) and with commands whose command lines
can consist of multiple option/argument pairs (like zrecompile or some 
such). This flexibility is certainly a big win, as I hope you'll agree.


Andrej Borsenkow wrote:

> ...
> 
> This may be useful in other cases as well. cvs comes in mind
> immediately - common options, then checkout, update, etc as argument -
> and possibly (sub-)options and (sub-)arguments for every of them.

Sub-commands (and their options and arguments!) as arguments to
every(!) common option?

What's wrong with the way _cvs works now?

> I understand, that this is hierarchical structure that probably cannot
> be handled with one single table ... but, just as idea, imagine that
> action for `update' argument simply points to subarguments description
> ... or something like this ... this may be more readable than shell
> functions. May be not. But it is easier in cases, where we need several
> versions for different plattforms.

For the different-platform problem: the easiest and most readable way
is still and will ever be: a `case ... in ... esac'. Either setting up 
an array of _arguments-specifications or calling _arguments directly.

> Then I realised, that reverse situation exists with options - there is
> no way to describe options without - prefix. Consider dd or tar ("tar"
> not "GNU tar" :-), BSD ps ... In case of dd we have only options; in
> case of tar ot ps, the first word consists of single letter options with
> possible arguments in next words in order. There is no way to describe
> both case with _arguments (unless I'm mistaken).

I *really* don't think we should make _arguments do this. I know
_arguments is handy in many cases but it should *not* be the only
function used if that requires to make it more complicated than
compctl ever was.

The main reason for inventing the new completion system was to get at
the flexibility of shell functions, after all. If we want to give help 
completing certain kinds of things we should write new utility
functions that can be combined with existing functions or we should
write wrappers around existing functions (like _argument_sets). But we 
shouldn't put everything into one basket.

> And I'd like repeat once more - currently, when _arguments is using
> lexical structure to describe semantic, it is hard to add something. If
> we had flags ... (not suggesting breaking compatibility - but just for
> future use).

I don't know what you are alluding to here. When did you complain
about it? And to make me believe that flags would help here I need 1)
a more complete description of how the flags work and 2) examples
where currently `it is hard to add something'.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 20+ messages in thread
* PATCH: Re: sudo completion problem
@ 2000-05-03 14:42 Sven Wischnowsky
  2000-05-03 14:56 ` Andrej Borsenkow
  2000-05-06  6:56 ` Andrej Borsenkow
  0 siblings, 2 replies; 20+ messages in thread
From: Sven Wischnowsky @ 2000-05-03 14:42 UTC (permalink / raw)
  To: zsh-workers


Andrej Borsenkow wrote:

> bor@itsrm2% sudo rm -r
> Completing Kerberos realm
> Completing `Kerberos realm'
> 
> Hmm ... it treats -r as sudo option ... but, I think, it did work once
> ...

If it did, then only before we used the separate description to get
only external command names or because there was some other bug.

Hm. From the logic of the specifications used by _sudo, this
completion is correct, after all, there may be options between
arguments unless otherwise specified.

So this adds the special string `-' for exclusion lists which makes
the description for the options not be used any more. And it makes
this be used in the places where we have such _command_names/_normal
combinations.


Bye
 Sven

Index: Completion/User/_fakeroot
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_fakeroot,v
retrieving revision 1.1
diff -u -r1.1 _fakeroot
--- Completion/User/_fakeroot	2000/04/08 21:06:48	1.1
+++ Completion/User/_fakeroot	2000/05/03 14:39:09
@@ -2,5 +2,6 @@
 
 _arguments \
        '--lib[alternate wrapper library]:wrapper library:_files' \
-       '--faked[alternate faked binary]:fake binary:_command_names' \
+       '--faked[alternate faked binary]:fake binary: _command_names -e' \
+       '(-):command name: _command_names -e'  \
        '*::arguments: _normal'
Index: Completion/User/_rlogin
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_rlogin,v
retrieving revision 1.3
diff -u -r1.3 _rlogin
--- Completion/User/_rlogin	2000/04/11 07:57:57	1.3
+++ Completion/User/_rlogin	2000/05/03 14:39:09
@@ -17,7 +17,7 @@
       '-n[ignore stdin]' \
       '-l[specify login user name]:login as:_rlogin_users' \
       ':remote host name:_rlogin_hosts' \
-      ':command: _command_names -e' \
+      '(-):command: _command_names -e' \
       '*::command:->command' && ret=0
 
     if [[ -n "$state" ]]; then
Index: Completion/User/_ssh
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_ssh,v
retrieving revision 1.2
diff -u -r1.2 _ssh
--- Completion/User/_ssh	2000/04/05 11:28:09	1.2
+++ Completion/User/_ssh	2000/05/03 14:39:09
@@ -18,7 +18,7 @@
   ssh|slogin)
     args=(
       ':remote host name:->userhost'
-      ':command: _command_names -e'
+      '(-):command: _command_names -e'
       '*::args:->command'
     )
     ;&
Index: Completion/User/_sudo
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_sudo,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 _sudo
--- Completion/User/_sudo	2000/03/09 11:43:52	1.1.1.3
+++ Completion/User/_sudo	2000/05/03 14:39:09
@@ -15,5 +15,5 @@
        '-s[run SHELL]' \
        '-H[set HOME environment variable]' \
        '-S[read password from stdin]' \
-       ':complete command name: _command_names -e'  \
+       '(-):command name: _command_names -e'  \
        '*::arguments: _normal'
Index: Completion/User/_xargs
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_xargs,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 _xargs
--- Completion/User/_xargs	1999/09/07 12:55:12	1.1.1.2
+++ Completion/User/_xargs	2000/05/03 14:39:09
@@ -9,5 +9,5 @@
   '(-n -l)-L:number of input lines:' \
   '(-l -L)-n:maximum number of arguments:' \
   '-s:maximum command line length:' \
-  ':command: _command_names -e' \
-  '*::args:_normal'
+  '(-):command: _command_names -e' \
+  '*::args: _normal'
Index: Completion/X/_xutils
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/X/_xutils,v
retrieving revision 1.4
diff -u -r1.4 _xutils
--- Completion/X/_xutils	2000/04/11 07:57:57	1.4
+++ Completion/X/_xutils	2000/05/03 14:39:09
@@ -107,7 +107,8 @@
     '-screen:screen number:' \
     '-user:remote user name:_users' \
     ':remote host:_hosts' \
-    '*:command::command:_normal'
+    '(-):command: _command_names -e' \
+    '*:command: _normal'
   ;;
 xsetroot)
   _x_arguments \
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.31
diff -u -r1.31 compsys.yo
--- Doc/Zsh/compsys.yo	2000/05/03 08:46:52	1.31
+++ Doc/Zsh/compsys.yo	2000/05/03 14:39:11
@@ -2925,9 +2925,10 @@
 the argument described by the specification will not be offered if the
 option tt(-foo) is on the line. Also, the list may contain a single
 star as one of its elements to specify that the description for the
-rest arguments should not be used and it may contain a colon to
+rest arguments should not be used, a colon to
 specify that the descriptions for all normal (non-option-) arguments
-should not be used.
+should not be used and a hyphen to specify that the descriptions for
+all options should not be used.
 
 In each of the cases above, the var(action) says how the possible
 completions should be generated. In cases where only one of a fixed
Index: Src/Zle/computil.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v
retrieving revision 1.11
diff -u -r1.11 computil.c
--- Src/Zle/computil.c	2000/05/02 08:56:28	1.11
+++ Src/Zle/computil.c	2000/05/03 14:39:12
@@ -1040,7 +1040,12 @@
 	    }
 	    if (x[0] == ':' && !x[1])
 		d->argsactive = 0;
-	    else if (x[0] == '*' && !x[1]) {
+	    else if (x[0] == '-' && !x[1]) {
+		Caopt p;
+
+		for (p = d->opts; p; p = p->next)
+		    p->active = 0;
+	    } else if (x[0] == '*' && !x[1]) {
 		if (d->rest)
 		    d->rest->active = 0;
 	    } else if (x[0] >= '0' && x[0] <= '9') {

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

end of thread, other threads:[~2000-05-08 18:13 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-08  9:00 PATCH: Re: sudo completion problem Sven Wischnowsky
2000-05-08  9:44 ` optional argument? Sven Wischnowsky
2000-05-08 10:01   ` Peter Stephenson
2000-05-08 14:49   ` Tanaka Akira
2000-05-08 17:58     ` Assorted _arguments arguments Bart Schaefer
2000-05-08 18:12       ` Peter Stephenson
2000-05-08 15:25 ` PATCH: Re: sudo completion problem Tanaka Akira
  -- strict thread matches above, loose matches on Subject: below --
2000-05-04 13:40 Sven Wischnowsky
2000-05-04 20:12 ` Tanaka Akira
2000-05-04 20:40   ` Tanaka Akira
2000-05-04  8:03 Sven Wischnowsky
2000-05-03 14:42 Sven Wischnowsky
2000-05-03 14:56 ` Andrej Borsenkow
2000-05-03 15:09   ` Zefram
2000-05-04  7:23     ` Andrej Borsenkow
2000-05-04 12:02       ` Tanaka Akira
2000-05-06  6:56 ` Andrej Borsenkow
2000-05-06  7:40   ` Tanaka Akira
2000-05-06  7:51     ` Andrej Borsenkow
2000-05-06  8:19   ` Zefram

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