Add wezterm cli send-text command

refs: #888
This commit is contained in:
Wez Furlong committed 2022-01-17 10:23:22 -07:00
1 parent db8f588c5e
commit b6d121dd52
2 files changed
+43

No files matched your search

+1
View File
@@ -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
+42
View File
@@ -193,6 +193,21 @@ Outputs the pane-id for the newly created pane on success"
#[structopt(parse(from_os_str))]
prog: Vec<OsString>,
},
/// 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<PaneId>,
/// The text to send. If omitted, will read the text from stdin.
text: Option<String>,
},
}
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,