mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: show symlink
This commit is contained in:
parent
d3a0d56ce6
commit
af193b50a9
4 changed files with 15 additions and 4 deletions
|
|
@ -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,13 @@ impl<'a> Widget for Folder<'a> {
|
|||
self.file_style(v)
|
||||
};
|
||||
|
||||
ListItem::new(format!(" {icon} {}", readable_path(k, &self.folder.cwd))).style(style)
|
||||
let display_path = readable_path(k, &self.folder.cwd);
|
||||
let display_full = if MANAGER.show_symlink && v.is_link {
|
||||
format!(" {icon} {} -> {}", display_path, v.link_to.clone().unwrap_or_default().to_string_lossy())
|
||||
} else {
|
||||
format!(" {icon} {}", display_path)
|
||||
};
|
||||
ListItem::new(display_full).style(style)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ sort_by = "modified"
|
|||
sort_reverse = true
|
||||
sort_dir_first = true
|
||||
show_hidden = false
|
||||
show_symlink = true
|
||||
|
||||
[preview]
|
||||
tab_size = 2
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ pub struct Manager {
|
|||
|
||||
// Display
|
||||
pub show_hidden: bool,
|
||||
pub show_symlink: bool,
|
||||
}
|
||||
|
||||
impl Default for Manager {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ pub struct File {
|
|||
pub path: PathBuf,
|
||||
pub meta: Metadata,
|
||||
pub length: Option<u64>,
|
||||
pub link_to: Option<PathBuf>,
|
||||
pub is_link: bool,
|
||||
pub is_hidden: bool,
|
||||
pub is_selected: bool,
|
||||
|
|
@ -22,13 +23,15 @@ 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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue