feat(completions): generate shell completion scripts

This commit is contained in:
TD-Sky 2023-10-16 20:42:11 +08:00 committed by sxyazi
parent fb10da6857
commit 82cd486efa
No known key found for this signature in database
7 changed files with 107 additions and 35 deletions

32
Cargo.lock generated
View file

@ -307,6 +307,35 @@ dependencies = [
"strsim",
]
[[package]]
name = "clap_complete"
version = "4.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3ae8ba90b9d8b007efe66e55e48fb936272f5ca00349b5b0e89877520d35ea7"
dependencies = [
"clap",
]
[[package]]
name = "clap_complete_fig"
version = "4.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29bdbe21a263b628f83fcbeac86a4416a1d588c7669dd41473bc4149e4e7d2f1"
dependencies = [
"clap",
"clap_complete",
]
[[package]]
name = "clap_complete_nushell"
version = "4.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df47268eb308aaac1ffbfcd8ae43e43820cd094a051b03956d238f2bc60dc3fe"
dependencies = [
"clap",
"clap_complete",
]
[[package]]
name = "clap_derive"
version = "4.4.2"
@ -363,6 +392,9 @@ version = "0.1.5"
dependencies = [
"anyhow",
"clap",
"clap_complete",
"clap_complete_fig",
"clap_complete_nushell",
"crossterm",
"dirs",
"futures",

View file

@ -1,32 +1,32 @@
[package]
name = "app"
name = "app"
version = "0.1.5"
edition = "2021"
[dependencies]
adaptor = { path = "../adaptor" }
config = { path = "../config" }
core = { path = "../core" }
plugin = { path = "../plugin" }
shared = { path = "../shared" }
config = { path = "../config" }
core = { path = "../core" }
plugin = { path = "../plugin" }
shared = { path = "../shared" }
# External dependencies
ansi-to-tui = "^3"
anyhow = "^1"
crossterm = { version = "^0", features = [ "event-stream" ] }
futures = "^0"
ratatui = "^0"
tokio = { version = "^1", features = [ "parking_lot" ] }
ansi-to-tui = "^3"
anyhow = "^1"
crossterm = { version = "^0", features = ["event-stream"] }
futures = "^0"
ratatui = "^0"
tokio = { version = "^1", features = ["parking_lot"] }
unicode-width = "^0"
# Logging
tracing = "^0"
tracing-appender = "^0"
tracing = "^0"
tracing-appender = "^0"
tracing-subscriber = "^0"
[target."cfg(unix)".dependencies]
libc = "^0"
signal-hook-tokio = { version = "^0", features = [ "futures-v0_3" ] }
libc = "^0"
signal-hook-tokio = { version = "^0", features = ["futures-v0_3"] }
[[bin]]
name = "yazi"

View file

@ -20,3 +20,9 @@ serde = { version = "^1", features = [ "derive" ] }
shell-words = "^1"
toml = { version = "^0", features = [ "preserve_order" ] }
validator = { version = "^0", features = [ "derive" ] }
[build-dependencies]
clap = { version = "^4", features = [ "derive" ] }
clap_complete = "^4"
clap_complete_nushell = "^4"
clap_complete_fig = "^4"

29
config/build.rs Normal file
View file

@ -0,0 +1,29 @@
#[path = "src/boot/cli.rs"]
mod cli;
use std::{fs, io};
use clap::CommandFactory;
use clap_complete::{generate_to, Shell::*};
use clap_complete_fig::Fig;
use clap_complete_nushell::Nushell;
use self::cli::Args;
fn main() -> io::Result<()> {
let cmd = &mut Args::command();
let name = "yazi";
let dir = "completions";
fs::create_dir_all(dir)?;
generate_to(Bash, cmd, name, dir)?;
generate_to(Fish, cmd, name, dir)?;
generate_to(Zsh, cmd, name, dir)?;
generate_to(Elvish, cmd, name, dir)?;
generate_to(PowerShell, cmd, name, dir)?;
generate_to(Nushell, cmd, name, dir)?;
generate_to(Fig, cmd, name, dir)?;
Ok(())
}

View file

@ -1,8 +1,9 @@
use std::{env, fs, path::PathBuf, process};
use clap::{command, Parser};
use clap::Parser;
use shared::expand_path;
use super::cli::Args;
use crate::{Xdg, PREVIEW};
#[derive(Debug)]
@ -14,25 +15,6 @@ pub struct Boot {
pub chooser_file: Option<PathBuf>,
}
#[derive(Debug, Parser)]
#[command(name = "yazi", version)]
struct Args {
/// Set the current working directory
#[arg(index = 1)]
cwd: Option<PathBuf>,
/// Write the cwd on exit to this file
#[arg(long)]
cwd_file: Option<PathBuf>,
/// Write the selected files on open emitted by the chooser mode
#[arg(long)]
chooser_file: Option<PathBuf>,
/// Clear the cache directory
#[arg(long, action)]
clear_cache: bool,
}
impl Default for Boot {
fn default() -> Self {
let args = Args::parse();

22
config/src/boot/cli.rs Normal file
View file

@ -0,0 +1,22 @@
use std::path::PathBuf;
use clap::{command, Parser};
#[derive(Debug, Parser)]
#[command(name = "yazi", version)]
pub(super) struct Args {
/// Set the current working directory
#[arg(index = 1)]
pub cwd: Option<PathBuf>,
/// Write the cwd on exit to this file
#[arg(long)]
pub cwd_file: Option<PathBuf>,
/// Write the selected files on open emitted by the chooser mode
#[arg(long)]
pub chooser_file: Option<PathBuf>,
/// Clear the cache directory
#[arg(long, action)]
pub clear_cache: bool,
}

View file

@ -1,3 +1,4 @@
mod boot;
mod cli;
pub use boot::*;