mirror of
https://github.com/sxyazi/yazi.git
synced 2024-12-19 23:01:36 +03:00
feat: show symlink path (#67)
This commit is contained in:
parent
d3a0d56ce6
commit
1135c13d0f
@ -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::<Vec<_>>();
|
||||
|
||||
|
@ -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
|
||||
|
@ -3,6 +3,7 @@ sort_by = "modified"
|
||||
sort_reverse = true
|
||||
sort_dir_first = true
|
||||
show_hidden = false
|
||||
show_symlink = true
|
||||
|
||||
[preview]
|
||||
tab_size = 2
|
||||
|
@ -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 {
|
||||
|
@ -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,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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user