zsh-workers
 help / color / mirror / code / Atom feed
* interact
@ 1995-06-08 11:17 Anthony Iano-Fletcher
  0 siblings, 0 replies; 5+ messages in thread
From: Anthony Iano-Fletcher @ 1995-06-08 11:17 UTC (permalink / raw)
  To: zsh-workers


Can we make a zsh script define some functions, some varables, etc..
and then give control over to the user as a usual interactive shell
(except with those functions, etc just defined)?

This is a bit like the interact command in the expect pacakge.

At the moment I do this by setting the ZDOTDIR varaible to a
directory containing the required definitions in the .zshrc file
and then run zsh... ie.

----------------------------------
#! /bin/sh

ZDOTDIR=/what/ever/path/the/zshrc/is/in
export ZDOTDIR

# most of the work is done in the .zshrc.

# now interact with the user....
exec zsh

-------------------------------

But this is ungraceful and I'd like to do this 'properly'.

If this can't be done is there support enough for me to attempt
to add an 'interact' keyword and associated code.


			Thanks, Anthony.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: interact
  1995-06-16 12:32 interact Anthony Iano-Fletcher
@ 1995-06-16 14:49 ` P.Stephenson
  0 siblings, 0 replies; 5+ messages in thread
From: P.Stephenson @ 1995-06-16 14:49 UTC (permalink / raw)
  To: Zsh hackers list

Anthony.Iano-Fletcher@maths.nott.ac.uk wrote:
> > In principle, you could move the
> > setting of the interactive option into the code I just adapted to be
> > run both when the shell starts up and after `exec <...', which already
> > checks for a tty.  You probably have to wait a bit for that code to
> > show up.
> 
> Fine I can wait...... Would this allow for the zsh script to call for
> more that one interactive sessions? or to continue executing after
> the exec?  Surely if I do 
> 
> 		exec < /dev/tty
> 
> and the user types control-D then the shell will exit.

I looked at this a little more closely --- it turns out it's not
ksh-compatible: running ksh on a file containing

print this is before
exec <file
print this is after

shows that it doesn't change command input to stdin, only input for
'read' etc.

It might therefore be better to implement this a more specific way,
like handling `setopt interactive' specially, then passing initio() or
whatever a flag saying whether it has to switch to using stdin for
input.  This is certainly feasible, though probably it ought to wait:
it looks like being a bigger change than I'd hoped to do it properly.
If done properly, though, interactive sessions should be able to
behave just like they usually do.

-- 
Peter Stephenson <P.Stephenson@swansea.ac.uk>  Tel: +44 1792 205678 extn. 4461
WWW:  http://python.swan.ac.uk/~pypeters/      Fax: +44 1792 295324
Department of Physics, University of Wales, Swansea,
Singleton Park, Swansea, SA2 8PP, U.K.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: interact
@ 1995-06-16 12:32 Anthony Iano-Fletcher
  1995-06-16 14:49 ` interact P.Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Anthony Iano-Fletcher @ 1995-06-16 12:32 UTC (permalink / raw)
  To: zsh-workers

Hi Peter,

	Thanks for your response.

> > I recieved no response to my question about how to turn control
> > over to a user for an interactive session part way through running
> > a zsh script, in the same way that you can in the expect language.
> 
> It's currently impossible to do this properly since there's no way of
> changing the `interactive' option.  In principle, you could move the
> setting of the interactive option into the code I just adapted to be
> run both when the shell starts up and after `exec <...', which already
> checks for a tty.  You probably have to wait a bit for that code to
> show up.

Fine I can wait...... Would this allow for the zsh script to call for
more that one interactive sessions? or to continue executing after
the exec?  Surely if I do 

		exec < /dev/tty

and the user types control-D then the shell will exit.

Your message makes me realise that instead of the 2 schemes Ive
already suggested for source I should just check if the specifed file
is a terminal (using isatty) and if it is go 'interactive'. This
is an easy modification.

			Anthony.

-- 
Anthony Iano-Fletcher
e-mail:		Anthony.Iano-Fletcher@maths.nott.ac.uk
post:		Maths Dept, Uni. of Nottingham, Nottingham, NG7 2RD, UK
telephone:	(+44) (115) 951-4945


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: interact
  1995-06-15 17:17 interact Anthony Iano-Fletcher
@ 1995-06-16  9:35 ` P.Stephenson
  0 siblings, 0 replies; 5+ messages in thread
From: P.Stephenson @ 1995-06-16  9:35 UTC (permalink / raw)
  To: Zsh hackers list

Anthony.Iano-Fletcher@maths.nott.ac.uk wrote:
> I recieved no response to my question about how to turn control
> over to a user for an interactive session part way through running
> a zsh script, in the same way that you can in the expect language.

It's currently impossible to do this properly since there's no way of
changing the `interactive' option.  In principle, you could move the
setting of the interactive option into the code I just adapted to be
run both when the shell starts up and after `exec <...', which already
checks for a tty.  You probably have to wait a bit for that code to
show up.

-- 
Peter Stephenson <P.Stephenson@swansea.ac.uk>  Tel: +44 1792 205678 extn. 4461
WWW:  http://python.swan.ac.uk/~pypeters/      Fax: +44 1792 295324
Department of Physics, University of Wales, Swansea,
Singleton Park, Swansea, SA2 8PP, U.K.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* interact
@ 1995-06-15 17:17 Anthony Iano-Fletcher
  1995-06-16  9:35 ` interact P.Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Anthony Iano-Fletcher @ 1995-06-15 17:17 UTC (permalink / raw)
  To: zsh-workers



I recieved no response to my question about how to turn control
over to a user for an interactive session part way through running
a zsh script, in the same way that you can in the expect language.

Ive looked at the source and it would seem that the command

	source /dev/tty

will do most of what I want (except give a prompt and have the
zle command line editting work).

I have 2 options....

	1. special case the command 'source /dev/tty' to set the
	   options INTERACTIVE and SHINSTDIN before the tty is
	   read in the source function in utils.c. You will still
	   get the original behavour using 'source //dev/tty'.


	2. allow the source (and .) built-ins to accept a -i flag,i.e.
			source -i /dev/tty
	   to force it into a fit state for an interactive session.
	   This involves small modifications  to the source function in
	   utils.c and to the bin_dot function in builtins.c.

There is a slight variation is option 1 and that is to special case
'source /dev/xxxxx', whatever xxxxx may be. 

I have implemented both versions to try them out and Im happy with
them all. I would welcome any comments.

To put this in its historical context.... this is not the first time
that I've wished to run a script setting up various functions and
variables and then wanted to pass control to the user. I find that
my only existing solution is clumsy.

			Anthony.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1995-06-16 15:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-06-08 11:17 interact Anthony Iano-Fletcher
1995-06-15 17:17 interact Anthony Iano-Fletcher
1995-06-16  9:35 ` interact P.Stephenson
1995-06-16 12:32 interact Anthony Iano-Fletcher
1995-06-16 14:49 ` interact P.Stephenson

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).