mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat(completions): generate shell completion scripts
This commit is contained in:
parent
fb10da6857
commit
82cd486efa
7 changed files with 107 additions and 35 deletions
32
Cargo.lock
generated
32
Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
29
config/build.rs
Normal 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(())
|
||||
}
|
||||
|
|
@ -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
22
config/src/boot/cli.rs
Normal 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,
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
mod boot;
|
||||
mod cli;
|
||||
|
||||
pub use boot::*;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue