zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@sunsite.dk
Subject: Re: retrieving invocation arguments
Date: Mon, 17 Sep 2001 16:13:07 +0000	[thread overview]
Message-ID: <1010917161307.ZM5925@candle.brasslantern.com> (raw)
In-Reply-To: <20010917112344.A3210@thelonious.new.ox.ac.uk>

On Sep 17, 11:23am, Adam Spiers wrote:
}
} Currently I have
} 
}   restart () {
}       exec $SHELL "$SHELL_ARGS" "$@"
}   }
} 
} and I do
} 
}   export SHELL_ARGS="$@"
} 
} in my ~/.switch_shell (run from bash).

Ah.  Well, "$@" doesn't include the option switches even in bash, and
bash has the same behavior as zsh with respect to $0 and the first non-
option argument following a -c command.  Even if you did have the option
switches, you couldn't use them if $SHELL had changed from the original
shell.

Also, "$SHELL_ARGS" is going to be one argument where the original "$@"
may have had several.

And I should repeat the warning about `export SHELL_ARGS="$@"' -- "$@"
is an array with each element quoted, so what you've really written is

    export SHELL_ARGS="$1" "$2" "$3" ...

which is probably not what you meant.  Using "$@" works in bash because it
treats the arguments to `export' as if they were assignment expressions;
but in zsh that requires `setopt kshtypeset' (4.0.2 and later).

Anyway, it's very difficult to restart the shell exactly as it was invoked
unless you stash the arguments very early in .zshenv and have a cooperative
/etc/zshenv.  Probably the best thing would be along the lines of:

    restart_saveargs() {
	local x='(interactive|shinstdin|stdin)'
	local -a on off
	typeset -ga restart_args restart_options
	on=( ${(ok)options[(R)on]:#$~x} )
	off=( ${(ok)options[(R)off]:#$~x}} )
	restart_options=(
	    ${on:+-o} ${(j.-o .)=on}
	    ${off:++o} ${(j.+o .)=off}
	)
	restart_args=( "$@" )
    }
    restart() {
        emulate -L zsh
	if [[ $SHELL:t = zsh* ]]; then
	    exec $SHELL $restart_options $restart_args
	else
	    exec $SHELL $restart_args
	fi
    }
    restart_saveargs "$@"

And now that's probably more glorious detail than I should have included.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


  reply	other threads:[~2001-09-17 16:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-14 20:42 Adam Spiers
2001-09-15 17:34 ` Bart Schaefer
2001-09-17 10:02   ` Sweth Chandramouli
2001-09-17 11:07     ` Peter Stephenson
2001-09-17 15:17       ` Bart Schaefer
2001-09-17 15:38         ` Peter Stephenson
2001-09-17 16:06           ` Bart Schaefer
2001-09-17 20:59           ` Adam Spiers
2001-09-17 20:25             ` Sweth Chandramouli
2001-09-18 10:53               ` Adam Spiers
2001-09-17 10:23   ` Adam Spiers
2001-09-17 16:13     ` Bart Schaefer [this message]
2001-09-18 11:39       ` Adam Spiers

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=1010917161307.ZM5925@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@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).