Skip to content

Commit 397cfe4

Browse files
mikayla-makitmickleydoyleAnthony-Eid
committed
Add a flag for passing the -q flag to login(1)
co-authored-by: Thomas <[email protected]> co-authored-by: Anthony <[email protected]>
1 parent be911fe commit 397cfe4

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

alacritty/src/cli.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ impl From<TerminalOptions> for PtyOptions {
200200
shell: options.command().map(Into::into),
201201
drain_on_exit: options.hold,
202202
env: HashMap::new(),
203+
hush_login: false,
203204
}
204205
}
205206
}

alacritty/src/config/ui_config.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,13 @@ impl UiConfig {
130130
let shell = self.terminal.shell.clone().or_else(|| self.shell.clone()).map(Into::into);
131131
let working_directory =
132132
self.working_directory.clone().or_else(|| self.general.working_directory.clone());
133-
PtyOptions { working_directory, shell, drain_on_exit: false, env: HashMap::new() }
133+
PtyOptions {
134+
working_directory,
135+
shell,
136+
drain_on_exit: false,
137+
env: HashMap::new(),
138+
hush_login: false,
139+
}
134140
}
135141

136142
/// Generate key bindings for all keyboard hints.

alacritty_terminal/src/tty/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ pub struct Options {
3333

3434
/// Extra environment variables.
3535
pub env: HashMap<String, String>,
36+
37+
/// Controls whether to pass the -q option to `login(1)`, on macOS.
38+
pub hush_login: bool,
3639
}
3740

3841
/// Shell options.

alacritty_terminal/src/tty/unix.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ 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, _hush_login: bool) -> 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, hush_login: bool) -> Command {
167167
let shell_name = shell.rsplit('/').next().unwrap();
168168

169169
// On macOS, use the `login` command so the shell will appear as a tty session.
@@ -176,9 +176,11 @@ fn default_shell_command(shell: &str, user: &str) -> Command {
176176
// -f: Bypasses authentication for the already-logged-in user.
177177
// -l: Skips changing directory to $HOME and prepending '-' to argv[0].
178178
// -p: Preserves the environment.
179+
// -q: Act as if `.hushlogin` exists.
179180
//
180181
// XXX: we use zsh here over sh due to `exec -a`.
181-
login_command.args(["-flp", user, "/bin/zsh", "-fc", &exec]);
182+
let flags = if hush_login { "-qflp" } else { "-flp" };
183+
login_command.args([flags, user, "/bin/zsh", "-fc", &exec]);
182184
login_command
183185
}
184186

@@ -208,7 +210,7 @@ pub fn from_fd(config: &Options, window_id: u64, master: OwnedFd, slave: OwnedFd
208210
cmd.args(shell.args.as_slice());
209211
cmd
210212
} else {
211-
default_shell_command(&user.shell, &user.user)
213+
default_shell_command(&user.shell, &user.user, config.hush_login)
212214
};
213215

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

0 commit comments

Comments
 (0)