mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 21:32:13 +03:00
Add fig
to shells for shell completion
This commit is contained in:
parent
f4b8028e5e
commit
f792a20f7a
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -538,6 +538,16 @@ dependencies = [
|
||||
"clap 3.2.17",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete_fig"
|
||||
version = "3.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed37b4c0c1214673eba6ad8ea31666626bf72be98ffb323067d973c48b4964b9"
|
||||
dependencies = [
|
||||
"clap 3.2.17",
|
||||
"clap_complete",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "3.2.17"
|
||||
@ -5253,6 +5263,7 @@ dependencies = [
|
||||
"chrono",
|
||||
"clap 3.2.17",
|
||||
"clap_complete",
|
||||
"clap_complete_fig",
|
||||
"codec",
|
||||
"config",
|
||||
"env-bootstrap",
|
||||
|
@ -14,6 +14,7 @@ anyhow = "1.0"
|
||||
chrono = "0.4"
|
||||
clap = {version="3.1", features=["derive"]}
|
||||
clap_complete = "3.1"
|
||||
clap_complete_fig = "3.2"
|
||||
codec = { path = "../codec" }
|
||||
config = { path = "../config" }
|
||||
env-bootstrap = { path = "../env-bootstrap" }
|
||||
|
@ -1,7 +1,7 @@
|
||||
use anyhow::{anyhow, Context};
|
||||
use chrono::{DateTime, Utc};
|
||||
use clap::{Parser, ValueHint};
|
||||
use clap_complete::{generate as generate_completion, Shell};
|
||||
use clap::{Parser, ValueEnum, ValueHint};
|
||||
use clap_complete::{generate as generate_completion, shells, Generator as CompletionGenerator};
|
||||
use config::keyassignment::SpawnTabDomain;
|
||||
use config::wezterm_version;
|
||||
use mux::activity::Activity;
|
||||
@ -56,6 +56,40 @@ struct Opt {
|
||||
cmd: Option<SubCommand>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, ValueEnum)]
|
||||
enum Shell {
|
||||
Bash,
|
||||
Elvish,
|
||||
Fish,
|
||||
PowerShell,
|
||||
Zsh,
|
||||
Fig,
|
||||
}
|
||||
|
||||
impl CompletionGenerator for Shell {
|
||||
fn file_name(&self, name: &str) -> String {
|
||||
match self {
|
||||
Shell::Bash => shells::Bash.file_name(name),
|
||||
Shell::Elvish => shells::Elvish.file_name(name),
|
||||
Shell::Fish => shells::Fish.file_name(name),
|
||||
Shell::PowerShell => shells::PowerShell.file_name(name),
|
||||
Shell::Zsh => shells::Zsh.file_name(name),
|
||||
Shell::Fig => clap_complete_fig::Fig.file_name(name),
|
||||
}
|
||||
}
|
||||
|
||||
fn generate(&self, cmd: &clap::Command, buf: &mut dyn std::io::Write) {
|
||||
match self {
|
||||
Shell::Bash => shells::Bash.generate(cmd, buf),
|
||||
Shell::Elvish => shells::Elvish.generate(cmd, buf),
|
||||
Shell::Fish => shells::Fish.generate(cmd, buf),
|
||||
Shell::PowerShell => shells::PowerShell.generate(cmd, buf),
|
||||
Shell::Zsh => shells::Zsh.generate(cmd, buf),
|
||||
Shell::Fig => clap_complete_fig::Fig.generate(cmd, buf),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser, Clone)]
|
||||
enum SubCommand {
|
||||
#[clap(
|
||||
@ -102,7 +136,7 @@ enum SubCommand {
|
||||
#[clap(name = "shell-completion")]
|
||||
ShellCompletion {
|
||||
/// Which shell to generate for
|
||||
#[clap(long, possible_values=["bash", "elvish", "fish", "powershell", "zsh"])]
|
||||
#[clap(long, value_parser)]
|
||||
shell: Shell,
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user