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

Re: ideas, questions, and bugs

Hi All,

	I realise that this might be an old thread by now but
I've only just got back after a fortnight's holiday.

> > > As much as I try, I can't figure out a good way to have zsh execute some
> > > command at startup and stay in interactive mode.

I too have wished for this and have done some strange juggling in .zshrc
files to arrange it. However I also have a patch that makes it all simple.
Basically you can have a script like:

#! /usr/local/bin/zsh -i
# create a function which is accessible
# for use by the user.
foo () { echo bar; }
# run some start up command.
echo "Welcome!"
# modify prompt so its clear where we are.
PS1="> $PS1"
export PS1

# the user gets control here.
source /dev/tty
# clean up.
echo "Good bye"

and this this will give the user a interactive prompt half way through the
script after defining some functions, etc.. After the user quits (via exit
or ^D) the script continues.

The actual change in behaviour only occurs when the file being sourced is a tty.
Sourcing a tty is not a common thing to do I guess so the knock on
effects are limited. In fact most of the functionality is there
anyway. This just triggers the command line editing and the prompt.

I had previously asked the list about this feature and
the reply at that time was wait a bit for the code to settle down.
This patch is simpler than my original and seems to work.

Anyway here is a patch against 3.1.2.

*** ../zsh-3.0.1/Src/init.c	Thu Oct 10 07:05:11 1996
--- ./Src/init.c	Thu Dec 19 16:50:41 1996
*** 799,804 ****
--- 799,810 ----
      dosetopt(SHINSTDIN, 0, 1);
      scriptname = s;
+     /* if its a tty we are sourcing then go interactive.....*/
+     if (isatty(SHIN))
+     {
+     	dosetopt(SHINSTDIN, 1, 1); /* SHINSTDIN option     */
+     }
      loop(0);			/* loop through the file to be sourced        */


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