zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@thoth.u-net.com>
To: Zsh workers <zsh-workers@sunsite.auc.dk>
Subject: PATCH: completions for su and implicit fg/bg
Date: Fri, 09 Jul 1999 11:23:06 +0100	[thread overview]
Message-ID: <3785CD8A.4CAA6484@thoth.u-net.com> (raw)

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


             reply	other threads:[~1999-07-09 10:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-09 10:23 Oliver Kiddle [this message]
1999-07-09 10:04 ` Peter Stephenson
1999-07-09 10:40 ` Andrej Borsenkow
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 13:47 Sven Wischnowsky
1999-07-12 10:39 Sven Wischnowsky
1999-07-12 11:27 ` Peter Stephenson
1999-07-12 12:11 Sven Wischnowsky
1999-07-12 14:29 ` Peter Stephenson
1999-07-13  9:02 Sven Wischnowsky
1999-07-19 13:58 Sven Wischnowsky
1999-07-19 13:38 ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3785CD8A.4CAA6484@thoth.u-net.com \
    --to=opk@thoth.u-net.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).