Last active
April 3, 2026 03:08
-
-
Save zhangchitc/8d9a9f409dab269d5b439151f9404a9f to your computer and use it in GitHub Desktop.
my yazi config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ============================================================ | |
| File: init.lua | |
| ============================================================ | |
| require("zoxide"):setup { | |
| update_db = true, | |
| } | |
| ============================================================ | |
| File: package.toml | |
| ============================================================ | |
| [[plugin.deps]] | |
| use = "yazi-rs/plugins:piper" | |
| rev = "1962818" | |
| hash = "384464b6df8cb807425c521f8cd790f3" | |
| [flavor] | |
| deps = [] | |
| ============================================================ | |
| File: yazi.toml | |
| ============================================================ | |
| [mgr] | |
| ratio = [1, 3, 4] | |
| [[plugin.prepend_previewers]] | |
| url = "*.md" | |
| run = 'piper -- CLICOLOR_FORCE=1 glow -w=$w -s=dark "$1"' | |
| [opener] | |
| play = [ | |
| { run = 'mpv "$@"', block = true, desc = "Play with mpv" }, | |
| ] | |
| [[open.prepend_rules]] | |
| mime = "video/*" | |
| use = "play" | |
| ============================================================ | |
| File: plugins/piper.yazi/main.lua | |
| ============================================================ | |
| --- @since 26.1.22 | |
| 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.path) }) | |
| :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("\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 { mode = tonumber(lines[i]:sub(-1) == "/" and "40700" or "100644", 8) }, | |
| }):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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment