add wezterm shell-completion subcommand to generate shell completions

This commit is contained in:
Wez Furlong committed 2022-05-28 07:43:28 -07:00
1 parent f857ec6a5a
commit 80caba1db3
3 files changed
+28 -1

No files matched your search

Generated
+10
View File
@@ -540,6 +540,15 @@ dependencies = [
"textwrap",
]
[[package]]
name = "clap_complete"
version = "3.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da92e6facd8d73c22745a5d3cbb59bdf8e46e3235c923e516527d8e81eec14a4"
dependencies = [
"clap",
]
[[package]]
name = "clap_derive"
version = "3.1.18"
@@ -4630,6 +4639,7 @@ dependencies = [
"anyhow",
"chrono",
"clap",
"clap_complete",
"codec",
"config",
"env-bootstrap",
+2 -1
View File
@@ -12,6 +12,8 @@ anyhow = "1.0"
[dependencies]
anyhow = "1.0"
chrono = "0.4"
clap = {version="3.1", features=["derive"]}
clap_complete = "3.1"
codec = { path = "../codec" }
config = { path = "../config" }
env-bootstrap = { path = "../env-bootstrap" }
@@ -26,7 +28,6 @@ serde = {version="1.0", features = ["derive"]}
serde_json = "1.0"
shell-words = "1.1"
smol = "1.2"
clap = {version="3.1", features=["derive"]}
tabout = { path = "../tabout" }
tempfile = "3.3"
termwiz = { path = "../termwiz" }
+16
View File
@@ -1,6 +1,7 @@
use anyhow::{anyhow, Context};
use chrono::{DateTime, Utc};
use clap::Parser;
use clap_complete::{generate as generate_completion, Shell};
use config::keyassignment::SpawnTabDomain;
use config::wezterm_version;
use mux::activity::Activity;
@@ -91,6 +92,14 @@ enum SubCommand {
#[clap(name = "replay", about = "Replay an asciicast terminal session")]
Replay(asciicast::PlayCommand),
/// Generate shell completion information
#[clap(name = "shell-completion")]
ShellCompletion {
/// Which shell to generate for
#[clap(long, possible_values=["bash", "elvish", "fish", "powershell", "zsh"])]
shell: Shell,
},
}
#[derive(Debug, Parser, Clone)]
@@ -469,6 +478,13 @@ fn run() -> anyhow::Result<()> {
SubCommand::Cli(cli) => run_cli(config, cli),
SubCommand::Record(cmd) => cmd.run(config),
SubCommand::Replay(cmd) => cmd.run(),
SubCommand::ShellCompletion { shell } => {
use clap::CommandFactory;
let mut cmd = Opt::command();
let name = cmd.get_name().to_string();
generate_completion(shell, &mut cmd, name, &mut std::io::stdout());
Ok(())
}
}
}