Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "extension" linemode (m e) to show extensions of files #1036

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions yazi-config/preset/keymap.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ keymap = [
{ on = [ "m", "s" ], run = "linemode size", desc = "Set linemode to size" },
{ on = [ "m", "p" ], run = "linemode permissions", desc = "Set linemode to permissions" },
{ on = [ "m", "m" ], run = "linemode mtime", desc = "Set linemode to mtime" },
{ on = [ "m", "m" ], run = "linemode extension", desc = "Set linemode to extension" },
{ on = [ "m", "n" ], run = "linemode none", desc = "Set linemode to none" },

# Copy
Expand Down
2 changes: 2 additions & 0 deletions yazi-plugin/preset/components/folder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function Folder:linemode(area, files)
spans[#spans + 1] = ui.Span(time and os.date("%y-%m-%d %H:%M", time // 1) or "")
elseif mode == "permissions" then
spans[#spans + 1] = ui.Span(f.cha:permissions() or "")
elseif mode == "extension" then
spans[#spans + 1] = ui.Span(f.url:extension() or "")
end

spans[#spans + 1] = ui.Span(" ")
Expand Down
3 changes: 3 additions & 0 deletions yazi-plugin/src/url/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ impl Url {
reg.add_method("stem", |lua, me, ()| {
me.file_stem().map(|s| lua.create_string(s.as_encoded_bytes())).transpose()
});
reg.add_method("extension", |lua, me, ()| {
me.extension().map(|s| lua.create_string(s.as_encoded_bytes())).transpose()
});
reg.add_method("join", |lua, me, other: UrlRef| Self::cast(lua, me.join(&*other)));
reg.add_method("parent", |lua, me, ()| {
me.parent_url().map(|u| Self::cast(lua, u)).transpose()
Expand Down