From 1135c13d0fe4766c3601e1eeea309f45bd219295 Mon Sep 17 00:00:00 2001 From: XYenon Date: Thu, 17 Aug 2023 14:58:46 +0800 Subject: [PATCH] feat: show symlink path (#67) --- app/src/manager/folder.rs | 11 +++++++++-- config/docs/yazi.md | 5 +++++ config/preset/yazi.toml | 1 + config/src/manager/manager.rs | 3 ++- core/src/files/file.rs | 6 +++++- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/src/manager/folder.rs b/app/src/manager/folder.rs index 1ca704f3..6cabdacf 100644 --- a/app/src/manager/folder.rs +++ b/app/src/manager/folder.rs @@ -1,6 +1,6 @@ use core::files::File; -use config::THEME; +use config::{MANAGER, THEME}; use ratatui::{buffer::Buffer, layout::Rect, style::Style, widgets::{List, ListItem, Widget}}; use shared::readable_path; @@ -80,7 +80,14 @@ impl<'a> Widget for Folder<'a> { self.file_style(v) }; - ListItem::new(format!(" {icon} {}", readable_path(k, &self.folder.cwd))).style(style) + let mut path = format!(" {icon} {}", readable_path(k, &self.folder.cwd)); + if let Some(ref link_to) = v.link_to { + if MANAGER.show_symlink { + path.push_str(&format!(" -> {}", link_to.display())); + } + } + + ListItem::new(path).style(style) }) .collect::>(); diff --git a/config/docs/yazi.md b/config/docs/yazi.md index e6614b04..c39a8135 100644 --- a/config/docs/yazi.md +++ b/config/docs/yazi.md @@ -24,6 +24,11 @@ - `true`: Show - `false`: Do not show +- show_symlink: Show the path of the symlink file point to, after the filename + + - `true`: Show + - `false`: Do not show + ## preview - tab_size: Tab width diff --git a/config/preset/yazi.toml b/config/preset/yazi.toml index 1d2d6ac1..ffb62506 100644 --- a/config/preset/yazi.toml +++ b/config/preset/yazi.toml @@ -3,6 +3,7 @@ sort_by = "modified" sort_reverse = true sort_dir_first = true show_hidden = false +show_symlink = true [preview] tab_size = 2 diff --git a/config/src/manager/manager.rs b/config/src/manager/manager.rs index 3995d302..90c013e3 100644 --- a/config/src/manager/manager.rs +++ b/config/src/manager/manager.rs @@ -11,7 +11,8 @@ pub struct Manager { pub sort_dir_first: bool, // Display - pub show_hidden: bool, + pub show_hidden: bool, + pub show_symlink: bool, } impl Default for Manager { diff --git a/core/src/files/file.rs b/core/src/files/file.rs index 515993c7..f0bb37f9 100644 --- a/core/src/files/file.rs +++ b/core/src/files/file.rs @@ -8,6 +8,7 @@ pub struct File { pub path: PathBuf, pub meta: Metadata, pub length: Option, + pub link_to: Option, pub is_link: bool, pub is_hidden: bool, pub is_selected: bool, @@ -22,13 +23,16 @@ impl File { pub async fn from_meta(path: &Path, mut meta: Metadata) -> File { let is_link = meta.is_symlink(); + let mut link_to = None; + if is_link { meta = fs::metadata(&path).await.unwrap_or(meta); + link_to = fs::read_link(&path).await.ok(); } let length = if meta.is_dir() { None } else { Some(meta.len()) }; let is_hidden = path.file_name().map(|s| s.to_string_lossy().starts_with('.')).unwrap_or(false); - File { path: path.to_path_buf(), meta, length, is_link, is_hidden, is_selected: false } + File { path: path.to_path_buf(), meta, length, link_to, is_link, is_hidden, is_selected: false } } }