feat: generate autocomplete script for ya command (#919)

This commit is contained in:
三咲雅 · Misaki Masa 2024-04-16 12:40:14 +08:00 committed by GitHub
parent 4b04cb24b4
commit 9e75ed5c71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 58 additions and 16 deletions

14
Cargo.lock generated
View File

@ -1554,9 +1554,9 @@ dependencies = [
[[package]] [[package]]
name = "ratatui" name = "ratatui"
version = "0.26.1" version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcb12f8fbf6c62614b0d56eb352af54f6a22410c3b079eb53ee93c7b97dd31d8" checksum = "a564a852040e82671dc50a37d88f3aa83bbc690dfc6844cfe7a2591620206a80"
dependencies = [ dependencies = [
"bitflags 2.5.0", "bitflags 2.5.0",
"cassowary", "cassowary",
@ -1848,12 +1848,12 @@ dependencies = [
[[package]] [[package]]
name = "stability" name = "stability"
version = "0.1.1" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebd1b177894da2a2d9120208c3386066af06a488255caabc5de8ddca22dbc3ce" checksum = "2ff9eaf853dec4c8802325d8b6d3dffa86cc707fd7a1a4cdbf416e13b061787a"
dependencies = [ dependencies = [
"quote", "quote",
"syn 1.0.109", "syn 2.0.58",
] ]
[[package]] [[package]]
@ -1903,7 +1903,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote",
"unicode-ident", "unicode-ident",
] ]
@ -2724,6 +2723,9 @@ version = "0.2.4"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",
"clap_complete",
"clap_complete_fig",
"clap_complete_nushell",
"tokio", "tokio",
"yazi-dds", "yazi-dds",
] ]

View File

@ -10,13 +10,15 @@ rustup toolchain install stable --profile minimal
rustup target add "$1" rustup target add "$1"
# Build for the target # Build for the target
cargo build --release --locked --target "$1" cargo build -p yazi-cli --release --locked --target "$1"
cargo build -p yazi-fm --release --locked --target "$1"
# Create the artifact # Create the artifact
mkdir "$ARTIFACT_NAME" mkdir -p "$ARTIFACT_NAME/completions"
cp "target/$1/release/ya" "$ARTIFACT_NAME" cp "target/$1/release/ya" "$ARTIFACT_NAME"
cp "target/$1/release/yazi" "$ARTIFACT_NAME" cp "target/$1/release/yazi" "$ARTIFACT_NAME"
cp -r yazi-boot/completions "$ARTIFACT_NAME" cp yazi-cli/completions/* "$ARTIFACT_NAME/completions"
cp yazi-boot/completions/* "$ARTIFACT_NAME/completions"
cp README.md LICENSE "$ARTIFACT_NAME" cp README.md LICENSE "$ARTIFACT_NAME"
# Zip the artifact # Zip the artifact

View File

@ -22,7 +22,7 @@ futures = "0.3.30"
image = "0.24.9" image = "0.24.9"
imagesize = "0.12.0" imagesize = "0.12.0"
kamadak-exif = "0.5.5" kamadak-exif = "0.5.5"
ratatui = "0.26.1" ratatui = "0.26.2"
tokio = { version = "1.37.0", features = [ "full" ] } tokio = { version = "1.37.0", features = [ "full" ] }
# Logging # Logging

View File

@ -9,13 +9,19 @@ homepage = "https://yazi-rs.github.io"
repository = "https://github.com/sxyazi/yazi" repository = "https://github.com/sxyazi/yazi"
[dependencies] [dependencies]
yazi-dds = { path = "../yazi-dds", version = "0.2.4" } yazi-dds = { path = "../yazi-dds", version = "0.2.4" }
# External dependencies # External dependencies
anyhow = "1.0.82" anyhow = "1.0.82"
clap = { version = "4.5.4", features = [ "derive" ] } clap = { version = "4.5.4", features = [ "derive" ] }
tokio = { version = "1.37.0", features = [ "full" ] } tokio = { version = "1.37.0", features = [ "full" ] }
[build-dependencies]
clap = { version = "4.5.4", features = [ "derive" ] }
clap_complete = "4.5.2"
clap_complete_nushell = "4.5.1"
clap_complete_fig = "4.5.0"
[[bin]] [[bin]]
name = "ya" name = "ya"
path = "src/main.rs" path = "src/main.rs"

28
yazi-cli/build.rs Normal file
View File

@ -0,0 +1,28 @@
#[path = "src/args.rs"]
mod args;
use std::{env, error::Error};
use clap::CommandFactory;
use clap_complete::{generate_to, Shell};
fn main() -> Result<(), Box<dyn Error>> {
if env::var_os("YAZI_GEN_COMPLETIONS").is_none() {
return Ok(());
}
let cmd = &mut args::Args::command();
let bin = "ya";
let out = "completions";
std::fs::create_dir_all(out)?;
generate_to(Shell::Bash, cmd, bin, out)?;
generate_to(Shell::Fish, cmd, bin, out)?;
generate_to(Shell::Zsh, cmd, bin, out)?;
generate_to(Shell::Elvish, cmd, bin, out)?;
generate_to(Shell::PowerShell, cmd, bin, out)?;
generate_to(clap_complete_nushell::Nushell, cmd, bin, out)?;
generate_to(clap_complete_fig::Fig, cmd, bin, out)?;
Ok(())
}

View File

@ -17,7 +17,7 @@ arc-swap = "1.7.1"
crossterm = "0.27.0" crossterm = "0.27.0"
globset = "0.4.14" globset = "0.4.14"
indexmap = "2.2.6" indexmap = "2.2.6"
ratatui = "0.26.1" ratatui = "0.26.2"
serde = { version = "1.0.197", features = [ "derive" ] } serde = { version = "1.0.197", features = [ "derive" ] }
shell-words = "1.1.0" shell-words = "1.1.0"
toml = { version = "0.8.12", features = [ "preserve_order" ] } toml = { version = "0.8.12", features = [ "preserve_order" ] }

View File

@ -26,7 +26,7 @@ crossterm = "0.27.0"
futures = "0.3.30" futures = "0.3.30"
notify = { version = "6.1.1", default-features = false, features = [ "macos_fsevent" ] } notify = { version = "6.1.1", default-features = false, features = [ "macos_fsevent" ] }
parking_lot = "0.12.1" parking_lot = "0.12.1"
ratatui = "0.26.1" ratatui = "0.26.2"
regex = "1.10.4" regex = "1.10.4"
scopeguard = "1.2.0" scopeguard = "1.2.0"
serde = "1.0.197" serde = "1.0.197"

View File

@ -57,6 +57,10 @@ impl Manager {
return; return;
}; };
if name.is_empty() {
return;
}
let new = hovered.parent().unwrap().join(name); let new = hovered.parent().unwrap().join(name);
if opt.force || !accessible(&new).await { if opt.force || !accessible(&new).await {
Self::rename_do(tab, hovered, Url::from(new)).await.ok(); Self::rename_do(tab, hovered, Url::from(new)).await.ok();

View File

@ -25,7 +25,7 @@ crossterm = { version = "0.27.0", features = [ "event-stream" ] }
fdlimit = "0.3.0" fdlimit = "0.3.0"
futures = "0.3.30" futures = "0.3.30"
mlua = { version = "0.9.7", features = [ "lua54", "vendored" ] } mlua = { version = "0.9.7", features = [ "lua54", "vendored" ] }
ratatui = "0.26.1" ratatui = "0.26.2"
scopeguard = "1.2.0" scopeguard = "1.2.0"
syntect = { version = "5.2.0", default-features = false, features = [ "parsing", "plist-load", "regex-onig" ] } syntect = { version = "5.2.0", default-features = false, features = [ "parsing", "plist-load", "regex-onig" ] }
tokio = { version = "1.37.0", features = [ "full" ] } tokio = { version = "1.37.0", features = [ "full" ] }

View File

@ -23,7 +23,7 @@ futures = "0.3.30"
md-5 = "0.10.6" md-5 = "0.10.6"
mlua = { version = "0.9.7", features = [ "lua54", "vendored", "serialize", "macros", "async" ] } mlua = { version = "0.9.7", features = [ "lua54", "vendored", "serialize", "macros", "async" ] }
parking_lot = "0.12.1" parking_lot = "0.12.1"
ratatui = "0.26.1" ratatui = "0.26.2"
serde = "1.0.197" serde = "1.0.197"
serde_json = "1.0.115" serde_json = "1.0.115"
shell-escape = "0.1.5" shell-escape = "0.1.5"

View File

@ -16,7 +16,7 @@ dirs = "5.0.1"
futures = "0.3.30" futures = "0.3.30"
parking_lot = "0.12.1" parking_lot = "0.12.1"
percent-encoding = "2.3.1" percent-encoding = "2.3.1"
ratatui = "0.26.1" ratatui = "0.26.2"
regex = "1.10.4" regex = "1.10.4"
serde = "1.0.197" serde = "1.0.197"
tokio = { version = "1.37.0", features = [ "full" ] } tokio = { version = "1.37.0", features = [ "full" ] }