better structure
This commit is contained in:
21
config/yazi/plugins/yaziline.yazi/LICENSE
Normal file
21
config/yazi/plugins/yaziline.yazi/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 llanosrocas
|
||||
|
||||
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.
|
||||
166
config/yazi/plugins/yaziline.yazi/README.md
Normal file
166
config/yazi/plugins/yaziline.yazi/README.md
Normal file
@@ -0,0 +1,166 @@
|
||||
# yaziline.yazi
|
||||
|
||||
Simple lualine-like status line for yazi.
|
||||
|
||||
Read more about features and configuration [here](#features).
|
||||
|
||||

|
||||
|
||||
## Requirements
|
||||
|
||||
- yazi version >= [25.5.28](https://github.com/sxyazi/yazi/releases/tag/v25.5.28)
|
||||
- Font with symbol support. For example [Nerd Fonts](https://www.nerdfonts.com/).
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
ya pkg add llanosrocas/yaziline
|
||||
```
|
||||
|
||||
Or manually copy `main.lua` to the `~/.config/yazi/plugins/yaziline.yazi/main.lua`
|
||||
|
||||
## Usage
|
||||
|
||||
Add this to your `~/.config/yazi/init.lua`:
|
||||
|
||||
```lua
|
||||
require("yaziline"):setup()
|
||||
```
|
||||
|
||||
Optionally, configure line:
|
||||
|
||||
```lua
|
||||
require("yaziline"):setup({
|
||||
color = "#98c379", -- main theme color
|
||||
secondary_color = "#5A6078", -- secondary color
|
||||
default_files_color = "darkgray", -- color of the file counter when it's inactive
|
||||
selected_files_color = "white",
|
||||
yanked_files_color = "green",
|
||||
cut_files_color = "red",
|
||||
|
||||
separator_style = "angly", -- "angly" | "curvy" | "liney" | "empty"
|
||||
separator_open = "",
|
||||
separator_close = "",
|
||||
separator_open_thin = "",
|
||||
separator_close_thin = "",
|
||||
separator_head = "",
|
||||
separator_tail = "",
|
||||
|
||||
select_symbol = "",
|
||||
yank_symbol = "",
|
||||
|
||||
filename_max_length = 24, -- truncate when filename > 24
|
||||
filename_truncate_length = 6, -- leave 6 chars on both sides
|
||||
filename_truncate_separator = "..." -- the separator of the truncated filename
|
||||
})
|
||||
```
|
||||
|
||||
```
|
||||
MODE size long_file...name.md S 0 Y 0
|
||||
| | | | | | | | |
|
||||
| | | | | | | | └─── yank_symbol
|
||||
| | | | | | | └─────── select_symbol
|
||||
| | | | | | └───────── separator_close_thin
|
||||
| | | | | └─────────────────── filename_truncate_separator
|
||||
| | | | └─────────────────────────────── separator_close
|
||||
| | | └────────────────────────────────── secondary_color
|
||||
| | └────────────────────────────────────── separator_close
|
||||
| └────────────────────────────────────────── color
|
||||
└───────────────────────────────────────────── separator_head
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
### Preconfigured separators
|
||||
|
||||
Choose your style:
|
||||
|
||||
- `angly`
|
||||

|
||||
- `curvy`
|
||||

|
||||
- `liney`
|
||||

|
||||
- `empty`
|
||||

|
||||
|
||||
### Separator customization
|
||||
|
||||
You can provide your own symbols for separators combined with preconfigured separators. For example:
|
||||
|
||||
```lua
|
||||
require("yaziline"):setup({
|
||||
-- Optinal config
|
||||
separator_style = "angly", -- preconfigured style
|
||||
separator_open = "", -- instead of
|
||||
separator_close = "", -- instead of
|
||||
separator_open_thin = "", -- change to anything
|
||||
separator_close_thin = "", -- change to anything
|
||||
separator_head = "", -- to match the style
|
||||
separator_tail = "" -- to match the style
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
_You can find more symbols [here](https://www.nerdfonts.com/cheat-sheet)_
|
||||
|
||||
### File actions icons
|
||||
|
||||
You can provide your own symbols for `select` and `yank`. For example:
|
||||
|
||||
```lua
|
||||
require("yaziline"):setup({
|
||||
-- Optinal config
|
||||
select_symbol = "", -- "S" by default
|
||||
yank_symbol = "" -- "Y" by default
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
_You can find more symbols [here](https://www.nerdfonts.com/cheat-sheet)_
|
||||
|
||||
### Colors and font weight
|
||||
|
||||
By default yaziline uses color values from your `theme.toml` (or flavor) but you can set custom colors in the `init.lua`:
|
||||
|
||||
```lua
|
||||
require("yaziline"):setup({
|
||||
color = "#98c379",
|
||||
default_files_color = "darkgray",
|
||||
selected_files_color = "white",
|
||||
yanked_files_color = "green",
|
||||
cut_files_color = "red",
|
||||
})
|
||||
```
|
||||
|
||||
For example, here is how my line looks like:
|
||||
|
||||

|
||||
|
||||
### Selected and Yanked Counter
|
||||
|
||||
Displays the number of selected ('S') and yanked ('Y') files on the left. If files are cut, the yank counter changes color, since its `yank --cut` under the hood.
|
||||
|
||||
### Truncated filename
|
||||
|
||||
Displays the truncated filename on the left, which is useful for smaller windows or long filenames. By default, it's 24 characters with trimming to 12 (6 + 6). Adjust in the `setup`.
|
||||
|
||||
```lua
|
||||
require("yaziline"):setup({
|
||||
filename_max_length = 24, -- truncate when filename > 24
|
||||
filename_truncate_length = 6, -- leave 6 chars on both sides
|
||||
filename_truncate_separator = "..." -- the separator of the truncated filename
|
||||
})
|
||||
```
|
||||
|
||||
### ISO Date for 'Modified'
|
||||
|
||||
On the right, you'll find the date and time the file was modified, formatted in an [ISO](https://en.wikipedia.org/wiki/ISO_8601)-like string for universal date representation. Adjust in the `Status:date` function.
|
||||
|
||||
## Credits
|
||||
|
||||
- [yazi source code](https://github.com/sxyazi/yazi)
|
||||
- [yatline.yazi](https://github.com/imsi32/yatline.yazi/tree/main)
|
||||
- [lualine.nvim](https://github.com/nvim-lualine/lualine.nvim)
|
||||
212
config/yazi/plugins/yaziline.yazi/main.lua
Normal file
212
config/yazi/plugins/yaziline.yazi/main.lua
Normal file
@@ -0,0 +1,212 @@
|
||||
---@diagnostic disable: undefined-global
|
||||
|
||||
local function setup(_, options)
|
||||
options = options or {}
|
||||
|
||||
local default_separators = {
|
||||
angly = { "", "", "", "" },
|
||||
curvy = { "", "", "", "" },
|
||||
liney = { "", "", "|", "|" },
|
||||
empty = { "", "", "", "" },
|
||||
}
|
||||
local separators = default_separators[options.separator_style or "angly"]
|
||||
|
||||
local config = {
|
||||
separator_styles = {
|
||||
separator_open = options.separator_open or separators[1],
|
||||
separator_close = options.separator_close or separators[2],
|
||||
separator_open_thin = options.separator_open_thin or separators[3],
|
||||
separator_close_thin = options.separator_close_thin or separators[4],
|
||||
separator_head = options.separator_head or "",
|
||||
separator_tail = options.separator_tail or "",
|
||||
},
|
||||
select_symbol = options.select_symbol or "S",
|
||||
yank_symbol = options.yank_symbol or "Y",
|
||||
|
||||
filename_max_length = options.filename_max_length or 24,
|
||||
filename_truncate_length = options.filename_truncate_length or 6,
|
||||
filename_truncate_separator = options.filename_truncate_separator or "...",
|
||||
|
||||
color = options.color or nil,
|
||||
secondary_color = options.secondary_color or nil,
|
||||
default_files_color = options.default_files_color
|
||||
or th.which.separator_style.fg
|
||||
or "darkgray",
|
||||
selected_files_color = options.selected_files_color
|
||||
or th.mgr.count_selected.bg
|
||||
or "white",
|
||||
yanked_files_color = options.selected_files_color
|
||||
or th.mgr.count_copied.bg
|
||||
or "green",
|
||||
cut_files_color = options.cut_files_color
|
||||
or th.mgr.count_cut.bg
|
||||
or "red",
|
||||
}
|
||||
|
||||
local current_separator_style = config.separator_styles
|
||||
|
||||
function Header:count()
|
||||
return ui.Line({})
|
||||
end
|
||||
|
||||
function Status:mode()
|
||||
local mode = tostring(self._tab.mode):upper()
|
||||
|
||||
local style = self:style()
|
||||
return ui.Line({
|
||||
ui.Span(current_separator_style.separator_head)
|
||||
:fg(config.color or style.main.bg),
|
||||
ui.Span(" " .. mode .. " ")
|
||||
:fg(th.which.mask.bg)
|
||||
:bg(config.color or style.main.bg),
|
||||
})
|
||||
end
|
||||
|
||||
function Status:size()
|
||||
local h = self._current.hovered
|
||||
local size = h and (h:size() or h.cha.len) or 0
|
||||
|
||||
local style = self:style()
|
||||
return ui.Span(current_separator_style.separator_close .. " " .. ya.readable_size(size) .. " ")
|
||||
:fg(config.color or style.main.bg)
|
||||
:bg(config.secondary_color or th.which.separator_style.fg)
|
||||
end
|
||||
|
||||
function Status:utf8_sub(str, start_char, end_char)
|
||||
local start_byte = utf8.offset(str, start_char)
|
||||
local end_byte = end_char and (utf8.offset(str, end_char + 1) - 1) or #str
|
||||
|
||||
if not start_byte or not end_byte then
|
||||
return ""
|
||||
end
|
||||
|
||||
return string.sub(str, start_byte, end_byte)
|
||||
end
|
||||
|
||||
function Status:truncate_name(filename, max_length)
|
||||
local base_name, extension = filename:match("^(.+)(%.[^%.]+)$")
|
||||
base_name = base_name or filename
|
||||
extension = extension or ""
|
||||
|
||||
if utf8.len(base_name) > max_length then
|
||||
base_name = self:utf8_sub(base_name, 1, config.filename_truncate_length)
|
||||
.. config.filename_truncate_separator
|
||||
.. self:utf8_sub(base_name, -config.filename_truncate_length)
|
||||
end
|
||||
|
||||
return base_name .. extension
|
||||
end
|
||||
|
||||
function Status:name()
|
||||
local h = self._current.hovered
|
||||
if not h then
|
||||
return ui.Line({
|
||||
ui.Span(current_separator_style.separator_close .. " ")
|
||||
:fg(config.secondary_color or th.which.separator_style.fg),
|
||||
ui.Span("Empty dir")
|
||||
:fg(config.color or style.main.bg),
|
||||
})
|
||||
end
|
||||
|
||||
local truncated_name = self:truncate_name(h.name, config.filename_max_length)
|
||||
|
||||
local style = self:style()
|
||||
return ui.Line({
|
||||
ui.Span(current_separator_style.separator_close .. " ")
|
||||
:fg(config.secondary_color or th.which.separator_style.fg),
|
||||
ui.Span(truncated_name)
|
||||
:fg(config.color or style.main.bg),
|
||||
})
|
||||
end
|
||||
|
||||
function Status:files()
|
||||
local files_yanked = #cx.yanked
|
||||
local files_selected = #cx.active.selected
|
||||
local files_cut = cx.yanked.is_cut
|
||||
|
||||
local selected_fg = files_selected > 0
|
||||
and config.selected_files_color
|
||||
or config.default_files_color
|
||||
local yanked_fg = files_yanked > 0
|
||||
and
|
||||
(files_cut
|
||||
and config.cut_files_color
|
||||
or config.yanked_files_color
|
||||
)
|
||||
or config.default_files_color
|
||||
|
||||
local yanked_text = files_yanked > 0
|
||||
and config.yank_symbol .. " " .. files_yanked
|
||||
or config.yank_symbol .. " 0"
|
||||
|
||||
return ui.Line({
|
||||
ui.Span(" " .. current_separator_style.separator_close_thin .. " ")
|
||||
:fg(th.which.separator_style.fg),
|
||||
ui.Span(config.select_symbol .. " " .. files_selected .. " ")
|
||||
:fg(selected_fg),
|
||||
ui.Span(yanked_text .. " ")
|
||||
:fg(yanked_fg),
|
||||
})
|
||||
end
|
||||
|
||||
function Status:modified()
|
||||
local hovered = cx.active.current.hovered
|
||||
|
||||
if not hovered then
|
||||
return ""
|
||||
end
|
||||
|
||||
local cha = hovered.cha
|
||||
local time = (cha.mtime or 0) // 1
|
||||
|
||||
return ui.Span(os.date("%Y-%m-%d %H:%M", time) .. " " .. current_separator_style.separator_open_thin .. " ")
|
||||
:fg(th.which.separator_style.fg)
|
||||
end
|
||||
|
||||
function Status:percent()
|
||||
local percent = 0
|
||||
local cursor = self._tab.current.cursor
|
||||
local length = #self._tab.current.files
|
||||
if cursor ~= 0 and length ~= 0 then
|
||||
percent = math.floor((cursor + 1) * 100 / length)
|
||||
end
|
||||
|
||||
if percent == 0 then
|
||||
percent = " Top "
|
||||
elseif percent == 100 then
|
||||
percent = " Bot "
|
||||
else
|
||||
percent = string.format(" %2d%% ", percent)
|
||||
end
|
||||
|
||||
local style = self:style()
|
||||
return ui.Line({
|
||||
ui.Span(" " .. current_separator_style.separator_open)
|
||||
:fg(config.secondary_color or th.which.separator_style.fg),
|
||||
ui.Span(percent)
|
||||
:fg(config.color or style.main.bg)
|
||||
:bg(config.secondary_color or th.which.separator_style.fg),
|
||||
ui.Span(current_separator_style.separator_open)
|
||||
:fg(config.color or style.main.bg)
|
||||
:bg(config.secondary_color or th.which.separator_style.fg),
|
||||
})
|
||||
end
|
||||
|
||||
function Status:position()
|
||||
local cursor = self._tab.current.cursor
|
||||
local length = #self._tab.current.files
|
||||
|
||||
local style = self:style()
|
||||
return ui.Line({
|
||||
ui.Span(string.format(" %2d/%-2d ", math.min(cursor + 1, length), length))
|
||||
:fg(th.which.mask.bg)
|
||||
:bg(config.color or style.main.bg),
|
||||
ui.Span(current_separator_style.separator_tail):fg(config.color or style.main.bg),
|
||||
})
|
||||
end
|
||||
|
||||
Status:children_add(Status.files, 4000, Status.LEFT)
|
||||
Status:children_add(Status.modified, 0, Status.RIGHT)
|
||||
end
|
||||
|
||||
return { setup = setup }
|
||||
Reference in New Issue
Block a user