1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-22 22:42:48 +03:00

use -$SHELL rather than $SHELL -l to trigger a login shell

Since the original code was written, Rust grew and stabilized
an interface for specifying argv0 for the child process, so
we can remove the fragile `-l` argument passing.

refs: https://github.com/wez/wezterm/issues/753
This commit is contained in:
Wez Furlong 2021-05-01 07:31:35 -07:00
parent 49b0ef2356
commit bc0766396d
3 changed files with 15 additions and 7 deletions

View File

@ -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

View File

@ -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`

View File

@ -131,14 +131,18 @@ impl CommandBuilder {
/// Convert the CommandBuilder to a `std::process::Command` instance.
pub(crate) fn as_command(&self) -> anyhow::Result<std::process::Command> {
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