From d5dac789b31cc59bb3e29381b1cbc4814d8db595 Mon Sep 17 00:00:00 2001 From: Integral Date: Wed, 6 Nov 2024 20:00:54 +0800 Subject: [PATCH 1/2] fix: fd binary name detection --- yazi-boot/src/actions/debug.rs | 1 + yazi-core/src/tab/commands/search.rs | 2 +- yazi-plugin/src/external/fd.rs | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/yazi-boot/src/actions/debug.rs b/yazi-boot/src/actions/debug.rs index cf9fb0add..c0dc4e1d1 100644 --- a/yazi-boot/src/actions/debug.rs +++ b/yazi-boot/src/actions/debug.rs @@ -84,6 +84,7 @@ impl Actions { writeln!(s, " magick : {}", Self::process_output("magick", "--version"))?; writeln!(s, " fzf : {}", Self::process_output("fzf", "--version"))?; writeln!(s, " fd : {}", Self::process_output("fd", "--version"))?; + writeln!(s, " fdfind : {}", Self::process_output("fdfind", "--version"))?; writeln!(s, " rg : {}", Self::process_output("rg", "--version"))?; writeln!(s, " chafa : {}", Self::process_output("chafa", "--version"))?; writeln!(s, " zoxide : {}", Self::process_output("zoxide", "--version"))?; diff --git a/yazi-core/src/tab/commands/search.rs b/yazi-core/src/tab/commands/search.rs index d3550db21..832491421 100644 --- a/yazi-core/src/tab/commands/search.rs +++ b/yazi-core/src/tab/commands/search.rs @@ -61,7 +61,7 @@ impl Tab { hidden, subject: opt.subject, args: opt.args, - }) + }).await }?; let rx = UnboundedReceiverStream::new(rx).chunks_timeout(1000, Duration::from_millis(300)); diff --git a/yazi-plugin/src/external/fd.rs b/yazi-plugin/src/external/fd.rs index 74aaca151..f2f6af57d 100644 --- a/yazi-plugin/src/external/fd.rs +++ b/yazi-plugin/src/external/fd.rs @@ -1,18 +1,24 @@ use std::process::Stdio; use anyhow::Result; -use tokio::{io::{AsyncBufReadExt, BufReader}, process::Command, sync::mpsc::{self, UnboundedReceiver}}; +use tokio::{ + io::{AsyncBufReadExt, BufReader}, + process::Command, + sync::mpsc::{self, UnboundedReceiver}, +}; use yazi_shared::fs::{File, Url}; pub struct FdOpt { - pub cwd: Url, - pub hidden: bool, + pub cwd: Url, + pub hidden: bool, pub subject: String, - pub args: Vec, + pub args: Vec, } -pub fn fd(opt: FdOpt) -> Result> { - let mut child = Command::new("fd") +pub async fn fd(opt: FdOpt) -> Result> { + let cmd_name = if Command::new("fd").arg("-V").status().await.is_ok() { "fd" } else { "fdfind" }; + + let mut child = Command::new(cmd_name) .arg("--base-directory") .arg(&opt.cwd) .arg("--regex") From 923248fcb3dfa9015724f7573a165584503c9d2c Mon Sep 17 00:00:00 2001 From: sxyazi Date: Wed, 6 Nov 2024 20:17:10 +0800 Subject: [PATCH 2/2] Avoid unnecessary `fd -V` check, run `rustfmt +nightly **/*.rs` --- cspell.json | 2 +- yazi-core/src/tab/commands/search.rs | 2 +- yazi-core/src/tab/commands/select.rs | 2 +- yazi-plugin/src/cha/cha.rs | 2 +- yazi-plugin/src/elements/padding.rs | 7 +++-- yazi-plugin/src/elements/paragraph.rs | 2 +- yazi-plugin/src/external/fd.rs | 42 +++++++++++++-------------- 7 files changed, 29 insertions(+), 30 deletions(-) diff --git a/cspell.json b/cspell.json index c9ca6db9f..b37b595d0 100644 --- a/cspell.json +++ b/cspell.json @@ -1 +1 @@ -{"flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds","tcsi","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod"],"version":"0.2","language":"en"} \ No newline at end of file +{"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds","tcsi","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod","fdfind"],"version":"0.2","language":"en","flagWords":[]} \ No newline at end of file diff --git a/yazi-core/src/tab/commands/search.rs b/yazi-core/src/tab/commands/search.rs index 832491421..d3550db21 100644 --- a/yazi-core/src/tab/commands/search.rs +++ b/yazi-core/src/tab/commands/search.rs @@ -61,7 +61,7 @@ impl Tab { hidden, subject: opt.subject, args: opt.args, - }).await + }) }?; let rx = UnboundedReceiverStream::new(rx).chunks_timeout(1000, Duration::from_millis(300)); diff --git a/yazi-core/src/tab/commands/select.rs b/yazi-core/src/tab/commands/select.rs index 997205507..3e237d41b 100644 --- a/yazi-core/src/tab/commands/select.rs +++ b/yazi-core/src/tab/commands/select.rs @@ -22,7 +22,7 @@ impl Tab { title: "Deprecated command".to_owned(), content: "`select` and `select_all` command has been renamed to `toggle` and `toggle_all` in Yazi v0.4 -Please change it in your keymap.toml, see #1773 for details: https://github.com/sxyazi/yazi/pull/1773".to_owned(), +Please change it in your keymap.toml, see #1772 for details: https://github.com/sxyazi/yazi/issues/1772".to_owned(), level: yazi_proxy::options::NotifyLevel::Error, timeout: Duration::from_secs(20), }); diff --git a/yazi-plugin/src/cha/cha.rs b/yazi-plugin/src/cha/cha.rs index 95e0ed136..ccaa16ef1 100644 --- a/yazi-plugin/src/cha/cha.rs +++ b/yazi-plugin/src/cha/cha.rs @@ -18,7 +18,7 @@ fn warn_deprecated(id: Option<&str>) { }; let s = "The `created`, `modified`, `accessed`, `length`, and `permissions` properties of `Cha` have been renamed in Yazi v0.4. -Please use the new `btime`, `mtime`, `atime`, `len`, and `perm` instead, in your {id}. See https://github.com/sxyazi/yazi/pull/1761 for details."; +Please use the new `btime`, `mtime`, `atime`, `len`, and `perm` instead, in your {id}. See #1772 for details: https://github.com/sxyazi/yazi/issues/1772"; yazi_proxy::AppProxy::notify(yazi_proxy::options::NotifyOpt { title: "Deprecated API".to_owned(), content: s.replace("{id}", &id), diff --git a/yazi-plugin/src/elements/padding.rs b/yazi-plugin/src/elements/padding.rs index 9e1fe90ea..295e90fbe 100644 --- a/yazi-plugin/src/elements/padding.rs +++ b/yazi-plugin/src/elements/padding.rs @@ -13,9 +13,10 @@ impl Deref for Padding { impl Padding { pub fn install(lua: &Lua, ui: &Table) -> mlua::Result<()> { - let new = lua.create_function(|_, (_, left, right, top, bottom): (Table, u16, u16, u16, u16)| { - Ok(Self(ratatui::widgets::Padding::new(left, right, top, bottom))) - })?; + let new = + lua.create_function(|_, (_, left, right, top, bottom): (Table, u16, u16, u16, u16)| { + Ok(Self(ratatui::widgets::Padding::new(left, right, top, bottom))) + })?; let padding = lua.create_table_from([ ( diff --git a/yazi-plugin/src/elements/paragraph.rs b/yazi-plugin/src/elements/paragraph.rs index df5b6f7c6..fb3974bcb 100644 --- a/yazi-plugin/src/elements/paragraph.rs +++ b/yazi-plugin/src/elements/paragraph.rs @@ -16,7 +16,7 @@ fn warn_deprecated(id: Option<&str>) { }; let s = "The `ui.Paragraph` and `ui.ListItem` elements have been deprecated in Yazi v0.4. -Please use the new `ui.Text` instead, in your {id}. See https://github.com/sxyazi/yazi/pull/1776 for details."; +Please use the new `ui.Text` instead, in your {id}. See #1772 for details: https://github.com/sxyazi/yazi/issues/1772"; yazi_proxy::AppProxy::notify(yazi_proxy::options::NotifyOpt { title: "Deprecated API".to_owned(), content: s.replace("{id}", &id), diff --git a/yazi-plugin/src/external/fd.rs b/yazi-plugin/src/external/fd.rs index f2f6af57d..61480e9a3 100644 --- a/yazi-plugin/src/external/fd.rs +++ b/yazi-plugin/src/external/fd.rs @@ -1,34 +1,18 @@ use std::process::Stdio; use anyhow::Result; -use tokio::{ - io::{AsyncBufReadExt, BufReader}, - process::Command, - sync::mpsc::{self, UnboundedReceiver}, -}; +use tokio::{io::{AsyncBufReadExt, BufReader}, process::{Child, Command}, sync::mpsc::{self, UnboundedReceiver}}; use yazi_shared::fs::{File, Url}; pub struct FdOpt { - pub cwd: Url, - pub hidden: bool, + pub cwd: Url, + pub hidden: bool, pub subject: String, - pub args: Vec, + pub args: Vec, } -pub async fn fd(opt: FdOpt) -> Result> { - let cmd_name = if Command::new("fd").arg("-V").status().await.is_ok() { "fd" } else { "fdfind" }; - - let mut child = Command::new(cmd_name) - .arg("--base-directory") - .arg(&opt.cwd) - .arg("--regex") - .arg(if opt.hidden { "--hidden" } else { "--no-hidden" }) - .args(opt.args) - .arg(opt.subject) - .kill_on_drop(true) - .stdout(Stdio::piped()) - .stderr(Stdio::null()) - .spawn()?; +pub fn fd(opt: FdOpt) -> Result> { + let mut child = spawn("fd", &opt).or_else(|_| spawn("fdfind", &opt))?; let mut it = BufReader::new(child.stdout.take().unwrap()).lines(); let (tx, rx) = mpsc::unbounded_channel(); @@ -43,3 +27,17 @@ pub async fn fd(opt: FdOpt) -> Result> { }); Ok(rx) } + +fn spawn(program: &str, opt: &FdOpt) -> std::io::Result { + Command::new(program) + .arg("--base-directory") + .arg(&opt.cwd) + .arg("--regex") + .arg(if opt.hidden { "--hidden" } else { "--no-hidden" }) + .args(&opt.args) + .arg(&opt.subject) + .kill_on_drop(true) + .stdout(Stdio::piped()) + .stderr(Stdio::null()) + .spawn() +}