Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the SHELL env variable to be the full path of the Elvish binary #1423

Closed
xiaq opened this issue Nov 8, 2021 · 8 comments · Fixed by #1566
Closed

Set the SHELL env variable to be the full path of the Elvish binary #1423

xiaq opened this issue Nov 8, 2021 · 8 comments · Fixed by #1566

Comments

@xiaq
Copy link
Member

xiaq commented Nov 8, 2021

No description provided.

@iandol
Copy link
Contributor

iandol commented Nov 8, 2021

❯ elvish
Elvish V0.17.0-dev.231bda61e40de5bc381f0642e26e227cc9b79e35 running on Darwin
⟨~/⟩❯ get-env SHELL
▶ /bin/zsh

@sauyon
Copy link
Contributor

sauyon commented Nov 8, 2021

Where should this be set? Inside shell.Run or maybe just main?

@krader1961
Copy link
Contributor

In general the only time a shell should set the SHELL env var is if it isn't already set.

@iandol
Copy link
Contributor

iandol commented Nov 9, 2021

I empirically confirm @krader1961 is correct. I just checked what SHELL is if run inside a bash run from zsh (which is my default shell):

❯ echo $SHELL
/bin/zsh
❯ bash
...
~▶ echo $SHELL
/bin/zsh
~▶ 

So this is consistent at least with bash. I also tested nushell, and it also doesn't change SHELL. So the question is if SHELL is set if elvish is set as the default shell?

@zzamboni
Copy link
Contributor

zzamboni commented Nov 9, 2021

After temporarily changing my login shell with chsh to /usr/local/bin/elvish:

|> echo $E:SHELL
/usr/local/bin/elvish

So it seems the value is being set correctly, to the user's login shell. Note that the SHELL environment variable is normally set by the login process, so the shell does not have to do anything. See for example http://man.openbsd.org/login.1#ENVIRONMENT (the macOS login man page says a similar thing).

@krader1961
Copy link
Contributor

Also, the SHELL env var is not meant to reflect the current shell. It is meant to reflect the shell that programs like make and vim should use when running "shell" commands if they haven't been explicitly configured to use a particular shell. That is normally the user's "login" shell which is historically expected to be at least minimally POSIX 1003.2 compliant -- which Elvish is not. This is one reason the recommended way to run Elvish is not to change your system "login" shell to Elvish.

I actually think Elvish should never explicitly set the SHELL env var. Not even if it is not present when Elvish starts. The path to the running Elvish binary should instead be exposed via a variable in the platform: namespace. The user can then choose to assign that to the SHELL env var (presumably in their ~/.config/elvish/rc.elv script) if they have decided that is appropriate for their situation. The var might be named platform:elvish-bin-path.

@ilius
Copy link

ilius commented Jan 8, 2022

In bash, sh and zsh, the argument zero $0 points to the shell executable that was run. Even though it can be the name or absolute or relative path (bash or /usr/bin/bash), but still it's useful (for example to write scripts that work in several shells, or behave differently according to shell).

But in Elvish, $args is empty by default and lacks the "argument zero".
So I suggest adding a new variable like $executable that points to Elvish executable (full path for consistency?), like Python's sys.executable.

@krader1961
Copy link
Contributor

In bash, sh and zsh, the argument zero $0 points to the shell executable that was run.

That's only true for interactive shells, those run with the -c option to execute a set of statements on the command line, and those that read statements from stdin. For shell scripts it is the path to the script. The latter case is handled by the src command in Elvish.

So I suggest adding a new variable like $executable that points to Elvish executable (full path for consistency?), like Python's sys.executable.

I don't have a strong opinion (at this time) for whether this should be exposed as builtin:executable, platform:elvish-path, or something else. But, as I said earlier, Elvish should never set E:SHELL to its path.

krader1961 added a commit to krader1961/elvish that referenced this issue Jun 26, 2022
krader1961 added a commit to krader1961/elvish that referenced this issue Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants