aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikayla Maki <mikayla.c.maki@gmail.com>2025-02-19 18:12:29 -0800
committerGitHub <noreply@github.com>2025-02-20 02:12:29 +0000
commit03c2907b44b4189aac5fdeaea331f5aab5c7072e (patch)
tree918fcfee7254d65025a8673ffd121a5acc88610f
parentbe911fead8b568797862ebfd41bbad32b46d42bf (diff)
downloadr-alacritty-03c2907b44b4189aac5fdeaea331f5aab5c7072e.tar.gz
r-alacritty-03c2907b44b4189aac5fdeaea331f5aab5c7072e.tar.bz2
r-alacritty-03c2907b44b4189aac5fdeaea331f5aab5c7072e.zip
Hide macOS login message with ~/.hushlogin present
On macOS every shell is a login shell, which will always print information about the last login when the terminal is started. The macOS standard for disabling this is to place a `.hushlogin` file in the user's home directory, but this did not work with Alacritty since `login` only looks for this file in the current directory. To ensure the login message is properly suppressed, Alacritty's default shell will now check for the presence of the `.hushlogin` file in the user's home directory and append `-q` to the `login` arguments if it is present, which will behave as if a `.hushlogin` file was found by `login`. Co-authored-by: Thomas <thomas@zed.dev> Co-authored-by: Anthony <anthony@zed.dev>
-rw-r--r--CHANGELOG.md4
-rw-r--r--alacritty_terminal/CHANGELOG.md4
-rw-r--r--alacritty_terminal/src/tty/unix.rs18
3 files changed, 22 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 49984568..cf13eb7a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,10 @@ Notable changes to the `alacritty_terminal` crate are documented in its
## 0.16.0-dev
+### Changed
+
+- Hide login message if `~/.hushlogin` is present
+
### Fixed
- Crash when OpenGL context resets
diff --git a/alacritty_terminal/CHANGELOG.md b/alacritty_terminal/CHANGELOG.md
index 90f300f7..9b2f9ebf 100644
--- a/alacritty_terminal/CHANGELOG.md
+++ b/alacritty_terminal/CHANGELOG.md
@@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## 0.25.1-dev
+### Changed
+
+- Pass `-q` to `login` on macOS if `~/.hushlogin` is present
+
## 0.25.0
### Changed
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs
index e3db51fb..884cb5c1 100644
--- a/alacritty_terminal/src/tty/unix.rs
+++ b/alacritty_terminal/src/tty/unix.rs
@@ -8,6 +8,8 @@ use std::os::fd::OwnedFd;
use std::os::unix::io::AsRawFd;
use std::os::unix::net::UnixStream;
use std::os::unix::process::CommandExt;
+#[cfg(target_os = "macos")]
+use std::path::Path;
use std::process::{Child, Command};
use std::sync::Arc;
use std::{env, ptr};
@@ -158,12 +160,12 @@ impl ShellUser {
}
#[cfg(not(target_os = "macos"))]
-fn default_shell_command(shell: &str, _user: &str) -> Command {
+fn default_shell_command(shell: &str, _user: &str, _home: &str) -> Command {
Command::new(shell)
}
#[cfg(target_os = "macos")]
-fn default_shell_command(shell: &str, user: &str) -> Command {
+fn default_shell_command(shell: &str, user: &str, home: &str) -> Command {
let shell_name = shell.rsplit('/').next().unwrap();
// 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 {
// `login` normally does this itself, but `-l` disables this.
let exec = format!("exec -a -{} {}", shell_name, shell);
+ // Since we use -l, `login` will not change directory to the user's home. However,
+ // `login` only checks the current working directory for a .hushlogin file, causing
+ // it to miss any in the user's home directory. We can fix this by doing the check
+ // ourselves and passing `-q`
+ let has_home_hushlogin = Path::new(home).join(".hushlogin").exists();
+
// -f: Bypasses authentication for the already-logged-in user.
// -l: Skips changing directory to $HOME and prepending '-' to argv[0].
// -p: Preserves the environment.
+ // -q: Act as if `.hushlogin` exists.
//
// XXX: we use zsh here over sh due to `exec -a`.
- login_command.args(["-flp", user, "/bin/zsh", "-fc", &exec]);
+ let flags = if has_home_hushlogin { "-qflp" } else { "-flp" };
+ login_command.args([flags, user, "/bin/zsh", "-fc", &exec]);
login_command
}
@@ -208,7 +218,7 @@ pub fn from_fd(config: &Options, window_id: u64, master: OwnedFd, slave: OwnedFd
cmd.args(shell.args.as_slice());
cmd
} else {
- default_shell_command(&user.shell, &user.user)
+ default_shell_command(&user.shell, &user.user, &user.home)
};
// Setup child stdin/stdout/stderr as slave fd of PTY.