From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@sunsite.dk
Subject: Re: fg jobs info
Date: Tue, 04 Sep 2007 08:31:04 -0700 [thread overview]
Message-ID: <070904083104.ZM25598@torch.brasslantern.com> (raw)
In-Reply-To: <20070903163147.GA14017@mastermind>
In-Reply-To: <20070904111631.81486.qmail@smasher.org>
On Sep 3, 12:31pm, Matthew Wozniski wrote:
} Subject: Re: fg jobs info
}
} On Sun, Sep 02, 2007 at 10:59:53AM -0700, Bart Schaefer wrote:
} ...
} > The "jobs" command should accept all the same job-identifier patterns
} > as "fg", and in recent zsh "jobs" doesn't lose track of the job list
} > when run in a subshell
}
} In how recent a zsh? I can't seem to get that working with 4.3.4.
You're right. $(jobs) and (jobs) produce different output. I thought
that because the latter worked, the former would also.
Looks to me as if there's a bug here; compare
print $(jobs)
(print $(jobs))
Also, although "jobs" or "jobs -l" prints out the entire jobs listing
even in subshells/pipelines/etc., "jobs %2" (for example) produces a
"no such job" error, which surprised me. That should at least be
documented. Try:
sleep 40 & sleep 30 &
jobs | cat
jobs %1 | cat
So the easy way out is not going to work here after all.
On Sep 4, 11:16pm, Atom Smasher wrote:
}
} On Sun, 2 Sep 2007, Bart Schaefer wrote:
}
} > Have a look at the variables jobdirs, jobtexts, and jobstates in the
} > zsh/parameter module. Or there's a lazier way out:
} =============
}
} that seems reasonably elegant... as long as a) there's only one
} suspended job or b) jobs are only referred to by number :(
}
} if the there's more than one job and either 1) the current job is
} implied or 2) a job is specified not by job number, things get messy.
Not all *that* messy. "The current job" is
jobno=${(k)jobstates[(r)*:+:*]}
Something like "fg %fred" is
jobno=${(k)jobstates[(r)*:?:fred*]}
And "fg %?wilma" is
jobno=${(k)jobstates[(r)*:?:*wilma*]}
Then you just do
fgjob="${jobtexts[$jobno]}"
fg %$jobno
} also, here's a case where (given what i'm trying to do) i'm confident
} that anything would fail (at least partially), short of some
} non-trivial updates to zsh:
}
} % fg %1 %2
You just have to handle that inside your "fg" function.
fg() {
[[ -z $1 ]] && set -- %+
# Still ignoring all sorts of error handling here ...
for jobspec
do
case $jobspec in
(%<->) jobno=${jobspec#%};;
(%+) jobno=${(k)jobstates[(r)*:+:*]};;
(%-) jobno=${(k)jobstates[(r)*:-:*]};;
# Need more quoting than shown for $jobspec below
(%[?]*) jobno=${(k)jobstates[(r)*:?:*${jobspec#%?}*]};;
(*) jobno=${(k)jobstates[(r)*:?:${jobspec#%}*]};;
esac
tab-title "$jobtexts[$jobno]"
builtin fg %$jobno
done
}
Jobs don't get renumbered as others exit, so the jobspecs that come in
are usable throughout.
The case that's going to be pretty difficult to handle is:
% %2
(That is, bringing a job to the foreground by simply typing its job spec.
Probably need a preexec function to catch that one.)
Incidentally, yet another bug:
% sleep 30 & sleep 50 &
% fg %- %-
[1] - running sleep 30
fg: %3: no such job
Where did I ever ask for job 3 ?
next prev parent reply other threads:[~2007-09-04 15:32 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-02 15:43 Atom Smasher
2007-09-02 17:59 ` Bart Schaefer
2007-09-03 7:38 ` Stephane Chazelas
2007-09-03 15:58 ` Bart Schaefer
2007-09-03 16:31 ` Matthew Wozniski
2007-09-04 11:16 ` Atom Smasher
2007-09-04 15:31 ` Bart Schaefer [this message]
2007-09-04 20:38 ` Peter Stephenson
2007-09-04 20:45 ` Peter Stephenson
2007-09-05 9:02 ` Atom Smasher
2007-09-05 9:28 ` Peter Stephenson
2007-09-05 11:21 ` Miek Gieben
2007-09-05 11:34 ` Matthew Wozniski
2007-09-05 11:36 ` Miek Gieben
2007-09-05 11:34 ` Atom Smasher
2007-09-05 11:40 ` Frank Terbeck
2007-09-05 12:18 ` Miek Gieben
2007-09-05 15:30 ` Bart Schaefer
2007-09-05 15:55 ` Peter Stephenson
-- strict thread matches above, loose matches on Subject: below --
2013-08-30 1:12 mailcap configuration in zsh can't open .bk files vinurs
2013-08-30 2:59 ` Phil Pennock
2013-08-30 3:27 ` shawn wilson
2013-08-30 8:29 ` Peter Stephenson
2013-08-30 17:10 ` Bart Schaefer
2013-09-01 17:11 ` Peter Stephenson
2013-09-02 1:28 ` vinurs
2013-09-02 13:46 ` Peter Stephenson
2013-09-02 17:45 ` Bart Schaefer
2010-08-20 15:35 Synchronous vs. Asynchronous Bart Schaefer
2010-08-20 15:45 ` Peter Stephenson
2010-08-20 17:36 ` Bart Schaefer
2010-08-21 18:41 ` Peter Stephenson
2010-08-21 22:31 ` Vincent Lefevre
2010-08-22 5:02 ` Bart Schaefer
2010-08-22 5:42 ` Bart Schaefer
2010-08-22 17:53 ` Peter Stephenson
[not found] <1209745744.25440.ezmlm@sunsite.dk>
2008-05-02 17:39 ` Zsh hangs sometimes? Kamil Jońca
2008-05-02 22:44 ` Peter Stephenson
2008-05-03 11:35 ` Bart Schaefer
2008-05-04 12:13 ` Peter Stephenson
2008-05-04 17:00 ` Bart Schaefer
2008-05-04 18:14 ` Peter Stephenson
2008-05-04 20:00 ` Bart Schaefer
2008-05-05 11:54 ` Aaron Davies
2007-09-05 16:34 preexec hook: possible enhancement? Matthew Wozniski
2007-09-05 17:14 ` Bart Schaefer
2007-09-05 19:05 ` Peter Stephenson
2007-09-05 21:11 ` Matthew Wozniski
2007-09-08 17:20 ` Bart Schaefer
2007-09-05 19:32 ` Stephane Chazelas
2007-03-31 20:51 Documentation of colon in parameter expansion Miciah Dashiel Butler Masters
2007-04-01 17:53 ` Bart Schaefer
2007-04-01 18:26 ` Peter Stephenson
2006-10-06 15:07 Move command line options to start of line Peter Stephenson
2006-10-07 2:55 ` Bart Schaefer
2006-10-07 6:20 ` Andrey Borzenkov
2006-10-07 12:02 ` Peter Stephenson
2006-10-07 12:39 ` Bart Schaefer
2006-10-07 17:21 ` Dan Nelson
2006-10-07 17:36 ` Peter Stephenson
2006-09-04 8:43 Solved, but now a new twist (was: Double Evaluation Question (not in FAQ)) Com MN PG P E B Consultant 3
2006-09-04 18:24 ` Bart Schaefer
2006-09-07 17:53 ` Peter Stephenson
[not found] <schaefer@brasslantern.com>
2006-07-30 6:29 ` Rebinding a widget within a keymap Bart Schaefer
2006-07-30 17:18 ` Peter Stephenson
2006-07-30 17:46 ` Bart Schaefer
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=070904083104.ZM25598@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-users@sunsite.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).