Compare commits
9 commits
97bdfbc9d1
...
4afd424435
Author | SHA1 | Date | |
---|---|---|---|
4afd424435 | |||
0f2ed387b3 | |||
cd3c21cac7 | |||
9ae6daae32 | |||
e3183be5f1 | |||
ca4cac86f7 | |||
cb49c2cb7a | |||
6f7b7da871 | |||
d4bde2f918 |
8 changed files with 1811 additions and 264 deletions
|
@ -45,15 +45,76 @@ Header:children_add(function()
|
|||
end
|
||||
return ui.Span(ya.user_name() .. "@" .. ya.host_name() .. ":"):fg("blue")
|
||||
end, 500, Header.LEFT)
|
||||
-- startship prompt
|
||||
require("starship"):setup({
|
||||
-- Hide flags (such as filter, find and search). This is recommended for starship themes which
|
||||
-- are intended to go across the entire width of the terminal.
|
||||
hide_flags = false, -- Default: false
|
||||
-- Whether to place flags after the starship prompt. False means the flags will be placed before the prompt.
|
||||
flags_after_prompt = true, -- Default: true
|
||||
-- Custom starship configuration file to use
|
||||
config_file = "~/.config/starship_full.toml", -- Default: nil
|
||||
})
|
||||
-- git for yazi
|
||||
--git
|
||||
require("git"):setup()
|
||||
-- yatline dracula_theme
|
||||
local dracula_theme = require("yatline-dracula"):setup()
|
||||
-- yatline
|
||||
require("yatline"):setup({
|
||||
theme = dracula_theme,
|
||||
section_separator = { open = "", close = "" },
|
||||
part_separator = { open = "", close = "" },
|
||||
inverse_separator = { open = "", close = "" },
|
||||
show_background = false,
|
||||
tab_width = 0,
|
||||
|
||||
header_line = {
|
||||
left = {
|
||||
section_a = {
|
||||
{ type = "coloreds", custom = false, name = "tab_path" },
|
||||
{type = "line", custom = false, name = "tabs", params = {"left"}},
|
||||
},
|
||||
section_b = {
|
||||
{type = "coloreds", custom = false, name = "githead"},
|
||||
},
|
||||
section_c = {
|
||||
}
|
||||
},
|
||||
right = {
|
||||
section_a = {
|
||||
|
||||
|
||||
},
|
||||
section_b = {
|
||||
|
||||
},
|
||||
section_c = {
|
||||
{type = "coloreds", custom = false, name = "count"},
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
status_line = {
|
||||
left = {
|
||||
section_a = {
|
||||
{type = "string", custom = false, name = "tab_mode"},
|
||||
},
|
||||
section_b = {
|
||||
{type = "string", custom = false, name = "hovered_size"},
|
||||
},
|
||||
section_c = {
|
||||
|
||||
{type = "string", custom = false, name = "hovered_path"},
|
||||
|
||||
}
|
||||
},
|
||||
right = {
|
||||
section_a = {
|
||||
{type = "string", custom = false, name = "cursor_position"},
|
||||
},
|
||||
section_b = {
|
||||
{type = "string", custom = false, name = "cursor_percentage"},
|
||||
},
|
||||
section_c = {
|
||||
|
||||
|
||||
{type = "coloreds", custom = false, name = "permissions"},
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
-- yatline-tab-path
|
||||
require("yatline-tab-path"):setup()
|
||||
-- yatline-githead
|
||||
require("yatline-githead"):setup()
|
||||
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2024 Rolv Apneseth
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -1,108 +0,0 @@
|
|||
# starship.yazi
|
||||
|
||||
Starship prompt plugin for [Yazi](https://github.com/sxyazi/yazi)
|
||||
|
||||
<https://github.com/Rolv-Apneseth/starship.yazi/assets/69486699/f7314687-5cb1-4d66-8d9d-cca960ba6716>
|
||||
|
||||
## Requirements
|
||||
|
||||
- [Yazi](https://github.com/sxyazi/yazi) (v25.4.8+)
|
||||
- [starship](https://github.com/starship/starship)
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
ya pack -a Rolv-Apneseth/starship
|
||||
```
|
||||
|
||||
### Manual
|
||||
|
||||
```sh
|
||||
# Linux / MacOS
|
||||
git clone https://github.com/Rolv-Apneseth/starship.yazi.git ~/.config/yazi/plugins/starship.yazi
|
||||
# Windows
|
||||
git clone https://github.com/Rolv-Apneseth/starship.yazi.git %AppData%\yazi\config\plugins\starship.yazi
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Add this to `~/.config/yazi/init.lua`:
|
||||
|
||||
```lua
|
||||
require("starship"):setup()
|
||||
```
|
||||
|
||||
Make sure you have [starship](https://github.com/starship/starship) installed and in your `PATH`.
|
||||
|
||||
## Config
|
||||
|
||||
Here is an example with all available config options:
|
||||
|
||||
```lua
|
||||
require("starship"):setup({
|
||||
-- Hide flags (such as filter, find and search). This is recommended for starship themes which
|
||||
-- are intended to go across the entire width of the terminal.
|
||||
hide_flags = false, -- Default: false
|
||||
-- Whether to place flags after the starship prompt. False means the flags will be placed before the prompt.
|
||||
flags_after_prompt = true, -- Default: true
|
||||
-- Custom starship configuration file to use
|
||||
config_file = "~/.config/starship_full.toml", -- Default: nil
|
||||
})
|
||||
```
|
||||
|
||||
## Extra
|
||||
|
||||
If you use a `starship` theme with a background colour, it might look a bit to cramped on just the one line `Yazi` gives the header by default. To fix this, you can add this to your `init.lua`:
|
||||
|
||||
<details>
|
||||
<summary>Click to expand</summary>
|
||||
|
||||
```lua
|
||||
local old_build = Tab.build
|
||||
|
||||
Tab.build = function(self, ...)
|
||||
local bar = function(c, x, y)
|
||||
if x <= 0 or x == self._area.w - 1 then
|
||||
return ui.Bar(ui.Bar.TOP):area(ui.Rect.default)
|
||||
end
|
||||
|
||||
return ui.Bar(ui.Bar.TOP)
|
||||
:area(ui.Rect({
|
||||
x = x,
|
||||
y = math.max(0, y),
|
||||
w = ya.clamp(0, self._area.w - x, 1),
|
||||
h = math.min(1, self._area.h),
|
||||
}))
|
||||
:symbol(c)
|
||||
end
|
||||
|
||||
local c = self._chunks
|
||||
self._chunks = {
|
||||
c[1]:pad(ui.Pad.y(1)),
|
||||
c[2]:pad(ui.Pad(1, c[3].w > 0 and 0 or 1, 1, c[1].w > 0 and 0 or 1)),
|
||||
c[3]:pad(ui.Pad.y(1)),
|
||||
}
|
||||
|
||||
local style = th.mgr.border_style
|
||||
self._base = ya.list_merge(self._base or {}, {
|
||||
ui.Bar(ui.Bar.RIGHT):area(self._chunks[1]):style(style),
|
||||
ui.Bar(ui.Bar.LEFT):area(self._chunks[1]):style(style),
|
||||
|
||||
bar("┬", c[1].right - 1, c[1].y),
|
||||
bar("┴", c[1].right - 1, c[1].bottom - 1),
|
||||
bar("┬", c[2].right, c[2].y),
|
||||
bar("┴", c[2].right, c[2].bottom - 1),
|
||||
})
|
||||
|
||||
old_build(self, ...)
|
||||
end
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
> [!NOTE]
|
||||
> This works by overriding your `Tab.build` function so make sure this is the only place you're doing that in your config. For example, this would be incompatible with the [full-border plugin](https://github.com/yazi-rs/plugins/tree/main/full-border.yazi)
|
||||
|
||||
## Thanks
|
||||
|
||||
- [sxyazi](https://github.com/sxyazi) for providing the code for this plugin and the demo video [in this comment](https://github.com/sxyazi/yazi/issues/767#issuecomment-1977082834)
|
|
@ -1,123 +0,0 @@
|
|||
--- @since 25.4.8
|
||||
|
||||
-- For development
|
||||
--[[ local function notify(message) ]]
|
||||
--[[ ya.notify({ title = "Starship", content = message, timeout = 3 }) ]]
|
||||
--[[ end ]]
|
||||
|
||||
local save = ya.sync(function(st, _cwd, output)
|
||||
st.output = output
|
||||
ya.render()
|
||||
end)
|
||||
|
||||
-- Helper function for accessing the `config_file` state variable
|
||||
---@return string
|
||||
local get_config_file = ya.sync(function(st)
|
||||
return st.config_file
|
||||
end)
|
||||
|
||||
return {
|
||||
---User arguments for setup method
|
||||
---@class SetupArgs
|
||||
---@field config_file string Absolute path to a starship config file
|
||||
---@field hide_flags boolean Whether to hide all flags (such as filter and search). Recommended for themes which are intended to take the full width of the terminal.
|
||||
---@field flags_after_prompt boolean Whether to place flags (such as filter and search) after the starship prompt. By default this is true.
|
||||
|
||||
--- Setup plugin
|
||||
--- @param st table State
|
||||
--- @param args SetupArgs|nil
|
||||
setup = function(st, args)
|
||||
local hide_flags = false
|
||||
local flags_after_prompt = true
|
||||
|
||||
-- Check setup args
|
||||
if args ~= nil then
|
||||
if args.config_file ~= nil then
|
||||
local url = Url(args.config_file)
|
||||
if url.is_regular then
|
||||
local config_file = args.config_file
|
||||
|
||||
-- Manually replace '~' and '$HOME' at the start of the path with the OS environment variable
|
||||
local home = os.getenv("HOME")
|
||||
if home then
|
||||
home = tostring(home)
|
||||
config_file = config_file:gsub("^~", home):gsub("^$HOME", home)
|
||||
end
|
||||
|
||||
st.config_file = config_file
|
||||
end
|
||||
end
|
||||
|
||||
if args.hide_flags ~= nil then
|
||||
hide_flags = args.hide_flags
|
||||
end
|
||||
|
||||
if args.flags_after_prompt ~= nil then
|
||||
flags_after_prompt = args.flags_after_prompt
|
||||
end
|
||||
end
|
||||
|
||||
-- Replace default header widget
|
||||
Header:children_remove(1, Header.LEFT)
|
||||
Header:children_add(function(self)
|
||||
local max = self._area.w - self._right_width
|
||||
if max <= 0 then
|
||||
return ""
|
||||
end
|
||||
|
||||
if hide_flags or not st.output then
|
||||
return ui.Line.parse(st.output or "")
|
||||
end
|
||||
|
||||
-- Split `st.output` at the first line break (or keep as is if none was found)
|
||||
local output = st.output:match("([^\n]*)\n?") or st.output
|
||||
|
||||
local flags = self:flags()
|
||||
if flags_after_prompt then
|
||||
output = output .. " " .. flags
|
||||
else
|
||||
output = flags .. " " .. output
|
||||
end
|
||||
|
||||
return ui.Line.parse(output)
|
||||
end, 1000, Header.LEFT)
|
||||
|
||||
-- Pass current working directory and custom config path (if specified) to the plugin's entry point
|
||||
---Callback for subscribers to update the prompt
|
||||
local callback = function()
|
||||
local cwd = cx.active.current.cwd
|
||||
if st.cwd ~= cwd then
|
||||
st.cwd = cwd
|
||||
|
||||
ya.manager_emit("plugin", {
|
||||
st._id,
|
||||
ya.quote(tostring(cwd), true),
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
-- Subscribe to events
|
||||
ps.sub("cd", callback)
|
||||
ps.sub("tab", callback)
|
||||
end,
|
||||
|
||||
entry = function(_, job)
|
||||
local args = job.args
|
||||
local command = Command("starship")
|
||||
:arg("prompt")
|
||||
:stdin(Command.INHERIT)
|
||||
:cwd(args[1])
|
||||
:env("STARSHIP_SHELL", "")
|
||||
|
||||
-- Point to custom starship config
|
||||
local config_file = get_config_file()
|
||||
if config_file then
|
||||
command = command:env("STARSHIP_CONFIG", config_file)
|
||||
end
|
||||
|
||||
local output = command:output()
|
||||
if output then
|
||||
save(args[1], output.stdout:gsub("^%s+", ""))
|
||||
end
|
||||
end,
|
||||
}
|
62
.config/yazi/plugins/yatline-dracula.yazi/main.lua
Normal file
62
.config/yazi/plugins/yatline-dracula.yazi/main.lua
Normal file
|
@ -0,0 +1,62 @@
|
|||
--==================--
|
||||
-- Dracula Theme --
|
||||
--==================--
|
||||
|
||||
local dracula_palette = {
|
||||
bg = "#282a36", -- Dracula background
|
||||
bg_highlight = "#44475a", -- Dracula current line/selection
|
||||
fg = "#f8f8f2", -- Dracula foreground
|
||||
blue = "#6272a4", -- Dracula comment
|
||||
cyan = "#8be9fd", -- Dracula cyan
|
||||
green = "#50fa7b", -- Dracula green
|
||||
orange = "#ffb86c", -- Dracula orange
|
||||
pink = "#ff79c6", -- Dracula pink
|
||||
purple = "#bd93f9", -- Dracula purple
|
||||
red = "#ff5555", -- Dracula red
|
||||
yellow = "#f1fa8c", -- Dracula yellow
|
||||
}
|
||||
|
||||
--- Gets the Dracula theme.
|
||||
--- @return table theme Used in Yatline.
|
||||
local function dracula_theme()
|
||||
local palette = dracula_palette
|
||||
|
||||
return {
|
||||
section_separator = { open = "", close = "" },
|
||||
part_separator = { open = "", close = "" },
|
||||
inverse_separator = { open = "", close = "" },
|
||||
---#=== yatline ===#---
|
||||
style_a = {
|
||||
fg = palette.bg,
|
||||
bg_mode = {
|
||||
normal = palette.purple, -- Using purple as primary mode color
|
||||
select = palette.pink, -- Using pink for select mode
|
||||
un_set = palette.red, -- Keeping red for unset mode
|
||||
},
|
||||
},
|
||||
style_b = { bg = palette.blue, fg = palette.fg },
|
||||
style_c = { bg = palette.bg_highlight, fg = palette.fg },
|
||||
|
||||
permissions_t_fg = palette.cyan, -- Using cyan for 't' permissions
|
||||
permissions_r_fg = palette.yellow, -- Using yellow for 'r' permissions
|
||||
permissions_w_fg = palette.red, -- Using red for 'w' permissions
|
||||
permissions_x_fg = palette.green, -- Using green for 'x' permissions
|
||||
permissions_s_fg = palette.fg, -- Using default fg for 's' permissions
|
||||
|
||||
selected = { icon = "", fg = palette.pink }, -- Using pink for selected items
|
||||
copied = { icon = "", fg = palette.green }, -- Using green for copied items
|
||||
cut = { icon = "", fg = palette.red }, -- Using red for cut items
|
||||
|
||||
total = { icon = "", fg = palette.yellow }, -- Using yellow for totals
|
||||
succ = { icon = "", fg = palette.green }, -- Using green for success
|
||||
fail = { icon = "", fg = palette.red }, -- Using red for failures
|
||||
found = { icon = "", fg = palette.cyan }, -- Using cyan for found items
|
||||
processed = { icon = "", fg = palette.orange }, -- Using orange for processed items
|
||||
}
|
||||
end
|
||||
|
||||
return {
|
||||
setup = function()
|
||||
return dracula_theme()
|
||||
end,
|
||||
}
|
314
.config/yazi/plugins/yatline-githead.yazi/main.lua
Normal file
314
.config/yazi/plugins/yatline-githead.yazi/main.lua
Normal file
|
@ -0,0 +1,314 @@
|
|||
---@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
|
||||
|
||||
if this.cwd ~= cwd then
|
||||
this.cwd = cwd
|
||||
ya.manager_emit("plugin", {
|
||||
this._id,
|
||||
ya.quote(tostring(cwd), true),
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
ps.sub("cd", callback)
|
||||
ps.sub("tab", callback)
|
||||
|
||||
if Yatline ~= nil then
|
||||
function Yatline.coloreds.get:githead()
|
||||
local status = this.output
|
||||
local githead = {}
|
||||
|
||||
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")
|
||||
:args({ "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,
|
||||
}
|
1362
.config/yazi/plugins/yatline.yazi/main.lua
Normal file
1362
.config/yazi/plugins/yatline.yazi/main.lua
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
[manager]
|
||||
show_hidden = true
|
||||
linemode = "size_and_mtime"
|
||||
linemode = "owner"
|
||||
|
||||
[plugin]
|
||||
prepend_previewers = [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue