mirror of
https://github.com/alacritty/alacritty.git
synced 2025-06-16 19:02:00 -04:00
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>
This commit is contained in:
parent
be911fead8
commit
03c2907b44
3 changed files with 22 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue