From: Micah Cowan <micah@cowan.name>
To: zsh-workers@sunsite.dk
Subject: "jobs" command within substitution
Date: Thu, 08 Mar 2007 11:27:07 -0800 [thread overview]
Message-ID: <45F0638B.6090203@cowan.name> (raw)
Hello, all. This is my first post to this group.
I scoured the manpages and list archives, but could not find the answer
I seek.
My question, in a nutshell, is: How can I effectively use the "jobs"
builtin command in producing the interactive prompt?
-- THE PROBLEM --
The following line was the obvious choice (provided appropriate options
are set), and indeed works fine in several other shells:
: PS1='$(jobs | pjobs_gen_prompt)'
: # pjobs_gen_prompt is a custom shell fn
However, I've discovered that, the output of
: echo $(jobs)
is empty (apart from the spurious newline), even when executing "jobs"
in the current shell would produce output. In fact,
: ( jobs )
still produces the expected, same results as execution directly within
the current shell.
It might be argued, due to the language of POSIX ("The jobs utility
shall display the status of jobs that were started in the current shell
environment"), that it is not required to do so for /copies/ of the
current shell environment: however, the case between $(jobs) and (jobs)
should at least be consistent, since their behavior in POSIX is defined
the same. I don't think the language in the standard is precise enough
to warrant me claiming that this actually /breaks/ POSIX, but it seems
against the likely /intentions/ at any rate, at least to me.
My personal opinion is that this is a bug, but I'd be happy to hear
explanations if this is intended behavior.
-- WORKAROUNDS? --
Regardless of whether this is a bug or not, I still need a way to do
what I want. You can get a very clear picture of what I'm trying to
accomplish by downloading my script (it lacks spit and polish that I
plan to add soon, so it's not the "official" version yet; but it's
functional):
http://micah.cowan.name/svn/promptjobs/trunk/prompt-jobs.sh
^^^ source this, DON'T execute it (it won't work).
and sourcing it (". ./prompt-jobs.sh"). After this, run a couple of jobs
in the foreground (say, "man man" or "ls | less") and then suspend them
via Ctrl-Z. In bash, this will produce a prompt such as:
micah(1:man 2:ls)$
The prompt will be colorized in color-supporting terminals.
I wish to get the same effect in zsh. You can follow the same steps in
zsh, and will get the colorized version of your prompt, but you won't
get the joblists.
In the case of bash, I'm actually not using command-substitution on the
value of PS1, but I'm using bash's PROMPT_COMMAND to /set/ PS1's value
via a command-substitution. This is because, when bash is interpolating
the value from PS1, it treats the escape-sequence protectors \[ and \]
(equivalent to zsh's %{, %}) before it does the command-substitution,
which would cause pjobs_gen_prompt's \[, \] to be printed literally. Zsh
treats %{ and %} after command-substitution, so that's not a problem.
Is there any /other/ way to do this that will work, today, for zsh?
Perhaps an equivalent to bash's PROMPT_COMMAND that I haven't found in
the documentation, or some option I missed that will allow jobs within
command substitution to produce the output I'm expecting?
Thanks /very/ much for taking the time to read this length explanation.
And, please let me know what you think of my little script :)
--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
next reply other threads:[~2007-03-08 19:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-08 19:27 Micah Cowan [this message]
[not found] ` <17393e3e0703081155o7a240628t49fae220ac9f49ae@mail.gmail.com>
[not found] ` <45F070A9.5060502@cowan.name>
2007-03-08 21:19 ` Matt Wozniski
2007-03-08 22:00 ` Micah Cowan
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=45F0638B.6090203@cowan.name \
--to=micah@cowan.name \
--cc=zsh-workers@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).