diff --git a/docs/changelog.md b/docs/changelog.md index f6b1dcd5b..cbbdb1d5b 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -23,6 +23,7 @@ As features stabilize some brief notes about them will accumulate here. * [wezterm.nerdfonts](config/lua/wezterm/nerdfonts.md) as a convenient way to resolve Nerd Fonts glyphs by name in your config file * [ShowLauncherArgs](config/lua/keyassignment/ShowLauncherArgs.md) key assignment to show the launcher scoped to certain items, or to launch it directly in fuzzy matching mode * Workspaces. Follow work in progress on [#1531](https://github.com/wez/wezterm/issues/1531) and [#1322](https://github.com/wez/wezterm/discussions/1322)! [window:active_workspace()](config/lua/window/active_workspace.md) [default_workspace](config/lua/config/default_workspace.md) [SwitchWorkspaceRelative](config/lua/keyassignment/SwitchWorkspaceRelative.md) +* `wezterm cli send-text "hello"` allows sending text, as though pasted, to a pane. See `wezterm cli send-text --help` for more information. [#888](https://github.com/wez/wezterm/issues/888) #### Changed diff --git a/wezterm/src/main.rs b/wezterm/src/main.rs index 3c19f5d28..cb13e01e4 100644 --- a/wezterm/src/main.rs +++ b/wezterm/src/main.rs @@ -193,6 +193,21 @@ Outputs the pane-id for the newly created pane on success" #[structopt(parse(from_os_str))] prog: Vec, }, + + /// Send text to a pane as though it were pasted. + /// If bracketed paste mode is enabled in the pane, then the + /// text will be sent as a bracketed paste. + #[structopt(name = "send-text")] + SendText { + /// Specify the target pane. + /// The default is to use the current pane based on the + /// environment variable WEZTERM_PANE. + #[structopt(long = "pane-id")] + pane_id: Option, + + /// The text to send. If omitted, will read the text from stdin. + text: Option, + }, } use termwiz::escape::osc::{ @@ -566,6 +581,33 @@ async fn run_cli_async(config: config::ConfigHandle, cli: CliCommand) -> anyhow: log::debug!("{:?}", spawned); println!("{}", spawned.pane_id); } + CliSubCommand::SendText { pane_id, text } => { + let pane_id: PaneId = match pane_id { + Some(p) => p, + None => std::env::var("WEZTERM_PANE") + .map_err(|_| { + anyhow!( + "--pane-id was not specified and $WEZTERM_PANE \ + is not set in the environment." + ) + })? + .parse()?, + }; + let data = match text { + Some(text) => text, + None => { + let mut text = String::new(); + std::io::stdin() + .read_to_string(&mut text) + .context("reading stdin")?; + text + } + }; + + client + .send_paste(codec::SendPaste { pane_id, data }) + .await?; + } CliSubCommand::SpawnCommand { cwd, prog,