feat: support customizing git status sign and style, closes #21

This commit is contained in:
sxyazi
2024-09-12 18:51:26 +08:00
parent 549d76614d
commit 0b9f325fe9
3 changed files with 50 additions and 11 deletions

View File

@@ -34,3 +34,42 @@ id = "git"
name = "*/" name = "*/"
run = "git" run = "git"
``` ```
## Advanced
> [!NOTE]
> This section currently requires Yazi nightly that includes https://github.com/sxyazi/yazi/pull/1637
You can customize the [Style](https://yazi-rs.github.io/docs/plugins/layout#style) of the status sign with:
- `THEME.git_modified`
- `THEME.git_added`
- `THEME.git_untracked`
- `THEME.git_ignored`
- `THEME.git_deleted`
- `THEME.git_updated`
For example:
```lua
-- ~/.config/yazi/init.lua
THEME.git_modified = ui.Style():fg("blue")
THEME.git_deleted = ui.Style():fg("red"):bold()
```
You can also customize the text of the status sign with:
- `THEME.git_modified_sign`
- `THEME.git_added_sign`
- `THEME.git_untracked_sign`
- `THEME.git_ignored_sign`
- `THEME.git_deleted_sign`
- `THEME.git_updated_sign`
For example:
```lua
-- ~/.config/yazi/init.lua
THEME.git_modified_sign = "M"
THEME.git_deleted_sign = "D"
```

View File

@@ -117,13 +117,13 @@ local function setup(st, opts)
[1] = THEME.git_updated and ui.Style(THEME.git_updated) or ui.Style():fg("#1e90ff"), [1] = THEME.git_updated and ui.Style(THEME.git_updated) or ui.Style():fg("#1e90ff"),
} }
-- TODO: Use nerd-font icons as default matching Yazi's default behavior -- TODO: Use nerd-font icons as default matching Yazi's default behavior
local icons = { local signs = {
[6] = THEME.git_modified and THEME.git_modified.icon or "*", [6] = THEME.git_modified_sign and THEME.git_modified_sign or "*",
[5] = THEME.git_added and THEME.git_added.icon or "+", [5] = THEME.git_added_sign and THEME.git_added_sign or "+",
[4] = THEME.git_untracked and THEME.git_untracked.icon or "?", [4] = THEME.git_untracked_sign and THEME.git_untracked_sign or "?",
[3] = THEME.git_ignored and THEME.git_ignored.icon or "!", [3] = THEME.git_ignored_sign and THEME.git_ignored_sign or "!",
[2] = THEME.git_deleted and THEME.git_deleted.icon or "-", [2] = THEME.git_deleted_sign and THEME.git_deleted_sign or "-",
[1] = THEME.git_updated and THEME.git_updated.icon or "U", [1] = THEME.git_updated_sign and THEME.git_updated_sign or "U",
} }
Linemode:children_add(function(self) Linemode:children_add(function(self)
@@ -134,12 +134,12 @@ local function setup(st, opts)
change = dir == "" and 3 or st.repos[dir][tostring(url):sub(#dir + 2)] change = dir == "" and 3 or st.repos[dir][tostring(url):sub(#dir + 2)]
end end
if not change or icons[change] == "" then if not change or signs[change] == "" then
return ui.Line("") return ui.Line("")
elseif self._file:is_hovered() then elseif self._file:is_hovered() then
return ui.Line { ui.Span(" "), ui.Span(icons[change]) } return ui.Line { ui.Span(" "), ui.Span(signs[change]) }
else else
return ui.Line { ui.Span(" "), ui.Span(icons[change]):style(styles[change]) } return ui.Line { ui.Span(" "), ui.Span(signs[change]):style(styles[change]) }
end end
end, opts.order) end, opts.order)
end end

View File

@@ -35,7 +35,7 @@ local function entry()
local h = hovered() local h = hovered()
if h.unique and h.is_dir then if h.unique and h.is_dir then
ya.manager_emit("escape", { filter = true }) ya.manager_emit("escape", { filter = true })
ya.manager_emit("enter", { h.url }) ya.manager_emit("enter", {})
input = prompt() input = prompt()
elseif event == 1 then elseif event == 1 then
ya.manager_emit("escape", { filter = true }) ya.manager_emit("escape", { filter = true })