mirror of
https://github.com/starship/starship.git
synced 2025-03-11 21:50:31 +01:00
feat(completions): Offer Nushell completions (#6366)
--------- Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
This commit is contained in:
parent
76675559c0
commit
df454d5a64
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -437,6 +437,16 @@ dependencies = [
|
||||
"clap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete_nushell"
|
||||
version = "4.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "315902e790cc6e5ddd20cbd313c1d0d49db77f191e149f96397230fb82a17677"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"clap_complete",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.28"
|
||||
@ -3093,6 +3103,7 @@ dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
"clap_complete",
|
||||
"clap_complete_nushell",
|
||||
"deelevate",
|
||||
"dirs 6.0.0",
|
||||
"dunce",
|
||||
|
@ -45,6 +45,7 @@ gix-faster = ["gix-features/zlib-stock", "gix/fast-sha1"]
|
||||
chrono = { version = "0.4.40", default-features = false, features = ["clock", "std", "wasmbind"] }
|
||||
clap = { version = "4.5.31", features = ["derive", "cargo", "unicode"] }
|
||||
clap_complete = "4.5.46"
|
||||
clap_complete_nushell = "4.5.4"
|
||||
dirs = "6.0.0"
|
||||
dunce = "1.0.5"
|
||||
# default feature restriction addresses https://github.com/starship/starship/issues/4251
|
||||
|
41
src/main.rs
41
src/main.rs
@ -6,8 +6,8 @@ use std::path::PathBuf;
|
||||
use std::thread::available_parallelism;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use clap::{CommandFactory, Parser, Subcommand};
|
||||
use clap_complete::{generate, Shell as CompletionShell};
|
||||
use clap::{CommandFactory, Parser, Subcommand, ValueEnum};
|
||||
use clap_complete::generate;
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::Rng;
|
||||
use starship::context::{Context, Properties, Target};
|
||||
@ -28,6 +28,36 @@ struct Cli {
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(clap::Parser, ValueEnum, Debug, Clone, PartialEq, Eq)]
|
||||
enum CompletionShell {
|
||||
Bash,
|
||||
Elvish,
|
||||
Fish,
|
||||
Nushell,
|
||||
PowerShell,
|
||||
Zsh,
|
||||
}
|
||||
|
||||
fn generate_shell(shell: impl clap_complete::Generator) {
|
||||
generate(
|
||||
shell,
|
||||
&mut Cli::command(),
|
||||
"starship",
|
||||
&mut io::stdout().lock(),
|
||||
)
|
||||
}
|
||||
|
||||
fn generate_completions(shell: CompletionShell) {
|
||||
match shell {
|
||||
CompletionShell::Bash => generate_shell(clap_complete::Shell::Bash),
|
||||
CompletionShell::Elvish => generate_shell(clap_complete::Shell::Elvish),
|
||||
CompletionShell::Fish => generate_shell(clap_complete::Shell::Fish),
|
||||
CompletionShell::PowerShell => generate_shell(clap_complete::Shell::PowerShell),
|
||||
CompletionShell::Zsh => generate_shell(clap_complete::Shell::Zsh),
|
||||
CompletionShell::Nushell => generate_shell(clap_complete_nushell::Nushell),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
enum Commands {
|
||||
/// Create a pre-populated GitHub issue with information about your configuration
|
||||
@ -236,12 +266,7 @@ fn main() {
|
||||
}
|
||||
Commands::Explain(props) => print::explain(props),
|
||||
Commands::Timings(props) => print::timings(props),
|
||||
Commands::Completions { shell } => generate(
|
||||
shell,
|
||||
&mut Cli::command(),
|
||||
"starship",
|
||||
&mut io::stdout().lock(),
|
||||
),
|
||||
Commands::Completions { shell } => generate_completions(shell),
|
||||
Commands::Session => println!(
|
||||
"{}",
|
||||
rand::thread_rng()
|
||||
|
Loading…
Reference in New Issue
Block a user