fixup split behavior with default_prog
https://github.com/wezterm/wezterm/pull/6850 changed the behavior of spawning in such a way that if you had a default_prog and split a pane, the default_prog you had set would not take effect. This is because a later normalization stage would skip applying resolving/applying the default_prog because it thought that the command builder was already fully baked. This commit allows that fixup logic to reason about the configured default_prog (which may be different in a WSL context!) and fixup the builder. This is an alternative approach to resolving https://github.com/wezterm/wezterm/issues/6955 for which a patch was proprosed in https://github.com/wezterm/wezterm/pull/6972. That PR wouldn't be quite right because the underlying logic could consider the default_prog from a domain-specific source, rather than the global configuration.
This commit is contained in:
4 files changed
+45
-16
No files matched your search
+13
-2
@@ -1538,18 +1538,29 @@ impl Config {
|
||||
}
|
||||
};
|
||||
|
||||
self.apply_cmd_defaults(&mut cmd, default_cwd);
|
||||
self.apply_cmd_defaults(&mut cmd, None, default_cwd);
|
||||
|
||||
Ok(cmd)
|
||||
}
|
||||
|
||||
pub fn apply_cmd_defaults(&self, cmd: &mut CommandBuilder, default_cwd: Option<&PathBuf>) {
|
||||
pub fn apply_cmd_defaults(
|
||||
&self,
|
||||
cmd: &mut CommandBuilder,
|
||||
default_prog: Option<&Vec<String>>,
|
||||
default_cwd: Option<&PathBuf>,
|
||||
) {
|
||||
// Apply `default_cwd` only if `cwd` is not already set, allows `--cwd`
|
||||
// option to take precedence
|
||||
if let (None, Some(cwd)) = (cmd.get_cwd(), default_cwd) {
|
||||
cmd.cwd(cwd);
|
||||
}
|
||||
|
||||
if let Some(default_prog) = default_prog {
|
||||
if cmd.is_default_prog() {
|
||||
cmd.replace_default_prog(default_prog);
|
||||
}
|
||||
}
|
||||
|
||||
// Augment WSLENV so that TERM related environment propagates
|
||||
// across the win32/wsl boundary
|
||||
let mut wsl_env = std::env::var("WSLENV").ok();
|
||||
|
||||
+15
-13
@@ -453,23 +453,25 @@ impl LocalDomain {
|
||||
pane_id: PaneId,
|
||||
) -> anyhow::Result<CommandBuilder> {
|
||||
let config = configuration();
|
||||
|
||||
let wsl = self.resolve_wsl_domain();
|
||||
let default_prog = wsl
|
||||
.as_ref()
|
||||
.map(|wsl| wsl.default_prog.as_ref())
|
||||
.unwrap_or(config.default_prog.as_ref());
|
||||
|
||||
let mut cmd = match command {
|
||||
Some(mut cmd) => {
|
||||
config.apply_cmd_defaults(&mut cmd, config.default_cwd.as_ref());
|
||||
config.apply_cmd_defaults(&mut cmd, default_prog, config.default_cwd.as_ref());
|
||||
cmd
|
||||
}
|
||||
None => {
|
||||
let wsl = self.resolve_wsl_domain();
|
||||
config.build_prog(
|
||||
None,
|
||||
wsl.as_ref()
|
||||
.map(|wsl| wsl.default_prog.as_ref())
|
||||
.unwrap_or(config.default_prog.as_ref()),
|
||||
wsl.as_ref()
|
||||
.map(|wsl| wsl.default_cwd.as_ref())
|
||||
.unwrap_or(config.default_cwd.as_ref()),
|
||||
)?
|
||||
}
|
||||
None => config.build_prog(
|
||||
None,
|
||||
default_prog,
|
||||
wsl.as_ref()
|
||||
.map(|wsl| wsl.default_cwd.as_ref())
|
||||
.unwrap_or(config.default_cwd.as_ref()),
|
||||
)?,
|
||||
};
|
||||
if let Some(dir) = command_dir {
|
||||
cmd.cwd(dir);
|
||||
|
||||
+1
-1
@@ -253,7 +253,7 @@ impl RemoteSshDomain {
|
||||
let config = config::configuration();
|
||||
let cmd = match command {
|
||||
Some(mut cmd) => {
|
||||
config.apply_cmd_defaults(&mut cmd, None);
|
||||
config.apply_cmd_defaults(&mut cmd, self.dom.default_prog.as_ref(), None);
|
||||
cmd
|
||||
}
|
||||
None => config.build_prog(None, self.dom.default_prog.as_ref(), None)?,
|
||||
|
||||
@@ -276,6 +276,22 @@ impl CommandBuilder {
|
||||
self.args.push(arg.as_ref().to_owned());
|
||||
}
|
||||
|
||||
/// If a builder is_default_prog, then this function can be used to
|
||||
/// set the actual prog that should be used.
|
||||
/// This is intended to facilitate plumbing through the handling
|
||||
/// of the underlying default prog when merging together supplemental
|
||||
/// env and cwd information.
|
||||
/// You will not typically use this method in your own code.
|
||||
pub fn replace_default_prog(&mut self, args: impl IntoIterator<Item = impl AsRef<OsStr>>) {
|
||||
if !self.is_default_prog() {
|
||||
panic!("attempted to replace_default_prog on a non-default_prog builder");
|
||||
}
|
||||
|
||||
for arg in args {
|
||||
self.args.push(arg.as_ref().to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
/// Append a sequence of arguments to the current command line
|
||||
pub fn args<I, S>(&mut self, args: I)
|
||||
where
|
||||
|
||||
Reference in new issue
Block a user