mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
feat(completions): Offer Nushell completions (#6366)
--------- Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
This commit is contained in:
Generated
+11
@@ -437,6 +437,16 @@ dependencies = [
|
|||||||
"clap",
|
"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]]
|
[[package]]
|
||||||
name = "clap_derive"
|
name = "clap_derive"
|
||||||
version = "4.5.28"
|
version = "4.5.28"
|
||||||
@@ -3093,6 +3103,7 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
"clap_complete",
|
"clap_complete",
|
||||||
|
"clap_complete_nushell",
|
||||||
"deelevate",
|
"deelevate",
|
||||||
"dirs 6.0.0",
|
"dirs 6.0.0",
|
||||||
"dunce",
|
"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"] }
|
chrono = { version = "0.4.40", default-features = false, features = ["clock", "std", "wasmbind"] }
|
||||||
clap = { version = "4.5.31", features = ["derive", "cargo", "unicode"] }
|
clap = { version = "4.5.31", features = ["derive", "cargo", "unicode"] }
|
||||||
clap_complete = "4.5.46"
|
clap_complete = "4.5.46"
|
||||||
|
clap_complete_nushell = "4.5.4"
|
||||||
dirs = "6.0.0"
|
dirs = "6.0.0"
|
||||||
dunce = "1.0.5"
|
dunce = "1.0.5"
|
||||||
# default feature restriction addresses https://github.com/starship/starship/issues/4251
|
# default feature restriction addresses https://github.com/starship/starship/issues/4251
|
||||||
|
|||||||
+33
-8
@@ -6,8 +6,8 @@ use std::path::PathBuf;
|
|||||||
use std::thread::available_parallelism;
|
use std::thread::available_parallelism;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use clap::{CommandFactory, Parser, Subcommand};
|
use clap::{CommandFactory, Parser, Subcommand, ValueEnum};
|
||||||
use clap_complete::{generate, Shell as CompletionShell};
|
use clap_complete::generate;
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use starship::context::{Context, Properties, Target};
|
use starship::context::{Context, Properties, Target};
|
||||||
@@ -28,6 +28,36 @@ struct Cli {
|
|||||||
command: Commands,
|
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)]
|
#[derive(Subcommand, Debug)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
/// Create a pre-populated GitHub issue with information about your configuration
|
/// Create a pre-populated GitHub issue with information about your configuration
|
||||||
@@ -236,12 +266,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
Commands::Explain(props) => print::explain(props),
|
Commands::Explain(props) => print::explain(props),
|
||||||
Commands::Timings(props) => print::timings(props),
|
Commands::Timings(props) => print::timings(props),
|
||||||
Commands::Completions { shell } => generate(
|
Commands::Completions { shell } => generate_completions(shell),
|
||||||
shell,
|
|
||||||
&mut Cli::command(),
|
|
||||||
"starship",
|
|
||||||
&mut io::stdout().lock(),
|
|
||||||
),
|
|
||||||
Commands::Session => println!(
|
Commands::Session => println!(
|
||||||
"{}",
|
"{}",
|
||||||
rand::thread_rng()
|
rand::thread_rng()
|
||||||
|
|||||||
Reference in New Issue
Block a user