diff --git a/docs/changelog.md b/docs/changelog.md index e7b234e6c..f4bbd3521 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -51,6 +51,7 @@ As features stabilize some brief notes about them will accumulate here. * Fixed: Numpad Enter reported as CTRL-C on macOS [#739](https://github.com/wez/wezterm/issues/739) * Fixed: mouse reporting gbutton state not cleared when focus is lost, eg: from clicking a link [#744](https://github.com/wez/wezterm/issues/744) * Improved: better looking curly underline. Thanks to [@ModProg](https://github.com/ModProg)! [#733](https://github.com/wez/wezterm/pull/733) +* Fixed: wezterm now sets argv0 to `-$SHELL` to invoke a login shell, rather than running `$SHELL -l`. [#753](https://github.com/wez/wezterm/issues/753) ### 20210405-110924-a5bb5be8 diff --git a/docs/config/launch.md b/docs/config/launch.md index cec132d71..a0695a383 100644 --- a/docs/config/launch.md +++ b/docs/config/launch.md @@ -14,6 +14,9 @@ Your shell is determined by the following rules: a login shell. A login shell generally loads additional startup files and sets up more environment than a non-login shell. +*Since: nightly builds*: instead of passing `-l` to the shell, wezterm +will spawn the shell as `-$SHELL` to invoke it as a login shell. + Note: if you have recently changed your shell using `chsh` and you have `$SHELL` set in the environment, you will need to sign out and sign back in again for the environment to pick up your new `$SHELL` diff --git a/pty/src/cmdbuilder.rs b/pty/src/cmdbuilder.rs index 9f37e00f3..83f66b490 100644 --- a/pty/src/cmdbuilder.rs +++ b/pty/src/cmdbuilder.rs @@ -131,14 +131,18 @@ impl CommandBuilder { /// Convert the CommandBuilder to a `std::process::Command` instance. pub(crate) fn as_command(&self) -> anyhow::Result { + use std::os::unix::process::CommandExt; + let mut cmd = if self.is_default_prog() { - let mut cmd = std::process::Command::new(&Self::get_shell()?); - // Run the shell as a login shell. This is a little shaky; it just - // happens to be the case that bash, zsh, fish and tcsh use -l - // to indicate that they are login shells. Ideally we'd just - // tell the command builder to prefix argv[0] with a `-`, but - // Rust doesn't support that. - cmd.arg("-l"); + let shell = Self::get_shell()?; + + let mut cmd = std::process::Command::new(&shell); + + // Run the shell as a login shell by prefixing the shell's + // basename with `-` and setting that as argv0 + let basename = shell.rsplit('/').next().unwrap_or(&shell); + cmd.arg0(&format!("-{}", basename)); + let home = Self::get_home_dir()?; let dir: &OsStr = self .cwd