Skip to content

Commit

Permalink
allow using relative cwd for wezterm cli subcommands
Browse files Browse the repository at this point in the history
refs: #1243
  • Loading branch information
wez committed Nov 14, 2021
1 parent da32968 commit f3a2e84
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ As features stabilize some brief notes about them will accumulate here.
* multiplexer: spawning remote tabs didn't correctly record local tab mapping, resulting in phantom additional tabs showing in the client. [#1222](https://github.com/wez/wezterm/issues/1222)
* `wezterm ls-fonts --text "✘"` didn't account for the system fallback list. [#849](https://github.com/wez/wezterm/issues/849)
* macOS: The `Menlo` font is now implicitly included in the system fallback list, as it is the only font that contains U+2718 ✘
* `wezterm cli spawn --cwd ..` and `wezterm cli split-pane --cwd ..` now resolve relative paths [#1243](https://github.com/wez/wezterm/issues/1243)

#### Updated and Improved

Expand Down
16 changes: 14 additions & 2 deletions wezterm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@ impl SetCwdCommand {
}
}

fn canon_cwd(cwd: Option<OsString>) -> anyhow::Result<Option<String>> {
match cwd {
None => Ok(None),
Some(cwd) => Ok(Some(
std::fs::canonicalize(cwd)?
.to_str()
.ok_or_else(|| anyhow!("path is not representable as String"))?
.to_string(),
)),
}
}

fn terminate_with_error_message(err: &str) -> ! {
log::error!("{}; terminating", err);
std::process::exit(1);
Expand Down Expand Up @@ -448,7 +460,7 @@ async fn run_cli_async(config: config::ConfigHandle, cli: CliCommand) -> anyhow:
let builder = CommandBuilder::from_argv(prog);
Some(builder)
},
command_dir: cwd.and_then(|c| c.to_str().map(|s| s.to_string())),
command_dir: canon_cwd(cwd)?,
})
.await?;

Expand Down Expand Up @@ -516,7 +528,7 @@ async fn run_cli_async(config: config::ConfigHandle, cli: CliCommand) -> anyhow:
let builder = CommandBuilder::from_argv(prog);
Some(builder)
},
command_dir: cwd.and_then(|c| c.to_str().map(|s| s.to_string())),
command_dir: canon_cwd(cwd)?,
size: config::configuration().initial_size(),
})
.await?;
Expand Down

0 comments on commit f3a2e84

Please sign in to comment.