mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: show symlink path (#67)
This commit is contained in:
parent
d3a0d56ce6
commit
1135c13d0f
5 changed files with 22 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use core::files::File;
|
use core::files::File;
|
||||||
|
|
||||||
use config::THEME;
|
use config::{MANAGER, THEME};
|
||||||
use ratatui::{buffer::Buffer, layout::Rect, style::Style, widgets::{List, ListItem, Widget}};
|
use ratatui::{buffer::Buffer, layout::Rect, style::Style, widgets::{List, ListItem, Widget}};
|
||||||
use shared::readable_path;
|
use shared::readable_path;
|
||||||
|
|
||||||
|
|
@ -80,7 +80,14 @@ impl<'a> Widget for Folder<'a> {
|
||||||
self.file_style(v)
|
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<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,11 @@
|
||||||
- `true`: Show
|
- `true`: Show
|
||||||
- `false`: Do not 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
|
## preview
|
||||||
|
|
||||||
- tab_size: Tab width
|
- tab_size: Tab width
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ sort_by = "modified"
|
||||||
sort_reverse = true
|
sort_reverse = true
|
||||||
sort_dir_first = true
|
sort_dir_first = true
|
||||||
show_hidden = false
|
show_hidden = false
|
||||||
|
show_symlink = true
|
||||||
|
|
||||||
[preview]
|
[preview]
|
||||||
tab_size = 2
|
tab_size = 2
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ pub struct Manager {
|
||||||
pub sort_dir_first: bool,
|
pub sort_dir_first: bool,
|
||||||
|
|
||||||
// Display
|
// Display
|
||||||
pub show_hidden: bool,
|
pub show_hidden: bool,
|
||||||
|
pub show_symlink: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Manager {
|
impl Default for Manager {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ pub struct File {
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
pub meta: Metadata,
|
pub meta: Metadata,
|
||||||
pub length: Option<u64>,
|
pub length: Option<u64>,
|
||||||
|
pub link_to: Option<PathBuf>,
|
||||||
pub is_link: bool,
|
pub is_link: bool,
|
||||||
pub is_hidden: bool,
|
pub is_hidden: bool,
|
||||||
pub is_selected: bool,
|
pub is_selected: bool,
|
||||||
|
|
@ -22,13 +23,16 @@ impl File {
|
||||||
|
|
||||||
pub async fn from_meta(path: &Path, mut meta: Metadata) -> File {
|
pub async fn from_meta(path: &Path, mut meta: Metadata) -> File {
|
||||||
let is_link = meta.is_symlink();
|
let is_link = meta.is_symlink();
|
||||||
|
let mut link_to = None;
|
||||||
|
|
||||||
if is_link {
|
if is_link {
|
||||||
meta = fs::metadata(&path).await.unwrap_or(meta);
|
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 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);
|
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