From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25408 invoked from network); 6 Nov 2001 10:49:17 -0000 Received: from ns2.primenet.com.au (HELO primenet.com.au) (?rsCskihfMyyIJecy+R+RqdVl8RAEwe0Z?@203.24.36.3) by ns1.primenet.com.au with SMTP; 6 Nov 2001 10:49:17 -0000 Received: (qmail 23716 invoked from network); 6 Nov 2001 10:49:16 -0000 Received: from sunsite.dk (130.225.247.90) by proxy.melb.primenet.com.au with SMTP; 6 Nov 2001 10:49:16 -0000 Received: (qmail 7403 invoked by alias); 6 Nov 2001 10:49:04 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 16224 Received: (qmail 7390 invoked from network); 6 Nov 2001 10:49:03 -0000 X-VirusChecked: Checked Sender: kiddleo@cav.logica.co.uk Message-ID: <3BE7BFFF.9D9EAD2F@yahoo.co.uk> Date: Tue, 06 Nov 2001 10:48:31 +0000 From: Oliver Kiddle X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.15 i686) X-Accept-Language: en MIME-Version: 1.0 To: zsh-workers@sunsite.dk Subject: PATCH: kill builtin completion and -n opt Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit The kill builtins in both ksh93 and bash take a -n option which is like -s but takes signal numbers instead of names as a parameter. Adding this is no more than a few lines of code (most of the patch being reindentation). This also updates _kill to use _arguments to complete options. I had to modify _signals to use zparseopts so that it could be called from _arguments. _alternative ought to be usable from _arguments too really. I used a state here. Note that kill is another candidate for using the ignore-line style. Oliver Index: Completion/Unix/Type/_signals =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_signals,v retrieving revision 1.1 diff -u -u -r1.1 _signals --- Completion/Unix/Type/_signals 2001/04/02 11:35:43 1.1 +++ Completion/Unix/Type/_signals 2001/11/06 10:44:14 @@ -7,16 +7,15 @@ # # A `-' or `--' as the first argument is ignored. -local expl last=-3 minus +local expl last minus -while [[ "$1" = -[ap] ]]; do - if [[ "$1" = -a ]]; then - last=-1 - else - minus=- - fi - shift -done +zparseopts -D -K -E 'p=minus' 'a=last' +if [[ -z "$last" ]]; then + last=-1 +else + last=-3 +fi +[[ -n "$minus" ]] && minus='-' [[ "$1" = -(|-) ]] && shift Index: Completion/Zsh/Command/_jobs_builtin =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_jobs_builtin,v retrieving revision 1.1 diff -u -u -r1.1 _jobs_builtin --- Completion/Zsh/Command/_jobs_builtin 2001/04/11 21:47:18 1.1 +++ Completion/Zsh/Command/_jobs_builtin 2001/11/06 10:44:14 @@ -2,7 +2,7 @@ _arguments -C -s \ "(-d -l -p -r -s *)-Z[specify string to replace shell's argument and environment with]:string" \ - '(-Z)-d[show directory from which to job was started]' \ + '(-Z)-d[show directory from which each job was started]' \ '(-Z)-l[list process IDs]' \ '(-Z)-p[list process groups]' \ '(-Z -s)-r[list only running jobs]' \ Index: Completion/Zsh/Command/_kill =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_kill,v retrieving revision 1.1 diff -u -u -r1.1 _kill --- Completion/Zsh/Command/_kill 2001/04/02 11:29:05 1.1 +++ Completion/Zsh/Command/_kill 2001/11/06 10:44:14 @@ -1,6 +1,18 @@ #compdef kill -_alternative \ - 'signals:: _signals -p' \ +local curcontext="$curcontext" line state ret=1 + +_arguments -C \ + '(-s -l 1)-n[specify signal number]:signal number' \ + '(-n -l 1)-s[specify signal name]:signal:_signals' \ + '(-n -s)-l[list signal names or numbers of specified signals]:*:signal:_signals' \ + '(-n -s -l)1::signal:_signals -p' \ + '*:processes:->processes' && ret=0 + +if [[ -n "$state" && -prefix [%0-9]# ]]; then + _alternative \ 'processes:: _pids' \ - 'jobs:: _jobs -t' + 'jobs:: _jobs -t' && ret=0 +fi + +return ret Index: Doc/Zsh/builtins.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v retrieving revision 1.40 diff -u -u -r1.40 builtins.yo --- Doc/Zsh/builtins.yo 2001/10/18 14:22:21 1.40 +++ Doc/Zsh/builtins.yo 2001/11/06 10:44:14 @@ -534,8 +534,8 @@ findex(kill) cindex(killing jobs) cindex(jobs, killing) -xitem(tt(kill) [ tt(-s) var(signal_name) ] var(job) ...) -xitem(tt(kill) [ tt(-)var(sig) ] var(job) ...) +xitem(tt(kill) [ tt(-s) var(signal_name) | tt(-n) var(signal_number) | \ +tt(-)var(sig) ] var(job) ...) item(tt(kill) tt(-l) [ var(sig) ... ])( Sends either tt(SIGTERM) or the specified signal to the given jobs or processes. @@ -544,7 +544,7 @@ will be sent a `tt(CONT)' signal if it is stopped. The argument var(job) can be the process ID of a job not in the job list. -In the third form, tt(kill -l), if var(sig) is not +In the second form, tt(kill -l), if var(sig) is not specified the signal names are listed. Otherwise, for each var(sig) that is a name, the corresponding signal number is listed. For each var(sig) that is a signal number or a number Index: Src/jobs.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v retrieving revision 1.13 diff -u -u -r1.13 jobs.c --- Src/jobs.c 2001/06/27 11:22:05 1.13 +++ Src/jobs.c 2001/11/06 10:44:14 @@ -1500,21 +1500,32 @@ putchar('\n'); return 0; } - if ((*argv)[1] == 's' && (*argv)[2] == '\0') - signame = *++argv; - else - signame = *argv + 1; - /* check for signal matching specified name */ - for (sig = 1; sig <= SIGCOUNT; sig++) - if (!cstrpcmp(sigs + sig, &signame)) - break; - if (*signame == '0' && !signame[1]) - sig = 0; - if (sig > SIGCOUNT) { - zwarnnam(nam, "unknown signal: SIG%s", signame, 0); - zwarnnam(nam, "type kill -l for a List of signals", NULL, 0); - return 1; + if ((*argv)[1] == 'n' && (*argv)[2] == '\0') { + char *endp; + + sig = zstrtol(*++argv, &endp, 10); + if (*endp) { + zwarnnam(nam, "invalid signal number", signame, 0); + return 1; + } + } else { + if ((*argv)[1] == 's' && (*argv)[2] == '\0') + signame = *++argv; + else + signame = *argv + 1; + + /* check for signal matching specified name */ + for (sig = 1; sig <= SIGCOUNT; sig++) + if (!cstrpcmp(sigs + sig, &signame)) + break; + if (*signame == '0' && !signame[1]) + sig = 0; + if (sig > SIGCOUNT) { + zwarnnam(nam, "unknown signal: SIG%s", signame, 0); + zwarnnam(nam, "type kill -l for a List of signals", NULL, 0); + return 1; + } } } argv++; _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. For further information visit http://www.messagelabs.com/stats.asp