zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: completions for su and implicit fg/bg
@ 1999-07-19 13:58 Sven Wischnowsky
  1999-07-19 13:38 ` Peter Stephenson
  0 siblings, 1 reply; 16+ messages in thread
From: Sven Wischnowsky @ 1999-07-19 13:58 UTC (permalink / raw)
  To: zsh-workers


I wrote:

> I wrote:
> 
> > This allows `compset -q' on unquoted words -- almost. There is a
> > problem when the match contains characters that have to be quoted. In
> > such cases the match should be quoted twice (`a b' should be inserted
> > as `a\\\ b'), but currently the completion code is far from being
> > prepared for such double-quoting and I'm seeing to much places where
> > changes are needed for a quick patch.
> 
> I've been thinking some more about this... This can get pretty ugly
> when we have multiple calls to `compset -q' for the same word. In such 
> cases we would have to keep track of the number of calls (the nesting
> level) and then quote the words put into the command line n times. Of
> course the results may become almost unreadable and it would require
> changes in several parts of the code.

I've now spent several days trying to get this right -- and am now
really fed up. My last solution almost worked but still had problems
with, e.g. zsh -c 'zsh -c "zsh -c echo\ <TAB>. Mainly due to the
somewhat weird backslash-in-quotes behavior. Also, I only had this for 
inserting unambiguous matches (do_single()), and the stuff for
unambiguous prefixes is even harder.

So, I *will* some day try to fix this, but I don't think I'll be able
to do this this week and next week I'll be away.

I'll have to find a completely different way for this...

Bye
 Sven


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


^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: PATCH: completions for su and implicit fg/bg
@ 1999-07-13  9:02 Sven Wischnowsky
  0 siblings, 0 replies; 16+ messages in thread
From: Sven Wischnowsky @ 1999-07-13  9:02 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> OK, the next problem seems to be that using ^D removes the quotes, although
> other completion functions don't.  I'm using

Oops. Forgot to restore the command line in two cases where it isn't
expected to change.

Bye
 Sven

diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Tue Jul 13 10:59:34 1999
+++ Src/Zle/zle_tricky.c	Tue Jul 13 10:59:52 1999
@@ -4380,10 +4380,14 @@
 	}
 	if (comppatmatch && *comppatmatch && comppatmatch != opm)
 	    haspattern = 1;
-	if (!useline && uselist)
+	if (!useline && uselist) {
 	    /* All this and the guy only wants to see the list, sigh. */
+	    cs = 0;
+	    foredel(ll);
+	    inststr(origline);
+	    cs = origcs;
 	    showinglist = -2;
-	else if (useline) {
+	} else if (useline) {
 	    /* We have matches. */
 	    if (nmatches > 1) {
 		/* There is more than one match. */
@@ -4399,9 +4403,13 @@
 		do_single(m->matches[0]);
 		invalidatelist();
 	    }
-	} else
+	} else {
 	    invalidatelist();
-
+	    cs = 0;
+	    foredel(ll);
+	    inststr(origline);
+	    cs = origcs;
+	}
 	/* Print the explanation strings if needed. */
 	if (!showinglist && validlist && usemenu != 2 && nmatches != 1) {
 	    Cmgroup g = amatches;

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


^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: PATCH: completions for su and implicit fg/bg
@ 1999-07-12 12:11 Sven Wischnowsky
  1999-07-12 14:29 ` Peter Stephenson
  0 siblings, 1 reply; 16+ messages in thread
From: Sven Wischnowsky @ 1999-07-12 12:11 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> Just trying compset -q to enhance completion for *sh -c:
> 
>   The word
>   currently being completed is split in separate words at the spaces. The 
>   resulting words are stored in the tt(words) array, and tt(PREFIX),
>   tt(SUFFIX), tt(QIPREFIX), and tt(QISUFFIX) are modified to reflect the 
>   word part that is completed.
> 
> What doesn't seem to get updated is CURRENT, which for consistency ought to
> point into the $words array as modified.

Whoa. Ahem.

This also corrects the test to decide if the ignored prefix/suffix
should be quoted or not.

Bye
 Sven

diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Fri Jul  9 15:48:20 1999
+++ Src/Zle/zle_tricky.c	Mon Jul 12 14:07:18 1999
@@ -5172,7 +5172,7 @@
 	compisuffix = ztrdup("");
 	zsfree(compqiprefix);
 	zsfree(compqisuffix);
-	if (instring) {
+	if (ois) {
 	    compqiprefix = qp;
 	    compqisuffix = qs;
 	} else {
@@ -5188,6 +5188,7 @@
 	    p = compwords[i] = (char *) getdata(n);
 	    untokenize(p);
 	}
+	compcurrent = cur + 1;
 	compwords[i] = NULL;
     }
     autoq = oaq;
diff -u od/Zsh/compwid.yo Doc/Zsh/compwid.yo
--- od/Zsh/compwid.yo	Mon Jul 12 10:21:21 1999
+++ Doc/Zsh/compwid.yo	Mon Jul 12 14:10:11 1999
@@ -622,9 +622,9 @@
 item(tt(-q))(
 The word
 currently being completed is split in separate words at the spaces. The 
-resulting words are stored in the tt(words) array, and tt(PREFIX),
-tt(SUFFIX), tt(QIPREFIX), and tt(QISUFFIX) are modified to reflect the 
-word part that is completed.
+resulting words are stored in the tt(words) array, and tt(CURRENT),
+tt(PREFIX), tt(SUFFIX), tt(QIPREFIX), and tt(QISUFFIX) are modified to
+reflect the word part that is completed.
 )
 enditem()
 

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


^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: PATCH: completions for su and implicit fg/bg
@ 1999-07-12 10:39 Sven Wischnowsky
  1999-07-12 11:27 ` Peter Stephenson
  0 siblings, 1 reply; 16+ messages in thread
From: Sven Wischnowsky @ 1999-07-12 10:39 UTC (permalink / raw)
  To: zsh-workers


I wrote:

> This allows `compset -q' on unquoted words -- almost. There is a
> problem when the match contains characters that have to be quoted. In
> such cases the match should be quoted twice (`a b' should be inserted
> as `a\\\ b'), but currently the completion code is far from being
> prepared for such double-quoting and I'm seeing to much places where
> changes are needed for a quick patch.

I've been thinking some more about this... This can get pretty ugly
when we have multiple calls to `compset -q' for the same word. In such 
cases we would have to keep track of the number of calls (the nesting
level) and then quote the words put into the command line n times. Of
course the results may become almost unreadable and it would require
changes in several parts of the code.

Hm. Automatically putting such strings in quotes is probably easier
but otherwise not much better. Does anybody see a better solution?
Should we just give up and make `compset -q' work only on quoted
strings again? Any other suggestions?

Bye
 Sven


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


^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: PATCH: completions for su and implicit fg/bg
@ 1999-07-09 13:47 Sven Wischnowsky
  0 siblings, 0 replies; 16+ messages in thread
From: Sven Wischnowsky @ 1999-07-09 13:47 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> > It's `compset -q' -- and with that I can repeat the question I asked
> > at the time when I sent the completion-quoting-patch: currently the
> > `-q' option only has an effect if the word on the command line is
> > quoted -- should we change it to work on unquoted strings, too?
> 
> Presumably the answer should be yes, for consistency.  I already gave an
> example with backslashing where it should be treated that way.

This allows `compset -q' on unquoted words -- almost. There is a
problem when the match contains characters that have to be quoted. In
such cases the match should be quoted twice (`a b' should be inserted
as `a\\\ b'), but currently the completion code is far from being
prepared for such double-quoting and I'm seeing to much places where
changes are needed for a quick patch.
I'll take care of that later.

Bye
 Sven

diff -u os/Zle/compctl.c Src/Zle/compctl.c
--- os/Zle/compctl.c	Fri Jul  9 10:56:31 1999
+++ Src/Zle/compctl.c	Fri Jul  9 15:41:02 1999
@@ -2096,9 +2096,7 @@
     case 'P': test = CVT_PREPAT; break;
     case 's': test = CVT_SUFNUM; break;
     case 'S': test = CVT_SUFPAT; break;
-    case 'q': return !(compquote && *compquote &&
-		       (*compquote == '\'' || *compquote == '"') &&
-		       !set_comp_sepptr());
+    case 'q': return set_comp_sepptr();
     default:
 	zerrnam(name, "bad option -%c", NULL, argv[0][1]);
 	return 1;
diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Fri Jul  9 10:56:33 1999
+++ Src/Zle/zle_tricky.c	Fri Jul  9 15:18:10 1999
@@ -5171,10 +5171,16 @@
 	zsfree(compisuffix);
 	compisuffix = ztrdup("");
 	zsfree(compqiprefix);
-	compqiprefix = qp;
 	zsfree(compqisuffix);
-	compqisuffix = qs;
-
+	if (instring) {
+	    compqiprefix = qp;
+	    compqisuffix = qs;
+	} else {
+	    compqiprefix = ztrdup(quotename(qp, NULL));
+	    zsfree(qp);
+	    compqisuffix = ztrdup(quotename(qs, NULL));
+	    zsfree(qs);
+	}
 	freearray(compwords);
 	i = countlinknodes(foo);
 	compwords = (char **) zalloc((i + 1) * sizeof(char *));
diff -u od/Zsh/compwid.yo Doc/Zsh/compwid.yo
--- od/Zsh/compwid.yo	Fri Jul  9 10:56:41 1999
+++ Doc/Zsh/compwid.yo	Fri Jul  9 15:42:36 1999
@@ -620,7 +620,7 @@
 testing and modification is performed as if it were not given.
 )
 item(tt(-q))(
-If the cursor is currently inside single or double quotes, the word
+The word
 currently being completed is split in separate words at the spaces. The 
 resulting words are stored in the tt(words) array, and tt(PREFIX),
 tt(SUFFIX), tt(QIPREFIX), and tt(QISUFFIX) are modified to reflect the 

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


^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: PATCH: completions for su and implicit fg/bg
@ 1999-07-09 10:44 Sven Wischnowsky
  1999-07-09 12:34 ` Peter Stephenson
  0 siblings, 1 reply; 16+ messages in thread
From: Sven Wischnowsky @ 1999-07-09 10:44 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> Oliver Kiddle wrote:
> > First, is a patch to _first which completes jobs after an initial % on
> > the command line.
> 
> I think the code in _first was deliberately left commented because it gets
> run every time, but the impact of this change is minimal.

Right. And since we only want it in command position, we should
probably put it in _command_names.

> > This is useful when foregrounding or backgrounding a
> > process without fg/bg. This feature seems to be undocumented actually.
> 
> Hmm, I thought it was an option, but it seems it's run unconditionally at
> the top of execcmd().  What is an option is AUTO_RESUME.

It's in builtins.yo under `bg' and `fg'.

> > I've included a basic completion for the
> > common shells which just does the -c option.
> 
> It really needs to be told to treat a (possibly quoted) word after -c as a
> complete command line.  I've forgotten how to do that.

It's `compset -q' -- and with that I can repeat the question I asked
at the time when I sent the completion-quoting-patch: currently the
`-q' option only has an effect if the word on the command line is
quoted -- should we change it to work on unquoted strings, too?

And: nothing against giving _normal (an) optional argument(s) that
will be put at the front of $words. (_normal is one of the older
functions that survived (with changes) the transition from reporting
command line words as positional parameters to the $words array we
have now; that's why nobody made it accept arguments again, I think).

Bye
 Sven


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


^ permalink raw reply	[flat|nested] 16+ messages in thread
* PATCH: completions for su and implicit fg/bg
@ 1999-07-09 10:23 Oliver Kiddle
  1999-07-09 10:04 ` Peter Stephenson
  1999-07-09 10:40 ` Andrej Borsenkow
  0 siblings, 2 replies; 16+ messages in thread
From: Oliver Kiddle @ 1999-07-09 10:23 UTC (permalink / raw)
  To: Zsh workers

First, is a patch to _first which completes jobs after an initial % on
the command line. This is useful when foregrounding or backgrounding a
process without fg/bg. This feature seems to be undocumented actually.
I'll send a patch to the docs unless someone locates it there somewhere
already. Completion of commands where the command will be run should
really quote an initial '%' (or more to the point should preserve a
quote which has been typed). This wouldn't be that easy to do though
because in many other cases when completing command names, an initial
'%' would be totally valid.

The second new completion is for su. Usernames are completed as the
first parameter or second after a -. Next it works out which shell the
specified user has and completes options for that shell. My first
thought was that I'd use something like compgen -l $shell but ofcourse
compgen doesn't support -l. Judging by _find, it seems that _normal is
the way to do this but it would need the shell's name to be on the
command-line. I've got it to work by pulling the relevant parts out of
_normal and roughly repeating it. I didn't bother with the pattern
matching stuff though. A better way would be if _normal took an optional
parameter similar to the parameter to compctl -l. I can make this change
if it is agreed. So that this stuff for completing shell parameters
after su is actually useful, I've included a basic completion for the
common shells which just does the -c option. Note that I've not bothered
to deal with the extra options which GNU su offers because I think they
are all utterly pointless.

Oliver Kiddle

*** Completion/Base/_first.old	Mon Jun 21 08:14:44 1999
--- Completion/Base/_first	Fri Jul  9 10:03:52 1999
***************
*** 61,63 ****
--- 61,68 ----
  #         (( i++ ))
  #       done
  #     fi
+ 
+ # Complete jobs in implicit fg and bg
+ if [[ "$CURRENT" = 1 && "$PREFIX[1]" = "%" ]]; then
+   compgen -j -P '%'
+ fi
*** Completion/User/_su.old	Fri Jul  9 10:25:55 1999
--- Completion/User/_su	Fri Jul  9 10:25:20 1999
***************
*** 0 ****
--- 1,22 ----
+ #compdef su
+ 
+ local shell comp name usr base
+ 
+ [[ $words[2] != - ]]
+ (( base=$?+2 ))
+ 
+ if [[ CURRENT -eq base ]]; then
+   compgen -u && return
+   usr=root
+ elif [[ CURRENT -ge base+1 ]]; then
+   usr=$words[base]
+ else
+   return
+ fi
+ 
+ shell=${"$(egrep "^$usr:" </etc/passwd)"##*:}
+ compset -n $base
+ for name in $shell $shell:t -default-; do
+   comp="$_comps[$name]"
+   [[ ! -z "$comp" ]] && "$comp" && return
+ done  
*** Completion/User/_sh.old	Fri Jul  9 10:25:52 1999
--- Completion/User/_sh	Fri Jul  9 10:25:20 1999
***************
*** 0 ****
--- 1,3 ----
+ #compdef sh ksh bash zsh csh tcsh rc
+ 
+ compset -N '-c' && _normal


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

end of thread, other threads:[~1999-07-19 14:09 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-19 13:58 PATCH: completions for su and implicit fg/bg Sven Wischnowsky
1999-07-19 13:38 ` Peter Stephenson
  -- strict thread matches above, loose matches on Subject: below --
1999-07-13  9:02 Sven Wischnowsky
1999-07-12 12:11 Sven Wischnowsky
1999-07-12 14:29 ` Peter Stephenson
1999-07-12 10:39 Sven Wischnowsky
1999-07-12 11:27 ` Peter Stephenson
1999-07-09 13:47 Sven Wischnowsky
1999-07-09 10:44 Sven Wischnowsky
1999-07-09 12:34 ` Peter Stephenson
     [not found]   ` <3785FAFB.3E9FDD41@thoth.u-net.com>
1999-07-09 13:53     ` Oliver Kiddle
1999-07-09 14:47       ` Peter Stephenson
1999-07-09 15:53         ` Oliver Kiddle
1999-07-09 10:23 Oliver Kiddle
1999-07-09 10:04 ` Peter Stephenson
1999-07-09 10:40 ` Andrej Borsenkow

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