[comp.sys.apollo] go to old directory == 'back' ??

danny@idacom.UUCP (Danny Wilson) (06/10/89)

When using the C shell, I have a handy alias that returns you to 
the directory you were just in. This involves making an alias
for 'cd' and 'back':

	alias cd   set old=$cwd; chdir !*
	alias back set back=$old; set old=$cwd; cd $back; unset back; dirs

I thought this would be a great function for the Aegis shell. I made
the following shell scripts:

file: wd
	eon
	if eqs ^1 "" then
		/com/wd		# no parameters, just print where we are
		return
	endif
	old := ^"/com/wd" 
	export old
	/com/wd ^1

file: back
	eon
	back := ^old
	old := ^"/com/wd"
	/com/wd ^back
	dlvar back
	/com/wd

However, because the variable 'old' gets set at a lower shell level it
is undefined within program 'back'. Has anyone got a solution for
a (seemingly) easy problem like this?


-- 
Danny Wilson
IDACOM Electronics		danny@idacom.uucp
Edmonton, Alberta		alberta!idacom!danny
C A N A D A

GBOPOLY1@NUSVM.BITNET (fclim) (06/28/89)

>Date: 9 Jun 89 22:01:09 GMT
>From: danny%idacom%alberta%att.uucp@ucbvax.Berkeley.EDU  (Danny Wilson)
>Organization: IDACOM Electronics Ltd., Edmonton, Alta.
>Subject: go to old directory == 'back' ??
>Message-Id: <678@idacom.UUCP>
>
>When using the C shell, I have a handy alias that returns you to
>the directory you were just in. This involves making an alias
>for 'cd' and 'back':
>
>    alias cd   set old=$cwd; chdir !*
>    alias back set back=$old; set old=$cwd; cd $back; unset back; dirs
>

A better method (since you're using csh) is to use pushd.  This is faster
'cos it's a built-in function of csh.

         % pwd
         foo
         % pushd bar
         bar foo
         % pwd
         bar
         % pushd
         foo bar
         % pwd
         foo
         % pushd
         bar foo
         % pwd
         bar

You could pushd-ed more directories onto the stack internal to csh.  Use
"dirs" to list the stack.  Use "pushd <n>" to move the nth entry to the
top of the stack.

>I thought this would be a great function for the Aegis shell. I made
>the following shell scripts:
>(/com/sh scripts deleted)  (no square brackets on my keyboard -- fclim)
>
>However, because the variable 'old' gets set at a lower shell level it
>is undefined within program 'back'. Has anyone got a solution for
>a (seemingly) easy problem like this?

I was thinking of implementing pushd/popd/dirs for Aegis users but have
not get round to it.  I was thinking of using paste_buffers.
(This is one way of passing global info).  Has anyone done so yet?

>Danny Wilson
>IDACOM Electronics        danny@idacom.uucp
>Edmonton, Alberta        alberta!idacom!danny
>C A N A D A

fclim          --- gbopoly1 % nusvm.bitnet @ cunyvm.cuny.edu
computer centre
singapore polytechnic
dover road
singapore 0513.

lori@hacgate.scg.hac.com (Lori Barfield) (06/29/89)

In article <678@idacom.UUCP>, danny@idacom.UUCP (Danny Wilson) writes:
> 
> However, because the variable 'old' gets set at a lower shell level it
> is undefined within program 'back'. Has anyone got a solution for
> a (seemingly) easy problem like this?

You can export the variable in ~user_data/sh/startup.
Try a script with x:='hello'; export x; then at the prompt do a lvar.
See what I mean?

(I'm writing off the top of my head now, so if the syntax here is goofy
send me email.  I just thought you waited long enough for such a simple
answer.)

You may also want to know about a command called "source".
If you invoke an Aegis script with source, it's the same as including
that code in the calling file:  Variable declarations and settings will
belong to the calling script.  (syntax:  source FILENAME
				instead of just FILENAME to invoke)

The third option is to use DM buffers.  Don't use the unnamed buffer;
users depend on that one if you use any of the std_keys key definitions
files without modifications.  I won't go into details here; it's easy
if you are familiar with DM scripting.  (If you aren't and you decide
to use this approach, you are welcome to email me.)



...lori

ARPA: lori@hacgate.scg.hac.com

nazgul@apollo.COM (Kee Hinckley) (07/04/89)

In article <678@idacom.UUCP> danny@idacom.UUCP (Danny Wilson) writes:
>I thought this would be a great function for the Aegis shell. I made
>the following shell scripts:
>
>file: wd
>	eon
>	if eqs ^1 "" then
>		/com/wd		# no parameters, just print where we are
>		return
>	endif
>	old := ^"/com/wd" 
>	export old
>	/com/wd ^1
>
>file: back
>	eon
>	back := ^old
>	old := ^"/com/wd"
>	/com/wd ^back
>	dlvar back
>	/com/wd
>
>However, because the variable 'old' gets set at a lower shell level it
>is undefined within program 'back'. Has anyone got a solution for
>a (seemingly) easy problem like this?

First of all you should probably stop using /com/wd, and just use wd.
wd is a builtin at SR10 (one program per process and all that).  The version
in /com is a shell script, so it will still work, it's just slower.

Now for the problem.  There is no way to have a shell script change
a variable above it unless you "source" the shell script.  To do what
you want I think the best solution would be:

wd:
    #!/com/sh
    eon
    if eqs ^1 "" then
	wd
    else
	wd > ^HOME/.olddir
	wd ^1
    endif
back:
    #!/com/sh
    eon
    read back < ^HOME/.olddir
    wd > ^HOME/.olddir
    wd ^back

Note that I haven't tested this!

						    -kee
-- 
### User Environment, Apollo Computer Inc. ###  Public Access ProLine BBS   ###
###     {mit-eddie,yale}!apollo!nazgul     ###  nazgul@pro-angmar.cts.com   ###
###           nazgul@apollo.com            ### (617) 641-3722 300/1200/2400 ###
I'm not sure which upsets me more; that people are so unwilling to accept      responsibility for their own actions, or that they are so eager to regulate   everyone else's.