-
-
Notifications
You must be signed in to change notification settings - Fork 301
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
Add a script file executed when Elvish is invoked as login shell #1841
Comments
FWIW, I am a strong thumbs down on adding this feature. See my comments in #316 and #1726. Mostly because the concept of a "login" shell is fuzzy. In the distant past, when I started programming in the 1970's, a "login" shell was the program launched by the The main problem is that the concept of a "login" shell is now far too vague to be useful. Even when its meaning was clearer its use by shells like the Korn shell and Bash was a constant source of problems. Which caused most users to put everything in their ~/.kshrc or ~/.bashrc and never bother with ~/.bash_login, ~/.profile, or equivalent. Which is a good reason not to add that "feature" to Elvish. I have a ~/.config/elvish/lib/env.elv module that I If you are relying on env vars being set by a file such as /etc/environment or /etc/environment.d/.conf* those are already set by whatever programs launched your Elvish shell. All you need to do is test whether the relevant env var is already set before setting a default value in your ~/.config/elvish/lib/env.elv module. |
Respectfully, I think I described one case where it is currently useful: setting up environment variables for all programs launched in user session. Including non-terminal programs, so I can't just I'm not saying a "login shell" is a good concept, but it's the one Linux world is stuck with, because it's been around forever, and no one can agree on a replacement standard, so it is what it is. Regarding usage of If Elvish makes an opinionated decision to not support the login shell concept, that's fine, but I think then it should not advertise setting itself as the login shell in https://elv.sh/get/default-shell.html#changing-your-login-shell |
I tend to agree that this is a bad idea, but I am willing to admit that the option of knowing whether you have a “login” shell could be useful to some. So I suggest a compromise: Make the shell's Document it with a minimum of fanfare, not to lead users astray. And who knows, some intrepid users might find other uses for this? |
I want to re-clarify that this issue isn't about detecting if you're in a login shell (#1726). Detecting if you're in a login shell is pointless, because elvish does not execute This issue is about possibly introducing a script file separate from |
Oh, I see. Or rather, I don't. I had no idea such a thing as a non-interactive login shell could even exist. |
Non-interactive login shells generally happen when you do a graphical login. While it's certainly possible to do a graphical login without a login shell (in Wayland at least), they usually are invoked, since login shells have been the only way to set up user environment variables sice forever, and there's no agreed-on alternative so far. |
From the Bash man page:
Legacy shells like Bash and Ksh have extremely problematic behavior with regard to the login option. If you have a ~/.profile and at a later date create a ~/.bash_login your ~/.profile is silently ignored. Elvish doesn't have to suffer the same problem but adding more files that are magically sourced when Elvish starts is likely to cause problems sooner or later. Sooner if you ask what happens if you start an interactive "login" Elvish shell. Does it source both ~/.config/elvish/rc.elv and ~/.config/elvish/login.elv? In which order does it source those files? What happens when they perform incompatible initializations? Support for Note that Elvish does not support the @mkalinski You wrote:
That is not a simple example; or, at least, lacks sufficient detail to understand what you attempted. If you provide more details about your system and how you attempted to replace a POSIX shell (e.g., Bash) with Elvish in your "graphical environment" we can provide better feedback. Including possibly agreeing that Elvish should support the |
The docs only say:
It doesn't say anything about "interactive", nor does it define what a "login shell" is, but all I can say is that all other Unix-y shells that I know of support some way of executing a script at login, so I think this is a natural expectation, when the docs lack any further explanation.
I'm not sure if any concrete details I can provide will be very useful, but sure. I'm normally logging in via GNOME desktop environment on Wayland. It does start the session within a login shell. I have a directory, if status is-login
fish_add_path -gP ~/.local/bin
end This prepends the directory to I have a script in If I didn't add This is just one case. I have more scripts in that directory, that I have to reference in other places in GUI applications. I also use other exported variables from login shell, but I wanted to focus in this example on what I think is the most common reason for people to have login scripts: extending |
@krader1961 Please don't be combative in the issue tracker. The Elvish community is about helping people do what they want to do with Elvish, not about proving that one way is better than another. (This is a formal warning from me as the moderator.) |
@mkalinski It would be useful to know how exactly the GNOME session invokes Elvish. Since it's not an interactive session, it must be either passing commands via Can you find the full command line of Elvish invocation made by the GNOME session? For example, if you run |
See https://www.reddit.com/r/linuxquestions/comments/1dd9xwi/why_does_gnomesession_wayland_start_a_login_shell/ for an explanation why Elvish is not a good fit as a "login" shell In the context of the Gnome Wayland ecosystem. The short version is the Gnome Wayland desktop environment assumes it can reinvoke the users default shell as a "login" shell (by prefacing the path to the user's default shell with a hyphen in the argv[0] value passed to the shell) for the side-effect of causing the shell to evaluate the relevant startup scripts (e.g., ~/.bash_login) before the shell enters its non-interactive REPL loop. This caused me to notice that Elvish has a related, but unexpected, behavior. Compare the behavior of Bash and Elvish:
I don't see any alternative but to implement support, more or less as proposed by @mkalinski, if Elvish is intended to be usable as the users "default" shell as defined by their user profile. I never noticed this shortcoming because I either did not set Elvish as my default shell, or when I did so I didn't use it in a manner that depended on side-effects of it being run as a "login" shell. I would also recommend exposing the argv[0] string via an Elvish builtin var. |
There are obviously many questions related to adding support for Elvish as a "login" shell. Starting with whether it should support the P.S., This is the /etc/profile content on my primary macOS server:
Using Elvish as a "login" shell would mean it has to duplicate whatever |
I'll also note that my "Mostly because the concept of a "login" shell is fuzzy." comment was ill advised. In the context of this issue a "login" shell is not fuzzy. Specifically, it means a program invoked with a |
I can show you how exactly it looks in exec bash -c "exec -l '$SHELL' -c '$0 -l $*'" This convoluted invocation means that, if
Bash's
I concede that setting a non-POSIX shell as the login shell can lead to unexpected problems, since there can always be applications that assume that
This ship has already sailed, when Elvish docs already show how to set it as the login shell, which already leads to incompatibilities. My primary inspiration for this proposal is the fish shell, which has a completely non-POSIX configuration files hierarchy and seems to get away with it. I've been using it as a login shell for years and never had any issue. Regarding files like Out of curiosity I checked, and on my own system, |
Hmm OK. Elvish does support I took a look at that script from gnome-session - this is the full source I believe and it's doing some quite convoluted things... But it is what it is, @mkalinski thanks for the analysis. I see that there's no way to make this work short of implementing your original proposal of executing a I'm thinking doing this in a slightly unusual way: execute set E:FOO = bar
fn lorem { ... } And if you run This is to ensure that script executed as |
What new feature should Elvish have?
I think Elvish should provide a script file, let's call it
~/.config/elvish/login.elv
, that's executed when Elvish is invoked as login shell.This was touched on in issues #316 and #1726, but I decided to open a new issue to point to what exactly I think is the problem, since the older issues are kind of muddled.
The reason why I think this is necessary, is because Linux is still, unfortunately, lacking a good way to set up environment variables for user session, that doesn't depend on the concept of a login shell (which is also an answer for this comment).
There is
environment.d
for systems that utilizesystemd
, but the wording in the man page seems purposefully vague on whether it will always set up the environment for all programs when you log in. It doesn't set up environment for the user session, but for "any services started by [the] service manager". Besides, the syntax supported is very limited compared to shells that provide utilities to ex. more easily handle$PATH
.Other than that, using a login shell that executes a script like
~/.profile
seems to be the only reliable way to set up the environment of the user session in Linux land.And by "environment of the user session" I don't mean "all shells started by the user", but "all programs of any kind started by the user".
One simple example: consider that a graphical environment may provide an option to set up a global keyboard shortcut to launch some command. Without being able to extend
$PATH
during login, so that the graphical environment inherits the value, all paths to custom user scripts would need to be typed out in full.Elvish says that it can be set up as login shell, but as it is now it's pretty pointless, since Elvish doesn't perform the primary function of a login shell, which is to set up the environment for all programs launched within the user session.
Output of "elvish -version"
0.21.0
Code of Conduct
The text was updated successfully, but these errors were encountered: