From 866ed1704459b91b7e6ea220e4aadcbd1397ba6d Mon Sep 17 00:00:00 2001 From: sxyazi Date: Wed, 9 Aug 2023 19:12:15 +0800 Subject: [PATCH 1/5] docs: fold installation steps --- README.md | 54 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 291b4a16..64799400 100644 --- a/README.md +++ b/README.md @@ -10,17 +10,19 @@ https://github.com/sxyazi/yazi/assets/17523360/740a41f4-3d24-4287-952c-3aec51520 Before getting started, ensure that the following dependencies are installed on your system: -- nerd-fonts (required, for icons) -- ffmpegthumbnailer (optional, for video thumbnails) -- unar (optional, for archive preview) -- jq (optional, for JSON preview) -- poppler (optional, for PDF preview) -- fd (optional, for file searching) -- rg (optional, for file content searching) -- fzf (optional, for directory jumping) -- zoxide (optional, for directory jumping) +- nerd-fonts (_required_, for icons) +- ffmpegthumbnailer (_optional_, for video thumbnails) +- unar (_optional_, for archive preview) +- jq (_optional_, for JSON preview) +- poppler (_optional_, for PDF preview) +- fd (_optional_, for file searching) +- rg (_optional_, for file content searching) +- fzf (_optional_, for directory jumping) +- zoxide (_optional_, for directory jumping) -### Arch Linux +
+ +Arch Linux Install with paru or your favorite AUR helper: @@ -30,7 +32,11 @@ paru -S yazi ffmpegthumbnailer unarchiver jq poppler fd ripgrep fzf zoxide Or, you can replace `yazi` with `yazi-bin` package if you want pre-built binary instead of compiling by yourself. -### macOS +
+ +
+ +macOS Install the dependencies with Homebrew: @@ -45,7 +51,11 @@ And download the latest release [from here](https://github.com/sxyazi/yazi/relea cargo install --git https://github.com/sxyazi/yazi.git ``` -### Nix +
+ +
+ +Nix Nix users can install Yazi from [the NUR](https://github.com/nix-community/nur-combined/blob/master/repos/xyenon/pkgs/yazi/default.nix): @@ -64,7 +74,11 @@ environment.systemPackages = with pkgs; [ If you prefer to use the most recent code, use `nur.repos.xyenon.yazi-unstable` instead. -### Build from source +
+ +
+ +Build from source Execute the following commands to clone the project and build Yazi: @@ -80,6 +94,8 @@ Then, you can run: ./target/release/yazi ``` +
+ ## Usage ```bash @@ -88,7 +104,7 @@ yazi If you want to use your own config, copy the [config folder](https://github.com/sxyazi/yazi/tree/main/config/preset) to `~/.config/yazi`, and modify it as you like. -There is a wrapper of yazi that provides the ability to change the current shell's working directory when yazi exited, feel free to use it: +There is a wrapper of yazi, that provides the ability to change the current working directory when yazi exiting, feel free to use it: ```bash function ya() { @@ -101,6 +117,11 @@ function ya() { } ``` +## Discussion + +- Discord Server (English mainly): https://discord.gg/qfADduSdJu +- Telegram Group (Chinese mainly): https://t.me/yazi_rs + ## Image Preview | Platform | Protocol | Support | @@ -120,11 +141,6 @@ That's relying on the `$TERM`, `$TERM_PROGRAM`, and `$XDG_SESSION_TYPE` variable For instance, if your terminal is Alacritty, which doesn't support displaying images itself, but you are running on an X11/Wayland environment, it will automatically use the "Window system protocol" to display images -- this requires you to have [Überzug++](https://github.com/jstkdng/ueberzugpp) installed. -## Discussion - -- Discord Server (English mainly): https://discord.gg/qfADduSdJu -- Telegram Group (Chinese mainly): https://t.me/yazi_rs - ## TODO - [x] Add example config for general usage, currently please see my [another repo](https://github.com/sxyazi/dotfiles/tree/main/yazi) instead From 4823c0abc49aef0e597b7f8fdc4b1bf7a0dcdcd1 Mon Sep 17 00:00:00 2001 From: XYenon Date: Wed, 9 Aug 2023 22:30:02 +0800 Subject: [PATCH 2/5] feat: add interactive cd (#43) --- app/src/executor.rs | 8 ++++++-- config/preset/keymap.toml | 1 + core/src/manager/tab.rs | 12 ++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/executor.rs b/app/src/executor.rs index 437bcef4..78414152 100644 --- a/app/src/executor.rs +++ b/app/src/executor.rs @@ -67,8 +67,12 @@ impl Executor { "forward" => cx.manager.active_mut().forward(), "cd" => { let path = exec.args.get(0).map(PathBuf::from).unwrap_or_default(); - emit!(Cd(path)); - false + if exec.named.contains_key("interactive") { + cx.manager.active_mut().cd_interactive(path) + } else { + emit!(Cd(path)); + false + } } // Selection diff --git a/config/preset/keymap.toml b/config/preset/keymap.toml index 5ae1e1ab..661665ea 100644 --- a/config/preset/keymap.toml +++ b/config/preset/keymap.toml @@ -97,6 +97,7 @@ keymap = [ { on = [ "g", "c" ], exec = "cd ~/.config" }, { on = [ "g", "d" ], exec = "cd ~/Downloads" }, { on = [ "g", "t" ], exec = "cd /tmp" }, + { on = [ "g", "" ], exec = "cd --interactive" }, ] [tasks] diff --git a/core/src/manager/tab.rs b/core/src/manager/tab.rs index 719fb57d..9124c995 100644 --- a/core/src/manager/tab.rs +++ b/core/src/manager/tab.rs @@ -115,6 +115,18 @@ impl Tab { true } + pub fn cd_interactive(&mut self, target: PathBuf) -> bool { + tokio::spawn(async move { + let result = + emit!(Input(InputOpt::top("Change directory:").with_value(target.to_string_lossy()))); + + if let Ok(target) = result.await { + emit!(Cd(PathBuf::from(target))); + } + }); + false + } + pub fn enter(&mut self) -> bool { let hovered = if let Some(ref h) = self.current.hovered { h.clone() From f119489907fb3e724e320feeeef1a6024c053fee Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Thu, 10 Aug 2023 18:28:42 +0800 Subject: [PATCH 3/5] feat: show current dir name in tab (#41) --- Cargo.lock | 1 + app/Cargo.toml | 1 + app/src/header/tabs.rs | 29 ++++++++++++++++++++++++++--- config/preset/theme.toml | 5 +++-- config/src/theme/theme.rs | 5 +++-- core/src/manager/tab.rs | 9 +++++++++ 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e99e9f20..4ca59c32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -134,6 +134,7 @@ dependencies = [ "tracing", "tracing-appender", "tracing-subscriber", + "unicode-width", ] [[package]] diff --git a/app/Cargo.toml b/app/Cargo.toml index 239afaed..099f2ce1 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -18,6 +18,7 @@ libc = "^0" ratatui = "^0" signal-hook-tokio = { version = "^0", features = [ "futures-v0_3" ] } tokio = { version = "^1", features = [ "parking_lot" ] } +unicode-width = "^0" # Logging tracing = "^0" diff --git a/app/src/header/tabs.rs b/app/src/header/tabs.rs index 02f8ca44..414eef59 100644 --- a/app/src/header/tabs.rs +++ b/app/src/header/tabs.rs @@ -1,5 +1,8 @@ +use std::ops::ControlFlow; + use config::THEME; use ratatui::{buffer::Buffer, layout::{Alignment, Rect}, text::{Line, Span}, widgets::{Paragraph, Widget}}; +use unicode_width::UnicodeWidthStr; use crate::Ctx; @@ -19,11 +22,31 @@ impl<'a> Widget for Tabs<'a> { tabs .iter() .enumerate() - .map(|(i, _)| { + .map(|(i, tab)| { + let mut text = format!("{}", i + 1); + if let Some(dir_name) = tab.current_name() { + text.push(' '); + text.push_str(dir_name); + } + + let threshold = THEME.tab.max_width.max(1); + let truncated = text.chars().try_fold(String::with_capacity(threshold), |mut text, c| { + if text.width() > threshold { + ControlFlow::Break(text) + } else { + text.push(c); + ControlFlow::Continue(text) + } + }); + let text = match truncated { + ControlFlow::Break(text) => text, + ControlFlow::Continue(text) => text, + }; + if i == tabs.idx() { - Span::styled(format!(" {} ", i + 1), THEME.tab.active.get()) + Span::styled(format!(" {text} "), THEME.tab.active.get()) } else { - Span::styled(format!(" {} ", i + 1), THEME.tab.inactive.get()) + Span::styled(format!(" {text} "), THEME.tab.inactive.get()) } }) .collect::>(), diff --git a/config/preset/theme.toml b/config/preset/theme.toml index 8016374c..a4cb7061 100644 --- a/config/preset/theme.toml +++ b/config/preset/theme.toml @@ -1,6 +1,7 @@ [tab] -active = { fg = "#1E2031", bg = "#80AEFA" } -inactive = { fg = "#C8D3F8", bg = "#484D66" } +active = { fg = "#1E2031", bg = "#80AEFA" } +inactive = { fg = "#C8D3F8", bg = "#484D66" } +max_width = 1 [status] primary = { normal = "#80AEFA", select = "#CD9EFC", unset = "#FFA577" } diff --git a/config/src/theme/theme.rs b/config/src/theme/theme.rs index 34adc49e..d3f66548 100644 --- a/config/src/theme/theme.rs +++ b/config/src/theme/theme.rs @@ -8,8 +8,9 @@ use crate::MERGED_THEME; #[derive(Deserialize)] pub struct Tab { - pub active: Style, - pub inactive: Style, + pub active: Style, + pub inactive: Style, + pub max_width: usize, } #[derive(Deserialize)] diff --git a/core/src/manager/tab.rs b/core/src/manager/tab.rs index 9124c995..78706e25 100644 --- a/core/src/manager/tab.rs +++ b/core/src/manager/tab.rs @@ -270,6 +270,15 @@ impl Tab { }; true } + + pub fn current_name(&self) -> Option<&str> { + self + .current + .cwd + .file_name() + .and_then(|name| name.to_str()) + .or_else(|| self.current.cwd.to_str()) + } } impl Tab { From 2efe97d14095edf7c5d0493e91d9602365e496ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Fri, 11 Aug 2023 13:52:06 +0800 Subject: [PATCH 4/5] fix: `show_hidden` not working (#47) --- core/src/files/files.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/files/files.rs b/core/src/files/files.rs index ac7a6be9..d2c39eb6 100644 --- a/core/src/files/files.rs +++ b/core/src/files/files.rs @@ -7,13 +7,22 @@ use tokio::fs; use super::File; -#[derive(Default)] pub struct Files { items: IndexMap, pub sort: FilesSort, pub show_hidden: bool, } +impl Default for Files { + fn default() -> Self { + Self { + items: Default::default(), + sort: Default::default(), + show_hidden: MANAGER.show_hidden, + } + } +} + impl Files { pub async fn read(paths: Vec) -> BTreeMap { let mut items = BTreeMap::new(); From a5eed70872e1aafe62bbaa89263959b69f617e9c Mon Sep 17 00:00:00 2001 From: sxyazi Date: Fri, 11 Aug 2023 14:38:41 +0800 Subject: [PATCH 5/5] docs: fix `mktemp` filename --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 64799400..9cd013a9 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ There is a wrapper of yazi, that provides the ability to change the current work ```bash function ya() { - tmp="$(mktemp -t "yazi-cwd")" + tmp="$(mktemp -t "yazi-cwd.XXXXX")" yazi --cwd-file="$tmp" if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then cd -- "$cwd"