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/README.md b/README.md
index 291b4a16..9cd013a9 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,11 +104,11 @@ 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() {
- 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"
@@ -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
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/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/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/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/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/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();
diff --git a/core/src/manager/tab.rs b/core/src/manager/tab.rs
index 719fb57d..78706e25 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()
@@ -258,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 {