Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

directory message for jobs builtin



It struck me as a bit funny that, while you get `pwd' messages when
starting a or suspending a job which you started in a different
directory, there's no way of actually inquiring for the directory
associated with a job, even though that is stored.  This patch adds a
`-d' option to jobs which prints thinks like
(pwd : ~/src/zsh-3.1.1/Src)
in exactly the same format as if you had run fg on the job started
somewhere else.

As you would expect, this doesn't take much new code.  It should save
me a bit of hunting around in time to come, but at heart I think it's
just a matter of consistency.

*** Doc/Zsh/builtins.yo.pwd	Mon Feb 10 13:43:43 1997
--- Doc/Zsh/builtins.yo	Mon Feb 10 13:52:40 1997
***************
*** 552,563 ****
  integers are not permitted.
  )
  findex(jobs)
! item(tt(jobs) [ tt(-lprs) ] [ var(job) ... ])(
  Lists information about each given job, or all jobs
  if var(job) is omitted.  The tt(-l) flag lists process
  IDs, and the tt(-p) flag lists process groups.
  If the tt(-r) flag is specified only running jobs will be listed
  and if the tt(-s) flag is given only stopped jobs are shown.
  )
  findex(kill)
  cindex(killing jobs)
--- 552,566 ----
  integers are not permitted.
  )
  findex(jobs)
! item(tt(jobs) [ tt(-dlprs) ] [ var(job) ... ])(
  Lists information about each given job, or all jobs
  if var(job) is omitted.  The tt(-l) flag lists process
  IDs, and the tt(-p) flag lists process groups.
  If the tt(-r) flag is specified only running jobs will be listed
  and if the tt(-s) flag is given only stopped jobs are shown.
+ If the tt(-d) flag is given, the directory from which the job was
+ started (which may not be the current directory of the job) will also
+ be shown.
  )
  findex(kill)
  cindex(killing jobs)
*** Src/hashtable.h.pwd	Mon Feb 10 10:36:26 1997
--- Src/hashtable.h	Mon Feb 10 10:36:38 1997
***************
*** 298,304 ****
  
      {NULL, "history", 0, bin_fc, 0, -1, BIN_FC, "nrdDfEim", "l"},
      {NULL, "integer", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "lrtux", "i"},
!     {NULL, "jobs", 0, bin_fg, 0, -1, BIN_JOBS, "lpZrs", NULL},
      {NULL, "kill", 0, bin_kill, 0, -1, 0, NULL, NULL},
      {NULL, "let", 0, bin_let, 1, -1, 0, NULL, NULL},
      {NULL, "limit", 0, bin_limit, 0, -1, 0, "sh", NULL},
--- 298,304 ----
  
      {NULL, "history", 0, bin_fc, 0, -1, BIN_FC, "nrdDfEim", "l"},
      {NULL, "integer", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "lrtux", "i"},
!     {NULL, "jobs", 0, bin_fg, 0, -1, BIN_JOBS, "dlpZrs", NULL},
      {NULL, "kill", 0, bin_kill, 0, -1, 0, NULL, NULL},
      {NULL, "let", 0, bin_let, 1, -1, 0, NULL, NULL},
      {NULL, "limit", 0, bin_limit, 0, -1, 0, "sh", NULL},
*** Src/jobs.c.pwd	Mon Feb 10 10:35:47 1997
--- Src/jobs.c	Mon Feb 10 13:57:15 1997
***************
*** 386,394 ****
      return ((j->procs->ti.ut + j->procs->ti.st) / clktck >= reporttime);
  }
  
! /* lng = 0 means jobs    *
!  * lng = 1 means jobs -l *
!  * lng = 2 means jobs -p 
   *
   * synch = 0 means asynchronous
   * synch = 1 means synchronous
--- 386,395 ----
      return ((j->procs->ti.ut + j->procs->ti.st) / clktck >= reporttime);
  }
  
! /* !(lng & 3) means jobs    *
!  *  (lng & 1) means jobs -l *
!  *  (lng & 2) means jobs -p
!  *  (lng & 4) means jobs -d
   *
   * synch = 0 means asynchronous
   * synch = 1 means synchronous
***************
*** 457,463 ****
  	    putc('\n', fout);
  	for (pn = jn->procs; pn;) {
  	    len2 = ((job == thisjob) ? 5 : 10) + len;	/* 2 spaces */
! 	    if (lng)
  		qn = pn->next;
  	    else
  		for (qn = pn->next; qn; qn = qn->next) {
--- 458,464 ----
  	    putc('\n', fout);
  	for (pn = jn->procs; pn;) {
  	    len2 = ((job == thisjob) ? 5 : 10) + len;	/* 2 spaces */
! 	    if (lng & 3)
  		qn = pn->next;
  	    else
  		for (qn = pn->next; qn; qn = qn->next) {
***************
*** 477,494 ****
  		    fprintf(fout, (job > 9) ? "        " : "       ");
  	    else
  		fprintf(fout, "zsh: ");
! 	    if (lng)
! 		if (lng == 1)
! 		    fprintf(fout, "%ld ", (long) pn->pid);
! 		else {
! 		    pid_t x = jn->gleader;
! 
! 		    fprintf(fout, "%ld ", (long) x);
! 		    do
! 			skip++;
! 		    while ((x /= 10));
  		    skip++;
! 		    lng = 0;
  	    } else
  		fprintf(fout, "%*s", skip, "");
  	    if (pn->status == SP_RUNNING)
--- 478,494 ----
  		    fprintf(fout, (job > 9) ? "        " : "       ");
  	    else
  		fprintf(fout, "zsh: ");
! 	    if (lng & 1)
! 		fprintf(fout, "%ld ", (long) pn->pid);
! 	    else if (lng & 2) {
! 		pid_t x = jn->gleader;
! 
! 		fprintf(fout, "%ld ", (long) x);
! 		do
  		    skip++;
! 		while ((x /= 10));
! 		skip++;
! 		lng &= ~3;
  	    } else
  		fprintf(fout, "%*s", skip, "");
  	    if (pn->status == SP_RUNNING)
***************
*** 521,531 ****
  	fflush(fout);
      }
  
! /* print "(pwd now: foo)" messages */
! 
!     if (interact && job == thisjob && strcmp(jn->pwd, pwd)) {
! 	fprintf(shout, "(pwd now: ");
! 	fprintdir(pwd, shout);
  	fprintf(shout, ")\n");
  	fflush(shout);
      }
--- 521,533 ----
  	fflush(fout);
      }
  
! /* print "(pwd now: foo)" messages: with (lng & 4) we are printing
!  * the directory where the job is running, otherwise the current directory
!  */
! 
!     if ((lng & 4) || (interact && job == thisjob && strcmp(jn->pwd, pwd))) {
! 	fprintf(shout, "(pwd %s: ", (lng & 4) ? "" : "now");
! 	fprintdir((lng & 4) ? jn->pwd : pwd, shout);
  	fprintf(shout, ")\n");
  	fflush(shout);
      }
***************
*** 948,953 ****
--- 950,958 ----
      }
  
      lng = (ops['l']) ? 1 : (ops['p']) ? 2 : 0;
+     if (ops['d'])
+ 	lng |= 4;
+     
      if ((func == BIN_FG || func == BIN_BG) && !jobbing) {
  	/* oops... maybe bg and fg should have been disabled? */
  	zwarnnam(name, "no job control in this shell.", NULL, 0);


-- 
Peter Stephenson <pws@xxxxxx>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.



Messages sorted by: Reverse Date, Date, Thread, Author