bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Idea: jobs(1) -i to print only :%ID:s


From: Steffen Nurpmeso
Subject: Re: Idea: jobs(1) -i to print only :%ID:s
Date: Thu, 09 Nov 2023 19:11:07 +0100
User-agent: s-nail v14.9.24-563-g944131280a

Steffen Nurpmeso wrote in
 <20231109011212.tC9Hj%steffen@sdaoden.eu>:
 ...

Something like this that would be, adding JLIST_SPEC_ONLY and
jobs(1) -j.  Just in case of interest.

diff --git a/builtins/jobs.def b/builtins/jobs.def
index 1ce098d08b..989a78079e 100644
--- a/builtins/jobs.def
+++ b/builtins/jobs.def
@@ -23,13 +23,14 @@ $PRODUCES jobs.c
 $BUILTIN jobs
 $FUNCTION jobs_builtin
 $DEPENDS_ON JOB_CONTROL
-$SHORT_DOC jobs [-lnprs] [jobspec ...] or jobs -x command [args]
+$SHORT_DOC jobs [-jlnprs] [jobspec ...] or jobs -x command [args]
 Display status of jobs.
 
 Lists the active jobs.  JOBSPEC restricts output to that job.
 Without options, the status of all active jobs is displayed.
 
 Options:
+  -j   lists only jobspecs
   -l   lists process IDs in addition to the normal information
   -n   lists only processes that have changed status since the last
                notification
@@ -90,10 +91,13 @@ jobs_builtin (list)
   state = JSTATE_ANY;
 
   reset_internal_getopt ();
-  while ((opt = internal_getopt (list, "lpnxrs")) != -1)
+  while ((opt = internal_getopt (list, "jlpnxrs")) != -1)
     {
       switch (opt)
        {
+       case 'j':
+         form = JLIST_SPEC_ONLY;
+         break;
        case 'l':
          form = JLIST_LONG;
          break;
diff --git a/doc/bash.1 b/doc/bash.1
index 55c562208a..8dc34a00d7 100644
--- a/doc/bash.1
+++ b/doc/bash.1
@@ -9150,7 +9150,7 @@ error occurs while reading or writing the history file, 
an invalid
 history expansion supplied as an argument to \fB\-p\fP fails.
 .RE
 .TP
-\fBjobs\fP [\fB\-lnprs\fP] [ \fIjobspec\fP ... ]
+\fBjobs\fP [\fB\-jlnprs\fP] [ \fIjobspec\fP ... ]
 .PD 0
 .TP
 \fBjobs\fP \fB\-x\fP \fIcommand\fP [ \fIargs\fP ... ]
@@ -9160,6 +9160,9 @@ meanings:
 .RS
 .PD 0
 .TP
+.B \-j
+List only the \fIjobspec\fPs.
+.TP
 .B \-l
 List process IDs
 in addition to the normal information.
diff --git a/jobs.c b/jobs.c
index 45869dd819..b56cecccb3 100644
--- a/jobs.c
+++ b/jobs.c
@@ -2037,6 +2037,13 @@ pretty_print_job (job_index, format, stream)
 {
   register PROCESS *p;
 
+  /* Format only jobspec? */
+  if (format == JLIST_SPEC_ONLY)
+    {
+      fprintf (stream, "%%%d\n", job_index + 1);
+      return;
+    }
+
   /* Format only pid information about the process group leader? */
   if (format == JLIST_PID_ONLY)
     {
diff --git a/jobs.h b/jobs.h
index 276204f0c7..5d1cc43d1f 100644
--- a/jobs.h
+++ b/jobs.h
@@ -32,8 +32,9 @@
 #define JLIST_STANDARD       0
 #define JLIST_LONG          1
 #define JLIST_PID_ONLY      2
-#define JLIST_CHANGED_ONLY   3
-#define JLIST_NONINTERACTIVE 4
+#define JLIST_SPEC_ONLY             3
+#define JLIST_CHANGED_ONLY   4
+#define JLIST_NONINTERACTIVE 5
 
 /* I looked it up.  For pretty_print_job ().  The real answer is 24. */
 #define LONGEST_SIGNAL_DESC 24

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]