docs: new example for previewing tarballs with tar

This commit is contained in:
sxyazi
2025-04-13 09:16:41 +08:00
parent 7112e91395
commit b12a9ab085
2 changed files with 35 additions and 6 deletions

View File

@@ -35,6 +35,16 @@ Available variables:
Here are some configuration examples:
### Preview tarballs with [`tar`](https://man7.org/linux/man-pages/man1/tar.1.html)
```toml
[[plugin.prepend_previewers]]
name = "*.tar*"
run = 'piper --format=url -- tar tf "$1"'
```
In this example, `--format=url` tells `piper` to parse the `tar` output as file URLs, so you'll be able to get a list of files with icons.
### Preview CSV with [`bat`](https://github.com/sharkdp/bat)
```toml

View File

@@ -26,7 +26,7 @@ function M:peek(job)
end
local limit = job.area.h
local i, lines = 0, ""
local i, lines = 0, {}
repeat
local next, event = child:read_line()
if event == 1 then
@@ -37,7 +37,7 @@ function M:peek(job)
i = i + 1
if i > job.skip then
lines = lines .. next
lines[#lines + 1] = next
end
until i >= job.skip + limit
@@ -45,13 +45,32 @@ function M:peek(job)
if job.skip > 0 and i < job.skip + limit then
ya.mgr_emit("peek", { math.max(0, i - limit), only_if = job.file.url, upper_bound = true })
else
lines = lines:gsub("\t", string.rep(" ", rt.preview.tab_size))
ya.preview_widgets(job, {
ui.Text.parse(lines):area(job.area),
})
ya.preview_widgets(job, { M.format(job, lines) })
end
end
function M:seek(job) require("code"):seek(job) end
function M.format(job, lines)
local format = job.args.format
if format ~= "url" then
local s = table.concat(lines, ""):gsub("\t", string.rep(" ", rt.preview.tab_size))
return ui.Text.parse(s):area(job.area)
end
for i = 1, #lines do
lines[i] = lines[i]:gsub("[\r\n]+$", "")
local icon = File({
url = Url(lines[i]),
cha = Cha { kind = lines[i]:sub(-1) == "/" and 1 or 0 },
}):icon()
if icon then
lines[i] = ui.Line { ui.Span(" " .. icon.text .. " "):style(icon.style), lines[i] }
end
end
return ui.Text(lines):area(job.area)
end
return M