1
0
Fork 0

various changes I don't remember.. again, lol

This commit is contained in:
Peter Domínguez 2026-02-28 13:39:46 -04:00
parent 06508d53ac
commit a3faa34f5e
13 changed files with 425 additions and 485 deletions

View file

@ -1,4 +1,4 @@
--- @since 25.5.31
--- @since 25.12.29
local selected_or_hovered = ya.sync(function()
local tab, paths = cx.active, {}
@ -11,6 +11,15 @@ local selected_or_hovered = ya.sync(function()
return paths
end)
local function fail(s, ...)
ya.notify {
title = "Chmod",
content = string.format(s, ...),
level = "error",
timeout = 5,
}
end
return {
entry = function()
ya.emit("escape", { visual = true })
@ -23,20 +32,16 @@ return {
local value, event = ya.input {
title = "Chmod:",
pos = { "top-center", y = 3, w = 40 },
position = { "top-center", y = 3, w = 40 }, -- TODO: remove
}
if event ~= 1 then
return
end
local status, err = Command("chmod"):arg(value):arg(urls):spawn():wait()
if not status or not status.success then
ya.notify {
title = "Chmod",
content = string.format("Chmod on selected files failed, error: %s", status and status.code or err),
level = "error",
timeout = 5,
}
local output, err = Command("chmod"):arg(value):arg(urls):stderr(Command.PIPED):output()
if not output then
fail("Failed to run chmod: %s", err)
elseif not output.status.success then
fail("Chmod failed with stderr:\n%s", output.stderr:gsub("^chmod:%s*", ""))
end
end,
}

View file

@ -22,19 +22,19 @@ And register it as fetchers in your `~/.config/yazi/yazi.toml`:
```toml
[[plugin.prepend_fetchers]]
id = "git"
name = "*"
run = "git"
id = "git"
url = "*"
run = "git"
[[plugin.prepend_fetchers]]
id = "git"
name = "*/"
run = "git"
id = "git"
url = "*/"
run = "git"
```
## Advanced
> [!NOTE]
> [!NOTE]
> The following configuration must be put before `require("git"):setup()`
You can customize the [Style](https://yazi-rs.github.io/docs/plugins/layout#style) of the status sign with:

View file

@ -1,4 +1,4 @@
--- @since 25.5.31
--- @since 25.12.29
local WINDOWS = ya.target_family() == "windows"
@ -125,12 +125,7 @@ local add = ya.sync(function(st, cwd, repo, changed)
st.repos[repo][path] = code
end
end
-- TODO: remove this
if ui.render then
ui.render()
else
ya.render()
end
ui.render()
end)
---@param cwd string
@ -142,12 +137,7 @@ local remove = ya.sync(function(st, cwd)
return
end
-- TODO: remove this
if ui.render then
ui.render()
else
ya.render()
end
ui.render()
st.dirs[cwd] = nil
if not st.repos[repo] then
return
@ -189,8 +179,12 @@ local function setup(st, opts)
}
Linemode:children_add(function(self)
if not self._file.in_current then
return ""
end
local url = self._file.url
local repo = st.dirs[tostring(url.base)]
local repo = st.dirs[tostring(url.base or url.parent)]
local code
if repo then
code = repo == CODES.excluded and CODES.ignored or st.repos[repo][tostring(url):sub(#repo + 2)]
@ -208,7 +202,7 @@ end
---@type UnstableFetcher
local function fetch(_, job)
local cwd = job.files[1].url.base
local cwd = job.files[1].url.base or job.files[1].url.parent
local repo = root(cwd)
if not repo then
remove(tostring(cwd))

View file

@ -35,26 +35,35 @@ Make sure you have [ouch](https://github.com/ouch-org/ouch) installed and in you
For archive preview, add this to your `yazi.toml`:
```toml
[plugin]
prepend_previewers = [
# Archive previewer
{ mime = "application/*zip", run = "ouch" },
{ mime = "application/x-tar", run = "ouch" },
{ mime = "application/x-bzip2", run = "ouch" },
{ mime = "application/x-7z-compressed", run = "ouch" },
{ mime = "application/x-rar", run = "ouch" },
{ mime = "application/vnd.rar", run = "ouch" },
{ mime = "application/x-xz", run = "ouch" },
{ mime = "application/xz", run = "ouch" },
{ mime = "application/x-zstd", run = "ouch" },
{ mime = "application/zstd", run = "ouch" },
{ mime = "application/java-archive", run = "ouch" },
]
[[plugin.prepend_previewers]]
mime = "application/{*zip,tar,bzip2,7z*,rar,xz,zstd,java-archive}"
run = "ouch"
```
Now go to an archive on Yazi, you should see the archive's content in the preview pane. You can use `J` and `K` to roll up and down the preview.
If you want to change the icon or the style of text, you can modify the `peek` function in `init.lua` file (all of them are stored in the `lines` variable).
#### Customization
Previews can be customized by adding extra arguments in the `run` string:
```toml
[plugin]
prepend_previewers = [
# Change the top-level archive icon
{ ..., run = "ouch --archive-icon='🗄️ '" },
# Or remove it by setting it to ''
{ ..., run = "ouch --archive-icon=''" },
# Enable file icons
{ ..., run = "ouch --show-file-icons" },
# Disable tree view
{ ..., run = "ouch --list-view" },
# These can be combined
{ ..., run = "ouch --archive-icon='🗄️ ' --show-file-icons --list-view" },
]
```
### Compression
For compession, add this to your `keymap.toml`:

View file

@ -1,15 +1,50 @@
local M = {}
-- Extract the tree prefix (if any) from a line
local function get_tree_prefix(line)
local _, prefix_len = line:find("", 1, true)
if prefix_len then
return line:sub(1, prefix_len)
else
return ""
end
end
-- Add a filetype icon to a line
local function line_with_icon(line)
line = line:gsub("[\r\n]+$", "") -- Trailing newlines mess with filetype detection
local tree_prefix = get_tree_prefix(line)
local url = line:sub(#tree_prefix + 1)
local icon = File({
url = Url(url),
cha = Cha {
mode = tonumber(url:sub(-1) == "/" and "40700" or "100644", 8),
kind = url:sub(-1) == "/" and 1 or 0, -- For Yazi <25.9.x compatibility
}
}):icon()
if icon then
line = ui.Line { tree_prefix, ui.Span(icon.text .. " "):style(icon.style), url }
end
return line
end
function M:peek(job)
local child = Command("ouch")
:arg({ "l", "-t", "-y", tostring(job.file.url) })
local cmd = Command("ouch"):arg("l")
if not job.args.list_view then
cmd:arg("-t")
end
cmd:arg({ "-y", tostring(job.file.url) })
:stdout(Command.PIPED)
:stderr(Command.PIPED)
:spawn()
local child = cmd:spawn()
local limit = job.area.h
local archive_icon = job.args.archive_icon or "\u{1f4c1} "
local file_name = string.match(tostring(job.file.url), ".*[/\\](.*)")
local lines = string.format("\u{1f4c1} %s\n", file_name)
local num_lines = 1
local lines = { string.format(" %s%s", archive_icon, file_name) }
local num_skip = 0
repeat
local line, event = child:read_line()
@ -21,19 +56,29 @@ function M:peek(job)
if line:find('Archive', 1, true) ~= 1 and line:find('[INFO]', 1, true) ~= 1 then
if num_skip >= job.skip then
lines = lines .. line
num_lines = num_lines + 1
if job.args.show_file_icons then
if line:find ('[ERROR]', 1, true) == 1 then
-- On error, disable file icons for the rest of the output
job.args.show_file_icons = false
elseif line:find ('[WARNING]', 1, true) ~= 1 then
-- Show icons for non-warning lines only
line = line_with_icon(line)
end
end
line = ui.Line { " ", line } -- One space padding
table.insert(lines, line)
else
num_skip = num_skip + 1
end
end
until num_lines >= limit
until #lines >= limit
child:start_kill()
if job.skip > 0 and num_lines < limit then
if job.skip > 0 and #lines < limit then
ya.emit(
"peek",
{ tostring(math.max(0, job.skip - (limit - num_lines))), only_if = tostring(job.file.url), upper_bound = "" }
{ tostring(math.max(0, job.skip - (limit - #lines))), only_if = tostring(job.file.url), upper_bound = "" }
)
else
ya.preview_widget(job, { ui.Text(lines):area(job.area) })

View file

@ -1,320 +0,0 @@
---@diagnostic disable: undefined-global
local save = ya.sync(function(this, cwd, output)
if cx.active.current.cwd == Url(cwd) then
this.output = output
ya.render()
end
end)
return {
setup = function(this, options)
options = options or {}
local config = {
show_branch = options.show_branch == nil and true or options.show_branch,
branch_prefix = options.branch_prefix or "on",
branch_symbol = options.branch_symbol or "",
branch_borders = options.branch_borders or "()",
commit_symbol = options.commit_symbol or "@",
show_behind_ahead = options.behind_ahead == nil and true or options.behind_ahead,
behind_symbol = options.behind_symbol or "",
ahead_symbol = options.ahead_symbol or "",
show_stashes = options.show_stashes == nil and true or options.show_stashes,
stashes_symbol = options.stashes_symbol or "$",
show_state = options.show_state == nil and true or options.show_state,
show_state_prefix = options.show_state_prefix == nil and true or options.show_state_prefix,
state_symbol = options.state_symbol or "~",
show_staged = options.show_staged == nil and true or options.show_staged,
staged_symbol = options.staged_symbol or "+",
show_unstaged = options.show_unstaged == nil and true or options.show_unstaged,
unstaged_symbol = options.unstaged_symbol or "!",
show_untracked = options.show_untracked == nil and true or options.show_untracked,
untracked_symbol = options.untracked_symbol or "?",
}
if options.theme then
options = options.theme
end
local theme = {
prefix_color = options.prefix_color or "white",
branch_color = options.branch_color or "blue",
commit_color = options.commit_color or "bright magenta",
behind_color = options.behind_color or "bright magenta",
ahead_color = options.ahead_color or "bright magenta",
stashes_color = options.stashes_color or "bright magenta",
state_color = options.state_color or "red",
staged_color = options.staged_color or "bright yellow",
unstaged_color = options.unstaged_color or "bright yellow",
untracked_color = options.untracked_color or "bright blue",
}
local function get_branch(status)
local branch = status:match("On branch (%S+)")
if branch == nil then
local commit = status:match("onto (%S+)") or status:match("detached at (%S+)")
if commit == nil then
return ""
else
local branch_prefix = config.branch_prefix == "" and " " or " " .. config.branch_prefix .. " "
local commit_prefix = config.commit_symbol == "" and "" or config.commit_symbol
return { "commit", branch_prefix .. commit_prefix, commit }
end
else
local left_border = config.branch_borders:sub(1, 1)
local right_border = config.branch_borders:sub(2, 2)
local branch_string = ""
if config.branch_symbol == "" then
branch_string = left_border .. branch .. right_border
else
branch_string = left_border .. config.branch_symbol .. " " .. branch .. right_border
end
local branch_prefix = config.branch_prefix == "" and " " or " " .. config.branch_prefix .. " "
return { "branch", branch_prefix, branch_string }
end
end
local function get_behind_ahead(status)
local diverged_ahead, diverged_behind = status:match("have (%d+) and (%d+) different")
if diverged_ahead and diverged_behind then
return { " " .. config.behind_symbol .. diverged_behind, config.ahead_symbol .. diverged_ahead }
else
local behind = status:match("behind %S+ by (%d+) commit")
local ahead = status:match("ahead of %S+ by (%d+) commit")
if ahead then
return { "", " " .. config.ahead_symbol .. ahead }
elseif behind then
return { " " .. config.behind_symbol .. behind, "" }
else
return ""
end
end
end
local function get_stashes(status)
local stashes = tonumber(status:match("Your stash currently has (%S+)"))
return stashes ~= nil and " " .. config.stashes_symbol .. stashes or ""
end
local function get_state(status)
local result = status:match("Unmerged paths:%s*(.-)%s*\n\n")
if result then
local filtered_result = result:gsub("^[%s]*%b()[%s]*", ""):gsub("^[%s]*%b()[%s]*", "")
local unmerged = 0
for line in filtered_result:gmatch("[^\r\n]+") do
if line:match("%S") then
unmerged = unmerged + 1
end
end
local state_name = ""
if config.show_state_prefix then
if status:find("git merge") then
state_name = "merge "
elseif status:find("git cherry%-pick") then
state_name = "cherry "
elseif status:find("git rebase") then
state_name = "rebase "
if status:find("done") then
local done = status:match("%((%d+) com.- done%)") or ""
state_name = state_name .. done .. "/" .. unmerged .. " "
end
else
state_name = ""
end
end
return " " .. state_name .. config.state_symbol .. unmerged
else
return ""
end
end
local function get_staged(status)
local result = status:match("Changes to be committed:%s*(.-)%s*\n\n")
if result then
local filtered_result = result:gsub("^[%s]*%b()[%s]*", "")
local staged = 0
for line in filtered_result:gmatch("[^\r\n]+") do
if line:match("%S") then
staged = staged + 1
end
end
return " " .. config.staged_symbol .. staged
else
return ""
end
end
local function get_unstaged(status)
local result = status:match("Changes not staged for commit:%s*(.-)%s*\n\n")
if result then
local filtered_result = result:gsub("^[%s]*%b()[\r\n]*", ""):gsub("^[%s]*%b()[\r\n]*", "")
local unstaged = 0
for line in filtered_result:gmatch("[^\r\n]+") do
if line:match("%S") then
unstaged = unstaged + 1
end
end
return " " .. config.unstaged_symbol .. unstaged
else
return ""
end
end
local function get_untracked(status)
local result = status:match("Untracked files:%s*(.-)%s*\n\n")
if result then
local filtered_result = result:gsub("^[%s]*%b()[\r\n]*", "")
local untracked = 0
for line in filtered_result:gmatch("[^\r\n]+") do
if line:match("%S") then
untracked = untracked + 1
end
end
return " " .. config.untracked_symbol .. untracked
else
return ""
end
end
function Header:githead()
local status = this.output
local branch_array = get_branch(status)
local prefix = ui.Span(config.show_branch and branch_array[2] or ""):fg(theme.prefix_color)
local branch = ui.Span(config.show_branch and branch_array[3] or "")
:fg(branch_array[1] == "commit" and theme.commit_color or theme.branch_color)
local behind_ahead = get_behind_ahead(status)
local behind = ui.Span(config.show_behind_ahead and behind_ahead[1] or ""):fg(theme.behind_color)
local ahead = ui.Span(config.show_behind_ahead and behind_ahead[2] or ""):fg(theme.ahead_color)
local stashes = ui.Span(config.show_stashes and get_stashes(status) or ""):fg(theme.stashes_color)
local state = ui.Span(config.show_state and get_state(status) or ""):fg(theme.state_color)
local staged = ui.Span(config.show_staged and get_staged(status) or ""):fg(theme.staged_color)
local unstaged = ui.Span(config.show_unstaged and get_unstaged(status) or ""):fg(theme.unstaged_color)
local untracked = ui.Span(config.show_untracked and get_untracked(status) or ""):fg(theme.untracked_color)
return ui.Line({ prefix, branch, behind, ahead, stashes, state, staged, unstaged, untracked })
end
Header:children_add(Header.githead, 2000, Header.LEFT)
local callback = function()
local cwd = cx.active.current.cwd
ya.emit("plugin", {
this._id,
ya.quote(tostring(cwd), true),
})
end
ps.sub("cd", callback)
ps.sub("rename", callback)
ps.sub("bulk", callback)
ps.sub("move", callback)
ps.sub("trash", callback)
ps.sub("delete", callback)
ps.sub("tab", callback)
if Yatline ~= nil then
function Yatline.coloreds.get:githead()
local status = this.output
local githead = {}
if not status then
return githead
end
local branch = config.show_branch and get_branch(status) or ""
if branch ~= nil and branch ~= "" then
table.insert(githead, { branch[2], theme.prefix_color })
if branch[1] == "commit" then
table.insert(githead, { branch[3], theme.commit_color })
else
table.insert(githead, { branch[3], theme.branch_color })
end
end
local behind_ahead = config.show_behind_ahead and get_behind_ahead(status) or ""
if behind_ahead ~= nil and behind_ahead ~= "" then
if behind_ahead[1] ~= nil and behind_ahead[1] ~= "" then
table.insert(githead, { behind_ahead[1], theme.behind_color })
elseif behind_ahead[2] ~= nil and behind_ahead[2] ~= "" then
table.insert(githead, { behind_ahead[2], theme.ahead_color })
end
end
local stashes = config.show_stashes and get_stashes(status) or ""
if stashes ~= nil and stashes ~= "" then
table.insert(githead, { stashes, theme.stashes_color })
end
local state = config.show_state and get_state(status) or ""
if state ~= nil and state ~= "" then
table.insert(githead, { state, theme.state_color })
end
local staged = config.show_staged and get_staged(status) or ""
if staged ~= nil and staged ~= "" then
table.insert(githead, { staged, theme.staged_color })
end
local unstaged = config.show_unstaged and get_unstaged(status) or ""
if unstaged ~= nil and unstaged ~= "" then
table.insert(githead, { unstaged, theme.unstaged_color })
end
local untracked = config.show_untracked and get_untracked(status) or ""
if untracked ~= nil and untracked ~= "" then
table.insert(githead, { untracked, theme.untracked_color })
end
if #githead == 0 then
return ""
else
table.insert(githead, { " ", theme.prefix_color })
return githead
end
end
end
end,
entry = function(_, job)
local args = job.args or job
local command = Command("git")
:arg({ "status", "--ignore-submodules=dirty", "--branch", "--show-stash", "--ahead-behind" })
:cwd(args[1])
:env("LANGUAGE", "en_US.UTF-8")
:stdout(Command.PIPED)
local output = command:output()
if output then
save(args[1], output.stdout)
end
end,
}