summaryrefslogtreecommitdiff
path: root/fedora/.config/yazi/plugins/piper.yazi
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-12-11 11:46:09 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-12-11 11:46:09 +0900
commit8c0fe8d0d0dd4bbd16c1095e25b2e3ffa1fdb0d3 (patch)
tree597b8dfd730eda9b410fb6082b0bee7fcc7e70e2 /fedora/.config/yazi/plugins/piper.yazi
parent74713d79880967f5f0f8652c6741bc5fa63a8794 (diff)
updates
Diffstat (limited to 'fedora/.config/yazi/plugins/piper.yazi')
-rw-r--r--fedora/.config/yazi/plugins/piper.yazi/README.md90
-rw-r--r--fedora/.config/yazi/plugins/piper.yazi/main.lua70
2 files changed, 160 insertions, 0 deletions
diff --git a/fedora/.config/yazi/plugins/piper.yazi/README.md b/fedora/.config/yazi/plugins/piper.yazi/README.md
new file mode 100644
index 0000000..1cb238f
--- /dev/null
+++ b/fedora/.config/yazi/plugins/piper.yazi/README.md
@@ -0,0 +1,90 @@
+# piper.yazi
+
+Pipe any shell command as a previewer.
+
+## Installation
+
+```sh
+ya pkg add yazi-rs/plugins:piper
+```
+
+## Usage
+
+Piper is a general-purpose previewer - you can pass any shell command to `piper` and it will use the command's output as the preview content.
+
+It accepts a string parameter, which is the shell command to be executed, for example:
+
+```toml
+# ~/.config/yazi/yazi.toml
+[[plugin.prepend_previewers]]
+name = "*"
+run = 'piper -- echo "$1"'
+```
+
+This will set `piper` as the previewer for all file types and use `$1` (file path) as the preview content.
+
+## Variables
+
+Available variables:
+
+- `$w`: the width of the preview area.
+- `$h`: the height of the preview area.
+- `$1`: the path to the file being previewed.
+
+## Examples
+
+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
+[[plugin.prepend_previewers]]
+name = "*.csv"
+run = 'piper -- bat -p --color=always "$1"'
+```
+
+Note that certain distributions might use a different name for `bat`, like Debian and Ubuntu uses `batcat` instead, so please adjust accordingly.
+
+### Preview Markdown with [`glow`](https://github.com/charmbracelet/glow)
+
+```toml
+[[plugin.prepend_previewers]]
+name = "*.md"
+run = 'piper -- CLICOLOR_FORCE=1 glow -w=$w -s=dark "$1"'
+```
+
+Note that there's [a bug in Glow v2.0](https://github.com/charmbracelet/glow/issues/440#issuecomment-2307992634) that causes slight color differences between tty and non-tty environments.
+
+### Preview directory tree with [`eza`](https://github.com/eza-community/eza)
+
+```toml
+[[plugin.prepend_previewers]]
+name = "*/"
+run = 'piper -- eza -TL=3 --color=always --icons=always --group-directories-first --no-quotes "$1"'
+```
+
+### Use [`hexyl`](https://github.com/sharkdp/hexyl) as fallback previewer
+
+Yazi defaults to using [`file -bL "$1"`](https://github.com/sxyazi/yazi/blob/main/yazi-plugin/preset/plugins/file.lua) if there's no matched previewer.
+
+This example uses `hexyl` as a fallback previewer instead of `file`.
+
+```toml
+[[plugin.append_previewers]]
+name = "*"
+run = 'piper -- hexyl --border=none --terminal-width=$w "$1"'
+```
+
+## License
+
+This plugin is MIT-licensed. For more information check the [LICENSE](LICENSE) file.
diff --git a/fedora/.config/yazi/plugins/piper.yazi/main.lua b/fedora/.config/yazi/plugins/piper.yazi/main.lua
new file mode 100644
index 0000000..aef08eb
--- /dev/null
+++ b/fedora/.config/yazi/plugins/piper.yazi/main.lua
@@ -0,0 +1,70 @@
+--- @since 25.5.31
+
+local M = {}
+
+local function fail(job, s) ya.preview_widget(job, ui.Text.parse(s):area(job.area):wrap(ui.Wrap.YES)) end
+
+function M:peek(job)
+ local child, err = Command("sh")
+ :arg({ "-c", job.args[1], "sh", tostring(job.file.url) })
+ :env("w", job.area.w)
+ :env("h", job.area.h)
+ :stdout(Command.PIPED)
+ :stderr(Command.PIPED)
+ :spawn()
+
+ if not child then
+ return fail(job, "sh: " .. err)
+ end
+
+ local limit = job.area.h
+ local i, outs, errs = 0, {}, {}
+ repeat
+ local next, event = child:read_line()
+ if event == 1 then
+ errs[#errs + 1] = next
+ elseif event ~= 0 then
+ break
+ end
+
+ i = i + 1
+ if i > job.skip then
+ outs[#outs + 1] = next
+ end
+ until i >= job.skip + limit
+
+ child:start_kill()
+ if #errs > 0 then
+ fail(job, table.concat(errs, ""))
+ elseif job.skip > 0 and i < job.skip + limit then
+ ya.emit("peek", { math.max(0, i - limit), only_if = job.file.url, upper_bound = true })
+ else
+ ya.preview_widget(job, M.format(job, outs))
+ 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("\r", ""):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