adde latex lsp and language

This commit is contained in:
liph22
2026-01-10 14:22:02 +01:00
parent b7cfdb00a3
commit d7b808ce59
32 changed files with 994 additions and 455 deletions

View File

@@ -0,0 +1,19 @@
Copyright (c) 2024 boydaihungst
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,110 @@
# file-extra-metadata
<!--toc:start-->
- [file-extra-metadata](#file-extra-metadata)
- [Preview](#preview)
- [Before:](#before)
- [After:](#after)
- [Requirements](#requirements)
- [Installation](#installation)
- [For developer](#for-developer)
<!--toc:end-->
This is a Yazi plugin that replaces the default file previewer and spotter with extra information.
> [!IMPORTANT]
> Minimum version: yazi v25.5.28
## Preview
### Before:
- Previewer
![Before preview](statics/2024-11-17-12-06-24.png)
- Spotter
![Before spot](statics/2025-12-29-before_spotter.png)
### After:
- Previewer
![After previewer](statics/2024-11-21-05-27-48.png)
- Spotter
![After spotter](statics/2025-12-29-after_spotter.png)
## Requirements
- [yazi >= 25.5.28](https://github.com/sxyazi/yazi)
- Tested on Linux. For MacOS, Windows: some fields will shows empty values.
## Installation
Install the plugin:
```sh
ya pkg add boydaihungst/file-extra-metadata
```
Create `~/.config/yazi/yazi.toml` and add:
For yazi < v25.12.29 (29/12/2025) replace `url` with `name`
```toml
[plugin]
append_previewers = [
{ url = "*", run = "file-extra-metadata" },
]
# Setup keybind for spotter: https://github.com/sxyazi/yazi/pull/1802
append_spotters = [
{ url = "*", run = "file-extra-metadata" },
]
```
or
```toml
[plugin]
previewers = [
# ... the rest
# disable default file plugin { name = "*", run = "file" },
{ url = "*", run = "file-extra-metadata" },
]
# Setup keybind for spotter: https://github.com/sxyazi/yazi/pull/1802
spotters = [
# ... the rest
# Fallback
# { name = "*", run = "file" },
{ url = "*", run = "file-extra-metadata" },
]
```
### Custom theme
Read more: https://github.com/sxyazi/yazi/pull/2391
Edit or add `yazi/theme.toml`:
```toml
[spot]
border = { fg = "#4fa6ed" }
title = { fg = "#4fa6ed" }
# Table.
tbl_cell = { fg = "#4fa6ed", reversed = true }
tbl_col = { fg = "#4fa6ed" }
```
## For developer
If you want to combine this with other spotter/previewer:
```lua
require("file-extra-metadata"):render_table(job, { show_plugins_section = true })
```

View File

@@ -0,0 +1,371 @@
--- @since 25.5.28
local M = {}
local STATE_KEY = {
ALTER_DF_COMMAND = "ALTER_DF_COMMAND",
}
local set_state = ya.sync(function(state, key, value)
state[key] = value
end)
local get_state = ya.sync(function(state, key)
return state[key]
end)
local function permission(file)
local h = file
if not h then
return ""
end
local perm = h.cha:perm()
if not perm then
return ""
end
local spans = ""
for i = 1, #perm do
local c = perm:sub(i, i)
spans = spans .. c
end
return spans
end
local function link_count(file)
local h = file
if h == nil or ya.target_family() ~= "unix" then
return ""
end
return h.cha.nlink
end
local function owner_group(file)
local h = file
if h == nil or ya.target_family() ~= "unix" then
return ""
end
return (ya.user_name(h.cha.uid) or tostring(h.cha.uid)) .. "/" .. (ya.group_name(h.cha.gid) or tostring(h.cha.gid))
end
local file_size_and_folder_childs = function(file)
local h = file
if not h then
return ""
end
return h.cha.len and ya.readable_size(h.cha.len) or ""
end
--- get file timestamp
---@param file any
---@param type "mtime" | "atime" | "btime"
---@return any
local function fileTimestamp(file, type)
local h = file
if not h then
return ""
end
local time = math.floor(h.cha[type] or 0)
if time == 0 then
return ""
else
return os.date("%Y-%m-%d %H:%M", time)
end
end
-- Function to split a string by spaces (considering multiple spaces as one delimiter)
local function split_by_whitespace(input)
local result = {}
for word in string.gmatch(input, "%S+") do
table.insert(result, word)
end
return result
end
local function get_filesystem_extra(file)
local result = {
filesystem = "",
device = "",
type = "",
used_space = "",
avail_space = "",
total_space = "",
used_space_percent = "",
avail_space_percent = "",
error = nil,
is_virtual = false,
}
local h = file
local file_url = h.url
local is_virtual = file_url.scheme and file_url.scheme.is_virtual
file_url = is_virtual and (file.path or Url(file_url.scheme.cache .. tostring(file_url.path)))
or (file_url.path or file_url.url)
if not h or ya.target_family() ~= "unix" then
return result
end
local output, child
local alter_df_command = get_state(STATE_KEY.ALTER_DF_COMMAND)
if not alter_df_command then
child, _ = Command("df"):arg({ "-P", "-T", "-h", tostring(file_url) }):stdout(Command.PIPED):spawn()
if child then
-- Ignore header
local _, event = child:read_line()
if event == 0 then
output, _ = child:read_line()
end
child:start_kill()
end
end
-- Fallback for macOS/BSD if -T failed (empty output or error)
if not output or output == "" then
if not alter_df_command then
set_state(STATE_KEY.ALTER_DF_COMMAND, true)
end
child, _ = Command("df"):arg({ "-P", "-h", tostring(file_url) }):stdout(Command.PIPED):spawn()
if child then
local _, event = child:read_line() -- skip header
if event == 0 then
output, _ = child:read_line()
end
child:start_kill()
end
end
if output and output ~= "" then
-- Splitting the data
local parts = split_by_whitespace(output)
-- Display the result
if #parts >= 7 then
result.filesystem = is_virtual and (parts[7] .. " (vfs)") or parts[7]
result.device = is_virtual and (parts[1] .. " (vfs)") or parts[1]
result.total_space = parts[3]
result.used_space = parts[4]
result.avail_space = parts[5]
result.used_space_percent = parts[6]
result.avail_space_percent = 100 - tonumber((string.match(parts[6], "%d+") or "0"))
result.type = is_virtual and (parts[2] .. " (vfs)") or parts[2]
else
result.filesystem = is_virtual and (parts[6] .. " (vfs)") or parts[6]
-- result.device (Type) is missing in df output, fetch from mount
result.total_space = parts[2]
result.used_space = parts[3]
result.avail_space = parts[4]
result.used_space_percent = parts[5]
result.avail_space_percent = 100 - tonumber((string.match(parts[5], "%d+") or "0"))
result.device = is_virtual and (parts[1] .. " (vfs)") or parts[1]
local mount_child = Command("mount"):stdout(Command.PIPED):spawn()
if mount_child then
while true do
local line, event = mount_child:read_line()
if not line or event ~= 0 then
break
end
-- Check if line starts with filesystem (e.g. /dev/disk1s1 on ...)
local s, e = line:find(parts[1] .. " on ", 1, true)
if s == 1 then
local fstype = line:match("%(([^,]+)")
if fstype then
result.type = is_virtual and (fstype .. " (vfs)") or fstype
end
break
end
end
end
end
result.is_virtual = is_virtual
else
result.error = "df error: check install"
end
return result
end
local function attributes(file)
local h = file
local file_url = h.url
if h.cha.is_link then
file_url = Url(h.link_to)
end
local is_virtual = file_url.scheme and file_url.scheme.is_virtual
file_url = is_virtual and (file.path or Url(file_url.scheme.cache .. tostring(file_url.path))) or file_url
if not h or ya.target_family() ~= "unix" then
return ""
end
local output, _ = Command("lsattr"):arg({ "-d", tostring(file_url) }):stdout(Command.PIPED):output()
if output then
-- Splitting the data
local parts = split_by_whitespace(output.stdout)
-- Display the result
for i, part in ipairs(parts) do
if i == 1 then
return part
end
end
return ""
else
return "lsattr error: check install"
end
end
---shorten string
---@param _s string string
---@param _t string tail
---@param _w number max characters
---@return string
local shorten = function(_s, _t, _w)
local s = _s or utf8.len(_s)
local t = _t or ""
local ellipsis = "" .. t
local w = _w < utf8.len(ellipsis) and utf8.len(ellipsis) or _w
local n_ellipsis = utf8.len(ellipsis) or 0
if utf8.len(s) > w then
return s:sub(1, (utf8.offset(s, w - n_ellipsis + 1) or 2) - 1) .. ellipsis
end
return s
end
function M:render_table(job, opts)
local styles = {
header = th.spot.title or ui.Style():fg("green"),
row_label = ui.Style():fg("reset"),
row_value = th.spot.tbl_col or ui.Style():fg("blue"),
}
local filesystem_extra = get_filesystem_extra(job.file)
local prefix = " "
local rows = {}
local label_max_length = 15
local file_name_extension = job.file.cha.is_dir and "" or ("." .. (job.file.url.ext or ""))
local row = function(key, value)
local h = type(value) == "table" and #value or 1
rows[#rows + 1] = ui.Row({ ui.Line(key):style(styles.row_label), ui.Text(value):style(styles.row_value) })
:height(h)
end
local file_name = shorten(
job.file.name,
file_name_extension,
math.floor(job.area.w - label_max_length - utf8.len(file_name_extension))
)
local location = shorten(
tostring((job.file.url.path or job.file.url).parent),
"",
math.floor(job.area.w - label_max_length - utf8.len(prefix))
)
local filesystem_error = filesystem_extra.error
and shorten(filesystem_extra.error, "", math.floor(job.area.w - label_max_length - utf8.len(prefix)))
or nil
local filesystem =
shorten(filesystem_extra.filesystem, "", math.floor(job.area.w - label_max_length - utf8.len(prefix)))
rows[#rows + 1] = ui.Row({ "Metadata", "" }):style(styles.header)
row(prefix .. "File:", file_name)
row(prefix .. "Mimetype:", job.mime)
row(prefix .. "Location:", location)
if job.file.cache then
row(prefix .. "Cached:", tostring(job.file.path or job.file.cache))
end
row(prefix .. "Mode:", permission(job.file))
row(prefix .. "Attributes:", attributes(job.file))
row(prefix .. "Links:", tostring(link_count(job.file)))
if job.file.cha.is_link then
row(prefix .. "Linked:", tostring(job.file.cha.is_link and job.file.link_to))
end
row(prefix .. "Owner:", owner_group(job.file))
row(prefix .. "Size:", file_size_and_folder_childs(job.file))
row(prefix .. "Created:", fileTimestamp(job.file, "btime"))
row(prefix .. "Modified:", fileTimestamp(job.file, "mtime"))
row(prefix .. "Accessed:", fileTimestamp(job.file, "atime"))
row(prefix .. "Filesystem:", filesystem_error or filesystem)
row(prefix .. "Device:", filesystem_error or filesystem_extra.device)
row(prefix .. "Type:", filesystem_error or filesystem_extra.type)
row(
prefix .. "Free space:",
filesystem_error
or (
(
filesystem_extra.avail_space
and filesystem_extra.total_space
and filesystem_extra.avail_space_percent
)
and (filesystem_extra.avail_space .. " / " .. filesystem_extra.total_space .. " (" .. filesystem_extra.avail_space_percent .. "%)")
or ""
)
)
if opts and opts.show_plugins_section then
-- TODO: Remove this after the next release
local is_yazi_nightly, _ = pcall(require, "mime.dir")
local spotter = rt.plugin.spotter(is_yazi_nightly and job.file or job.file.url, job.mime)
local previewer = rt.plugin.previewer(is_yazi_nightly and job.file or job.file.url, job.mime)
local fetchers = rt.plugin.fetchers(job.file, job.mime)
local preloaders = rt.plugin.preloaders(is_yazi_nightly and job.file or job.file.url, job.mime)
for i, v in ipairs(fetchers) do
fetchers[i] = v.cmd
end
for i, v in ipairs(preloaders) do
preloaders[i] = v.cmd
end
rows[#rows + 1] = ui.Row({ { "", "Plugins" }, "" }):height(2):style(styles.header)
row(prefix .. "Spotter:", spotter and spotter.cmd or "(none)")
row(prefix .. "Previewer:", previewer and previewer.cmd or "(none)")
row(prefix .. "Fetchers:", #fetchers ~= 0 and fetchers or "(none)")
row(prefix .. "Preloaders:", #preloaders ~= 0 and preloaders or "(none)")
end
return ui.Table(rows):area(job.area):row(1):col(1):col_style(styles.row_value):widths({
ui.Constraint.Length(label_max_length),
ui.Constraint.Fill(1),
})
end
function M:peek(job)
local start, cache = os.clock(), ya.file_cache(job)
if not cache or not self:preload(job) then
return 1
end
ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock()))
ya.preview_widget(job, { self:render_table(job) })
end
function M:seek(job)
local h = cx.active.current.hovered
if h and h.url == job.file.url then
local step = math.floor(job.units * job.area.h / 10)
ya.emit("peek", {
tostring(math.max(0, cx.active.preview.skip + step)),
only_if = tostring(job.file.url),
})
end
end
function M:preload(job)
local cache = ya.file_cache(job)
if not cache or fs.cha(cache) then
return true
end
return true
end
function M:spot(job)
job.area = ui.Pos({ "center", w = 80, h = 25 })
ya.spot_table(
job,
self:render_table(job, { show_plugins_section = true })
:cell_style(th.spot.tbl_cell or ui.Style():fg("blue"):reverse())
)
end
return M

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 yazi-rs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,32 @@
# full-border.yazi
Add a full border to Yazi to make it look fancier.
![full-border](https://github.com/yazi-rs/plugins/assets/17523360/ef81b560-2465-4d36-abf2-5d21dcb7b987)
## Installation
```sh
ya pkg add yazi-rs/plugins:full-border
```
## Usage
Add this to your `init.lua` to enable the plugin:
```lua
require("full-border"):setup()
```
Or you can customize the border type:
```lua
require("full-border"):setup {
-- Available values: ui.Border.PLAIN, ui.Border.ROUNDED
type = ui.Border.ROUNDED,
}
```
## License
This plugin is MIT-licensed. For more information check the [LICENSE](LICENSE) file.

View File

@@ -0,0 +1,43 @@
--- @since 25.2.26
local function setup(_, opts)
local type = opts and opts.type or ui.Border.ROUNDED
local old_build = Tab.build
Tab.build = function(self, ...)
local bar = function(c, x, y)
if x <= 0 or x == self._area.w - 1 or th.mgr.border_symbol ~= "" then
return ui.Bar(ui.Edge.TOP)
end
return ui.Bar(ui.Edge.TOP)
:area(
ui.Rect { x = x, y = math.max(0, y), w = ya.clamp(0, self._area.w - x, 1), h = math.min(1, self._area.h) }
)
:symbol(c)
end
local c = self._chunks
self._chunks = {
c[1]:pad(ui.Pad.y(1)),
c[2]:pad(ui.Pad(1, c[3].w > 0 and 0 or 1, 1, c[1].w > 0 and 0 or 1)),
c[3]:pad(ui.Pad.y(1)),
}
local style = th.mgr.border_style
self._base = ya.list_merge(self._base or {}, {
ui.Border(ui.Edge.ALL):area(self._area):type(type):style(style),
ui.Bar(ui.Edge.RIGHT):area(self._chunks[1]):style(style),
ui.Bar(ui.Edge.LEFT):area(self._chunks[3]):style(style),
bar("", c[1].right - 1, c[1].y),
bar("", c[1].right - 1, c[1].bottom - 1),
bar("", c[2].right, c[2].y),
bar("", c[2].right, c[2].bottom - 1),
})
old_build(self, ...)
end
end
return { setup = setup }