Skip to content

Commit

Permalink
feat: generate autocomplete script for ya command (#919)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi authored Apr 16, 2024
1 parent 4b04cb2 commit 9e75ed5
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 16 deletions.
14 changes: 8 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ rustup toolchain install stable --profile minimal
rustup target add "$1"

# 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
mkdir "$ARTIFACT_NAME"
mkdir -p "$ARTIFACT_NAME/completions"
cp "target/$1/release/ya" "$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"

# Zip the artifact
Expand Down
2 changes: 1 addition & 1 deletion yazi-adaptor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ futures = "0.3.30"
image = "0.24.9"
imagesize = "0.12.0"
kamadak-exif = "0.5.5"
ratatui = "0.26.1"
ratatui = "0.26.2"
tokio = { version = "1.37.0", features = [ "full" ] }

# Logging
Expand Down
8 changes: 7 additions & 1 deletion yazi-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ homepage = "https://yazi-rs.github.io"
repository = "https://github.com/sxyazi/yazi"

[dependencies]
yazi-dds = { path = "../yazi-dds", version = "0.2.4" }
yazi-dds = { path = "../yazi-dds", version = "0.2.4" }

# External dependencies
anyhow = "1.0.82"
clap = { version = "4.5.4", features = [ "derive" ] }
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]]
name = "ya"
path = "src/main.rs"
28 changes: 28 additions & 0 deletions yazi-cli/build.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
2 changes: 1 addition & 1 deletion yazi-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ arc-swap = "1.7.1"
crossterm = "0.27.0"
globset = "0.4.14"
indexmap = "2.2.6"
ratatui = "0.26.1"
ratatui = "0.26.2"
serde = { version = "1.0.197", features = [ "derive" ] }
shell-words = "1.1.0"
toml = { version = "0.8.12", features = [ "preserve_order" ] }
Expand Down
2 changes: 1 addition & 1 deletion yazi-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ crossterm = "0.27.0"
futures = "0.3.30"
notify = { version = "6.1.1", default-features = false, features = [ "macos_fsevent" ] }
parking_lot = "0.12.1"
ratatui = "0.26.1"
ratatui = "0.26.2"
regex = "1.10.4"
scopeguard = "1.2.0"
serde = "1.0.197"
Expand Down
4 changes: 4 additions & 0 deletions yazi-core/src/manager/commands/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ impl Manager {
return;
};

if name.is_empty() {
return;
}

let new = hovered.parent().unwrap().join(name);
if opt.force || !accessible(&new).await {
Self::rename_do(tab, hovered, Url::from(new)).await.ok();
Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ crossterm = { version = "0.27.0", features = [ "event-stream" ] }
fdlimit = "0.3.0"
futures = "0.3.30"
mlua = { version = "0.9.7", features = [ "lua54", "vendored" ] }
ratatui = "0.26.1"
ratatui = "0.26.2"
scopeguard = "1.2.0"
syntect = { version = "5.2.0", default-features = false, features = [ "parsing", "plist-load", "regex-onig" ] }
tokio = { version = "1.37.0", features = [ "full" ] }
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ futures = "0.3.30"
md-5 = "0.10.6"
mlua = { version = "0.9.7", features = [ "lua54", "vendored", "serialize", "macros", "async" ] }
parking_lot = "0.12.1"
ratatui = "0.26.1"
ratatui = "0.26.2"
serde = "1.0.197"
serde_json = "1.0.115"
shell-escape = "0.1.5"
Expand Down
2 changes: 1 addition & 1 deletion yazi-shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dirs = "5.0.1"
futures = "0.3.30"
parking_lot = "0.12.1"
percent-encoding = "2.3.1"
ratatui = "0.26.1"
ratatui = "0.26.2"
regex = "1.10.4"
serde = "1.0.197"
tokio = { version = "1.37.0", features = [ "full" ] }
Expand Down

0 comments on commit 9e75ed5

Please sign in to comment.