* A startup function for interactive rc's is unnecessary
@ 1991-08-27 19:07 Chris Siebenmann
1991-08-31 9:58 ` John Mackin
0 siblings, 1 reply; 2+ messages in thread
From: Chris Siebenmann @ 1991-08-27 19:07 UTC (permalink / raw)
To: rc
After some thought, instead of hacking, I realized that all the
functionality of a function that's run on interactive startup can be
done with a prompt function. The trick is to figure out how to
recognize when you're in a new shell, and the easy way to do that is to
compare $pid against a saved version of it, so:
fn prompt { if (~ $cpid $pid) {cpid=$pid; <initialize>} }
As an extra bonus, this gets run naturally even for login shells.
This leaves the question of whether there's any use for a function
executed automatically at the start of non-interactive rc shells;
I can't think of any.
- cks
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: A startup function for interactive rc's is unnecessary
1991-08-27 19:07 A startup function for interactive rc's is unnecessary Chris Siebenmann
@ 1991-08-31 9:58 ` John Mackin
0 siblings, 0 replies; 2+ messages in thread
From: John Mackin @ 1991-08-31 9:58 UTC (permalink / raw)
To: The rc Mailing List
Chris points out the following:
After some thought, instead of hacking, I realized that all the
functionality of a function that's run on interactive startup can be
done with a prompt function. The trick is to figure out how to
recognize when you're in a new shell, and the easy way to do that is to
compare $pid against a saved version of it, so:
fn prompt { if (~ $cpid $pid) {cpid=$pid; <initialize>} }
As an extra bonus, this gets run naturally even for login shells.
There is actually an improvement on this idea, which I thought of
some weeks ago but didn't suggest on the list since I wasn't sure it
was really OK. I finally got around to asking Byron about it, and he
showed me why it is legal (my cursory inspection of the code didn't
encompass the relevant part), so: just define the prompt function to
do whatever initialisation you want to happen before the first prompt
_and then delete itself_ (or, if you still want a prompt function,
redefine itself):
fn prompt {
... initialise ...
fn prompt # or, "fn prompt { normal-prompt-func }"
}
OK,
John.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1991-08-31 10:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-08-27 19:07 A startup function for interactive rc's is unnecessary Chris Siebenmann
1991-08-31 9:58 ` John Mackin
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).