Repository: alacritty/alacritty (language: rust)

Issue:
ZSH pollutes environment on macOS even with `$SHELL` set to `bash`
With `$SHELL` set to `/bin/bash` `~/.zshenv` still seems to get run, which is not really great. This is a result of the choice to execute the shell in a [very roundabout way](https://github.com/alacritty/alacritty/blob/d4f2f8577f763df059653dfab733dfe6ddc06913/alacritty_terminal/src/tty/unix.rs#L179) through `zsh -c` by default. Is this really necessary? Wouldn't `/usr/bin/login -fp $user $SHELL` be sufficient as we seem to counteract the `-l` immediately using an `exec -a` anyway.

If that doesn't work for some reason I can't foresee, perhaps zsh should be executed with `-f`/`--no-rcs`

### System

OS: macOS
Version: `alacritty 0.13.2 (bb8ea18)`


Discussion / hints:
I took a quick look at the git blame and it seems the `-l` is needed to keep the current directory. I guess passing `-f` to zsh is the way to go.
This has nothing to do with alacritty, I recommend playing with your shell until it behaves as expected.
> This has nothing to do with alacritty, I recommend playing with your shell until it behaves as expected.

I respectfully disagree. This has something to do with alacritty as alacritty's choice to invoke the user login shell through zsh is what pollutes the environment. It's not expected behaviour that your terminal emulator runs an extra shell. Especially a shell that is not the login shell you picked with no recourse but to fork and compile your own.
That’s not alacritty doing that, I believe this was a choice macOS made recently. Feel free to change your shell invocation in the alacritty config to get around it though, or write your own wrapper shell as your default shell.
I even linked the line where alacritty starts the login shell through `zsh -c` how is that a choice by macOS? The only reason alacritty uses `zsh` there seems to be the fact that it needs `exec -a`. `zsh -fc` would be the correct way to abuse `zsh` there without polluting the environment.
Apologies. I forgot all about that logic and was assuming that something changed when macOS defaulted to ZSH somewhat recently.
@Learath2 perhaps reading over #6426 will shed some light on this issue. I vaguely recall being a bit confused about this myself a while ago now that I’m thinking more about it. Though I assume you have at this point.
So now I'm curious and I'm trying running the suggested change here:

```diff
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs
index a4b07b74..d559a4e4 100644
--- a/alacritty_terminal/src/tty/unix.rs
+++ b/alacritty_terminal/src/tty/unix.rs
@@ -162,21 +162,12 @@ fn default_shell_command(shell: &str, _user: &str) -> Command {
 
 #[cfg(target_os = "macos")]
 fn default_shell_command(shell: &str, user: &str) -> Command {
-    let shell_name = shell.rsplit('/').next().unwrap();
-
     // On macOS, use the `login` command so the shell will appear as a tty session.
     let mut login_command = Command::new("/usr/bin/login");
 
-    // Exec the shell with argv[0] prepended by '-' so it becomes a login shell.
-    // `login` normally does this itself, but `-l` disables this.
-    let exec = format!("exec -a -{} {}", shell_name, shell);
-
     // -f: Bypasses authentication for the already-logged-in user.
-    // -l: Skips changing directory to $HOME and prepending '-' to argv[0].
     // -p: Preserves the environment.
-    //
-    // XXX: we use zsh here over sh due to `exec -a`.
-    login_command.args(["-flp", user, "/bin/zsh", "-c", &exec]);
+    login_command.args(["-fp", user, shell]);
     login_command
 }
 ```

Seems to work for me, so I'm not sure why things are as they are. Also, it's worth noting that having your `shell.program` set to something without the `login` call also results in a terminal without a registered session, which I suspect many people have. I don't honestly know what the consequences of not being a registered session are, but all my alacritty instances don't show up when I call `who`.

Hope this helps a bit.
You can look into the `git history` to figure out why the changes are like that, but most likely because of some macOS bug.

PR that added that is also relatively new thing.

Also, none of that triggers if you run the command on your own iirc.
It just surprised me that all this special logic is skipped if you choose your own shell in the config. Shouldn’t it be applied to custom shells too?
Careful. Removing the `-l` isn't correct. It'll switch directories to home. I'm running with `-f` added to the zsh invocation, and that has been working fine for me, albeit only tested for a week or so.

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5ae7ffb8885..a30d61966f0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ Notable changes to the `alacritty_terminal` crate are documented in its
 
 - Pressing `Alt` with unicode input will now add `ESC` like for ASCII input
 - Decorations use opaque style and system window background on macOS
+- No longer source `~/.zshenv` on macOS
 
 ### Fixed
 
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs
index 54118a58c09..1336fd04364 100644
--- a/alacritty_terminal/src/tty/unix.rs
+++ b/alacritty_terminal/src/tty/unix.rs
@@ -177,7 +177,7 @@ fn default_shell_command(shell: &str, user: &str) -> Command {
     // -p: Preserves the environment.
     //
     // XXX: we use zsh here over sh due to `exec -a`.
-    login_command.args(["-flp", user, "/bin/zsh", "-c", &exec]);
+    login_command.args(["-flp", user, "/bin/zsh", "-fc", &exec]);
     login_command
 }
 


Test patch: