Skip to content

Commit 969287e

Browse files
committed
Check for ~/.hushlogin on macOS when initializing a shell
1 parent 1297cbc commit 969287e

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

alacritty_terminal/src/tty/unix.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,14 @@ impl ShellUser {
158158
}
159159

160160
#[cfg(not(target_os = "macos"))]
161-
fn default_shell_command(shell: &str, _user: &str) -> Command {
161+
fn default_shell_command(shell: &str, _user: &str, _home: &str) -> Command {
162162
Command::new(shell)
163163
}
164164

165165
#[cfg(target_os = "macos")]
166-
fn default_shell_command(shell: &str, user: &str) -> Command {
166+
fn default_shell_command(shell: &str, user: &str, home: &str) -> Command {
167+
use std::path::Path;
168+
167169
let shell_name = shell.rsplit('/').next().unwrap();
168170

169171
// On macOS, use the `login` command so the shell will appear as a tty session.
@@ -173,12 +175,20 @@ fn default_shell_command(shell: &str, user: &str) -> Command {
173175
// `login` normally does this itself, but `-l` disables this.
174176
let exec = format!("exec -a -{} {}", shell_name, shell);
175177

178+
// Since we use -l, `login` will not change directory to the user's home. However,
179+
// `login` only checks the current working directory for a .hushlogin file, causing
180+
// it to miss any in the user's home directory. We can fix this by doing the check
181+
// ourselves and passing `-q`
182+
let has_home_hushlogin = Path::new(home).join(".hushlogin").exists();
183+
176184
// -f: Bypasses authentication for the already-logged-in user.
177185
// -l: Skips changing directory to $HOME and prepending '-' to argv[0].
178186
// -p: Preserves the environment.
187+
// -q: Act as if `.hushlogin` exists.
179188
//
180189
// XXX: we use zsh here over sh due to `exec -a`.
181-
login_command.args(["-flp", user, "/bin/zsh", "-fc", &exec]);
190+
let flags = if has_home_hushlogin { "-qflp" } else { "-flp" };
191+
login_command.args([flags, user, "/bin/zsh", "-fc", &exec]);
182192
login_command
183193
}
184194

@@ -208,7 +218,11 @@ pub fn from_fd(config: &Options, window_id: u64, master: OwnedFd, slave: OwnedFd
208218
cmd.args(shell.args.as_slice());
209219
cmd
210220
} else {
221+
<<<<<<< Updated upstream
211222
default_shell_command(&user.shell, &user.user)
223+
=======
224+
default_shell_command(&user.shell, &user.user, &user.home)
225+
>>>>>>> Stashed changes
212226
};
213227

214228
// Setup child stdin/stdout/stderr as slave fd of PTY.

0 commit comments

Comments
 (0)