custom-hypr - add yazi config
This commit is contained in:
21
.config/yazi/plugins/eza-preview.yazi/LICENSE
Normal file
21
.config/yazi/plugins/eza-preview.yazi/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 sharklasers996
|
||||
|
||||
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.
|
||||
63
.config/yazi/plugins/eza-preview.yazi/README.md
Normal file
63
.config/yazi/plugins/eza-preview.yazi/README.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# eza-preview.yazi
|
||||
|
||||
[Yazi](https://github.com/sxyazi/yazi) plugin to preview directories using [eza](https://github.com/eza-community/eza), can be switched between list and tree modes.
|
||||
|
||||
List mode:
|
||||

|
||||
|
||||
Tree mode:
|
||||

|
||||
|
||||
## Requirements
|
||||
|
||||
- [yazi (0.4+) or nightly](https://github.com/sxyazi/yazi)
|
||||
- [eza (0.20+)](https://github.com/eza-community/eza)
|
||||
|
||||
## Installation
|
||||
|
||||
### Linux/MacOS
|
||||
|
||||
```sh
|
||||
ya pack -a ahkohd/eza-preview
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Add `eza-preview` to previewers in `yazi.toml`:
|
||||
|
||||
```toml
|
||||
[[plugin.prepend_previewers]]
|
||||
name = "*/"
|
||||
run = "eza-preview"
|
||||
```
|
||||
|
||||
Set key binding to switch between list and tree modes in `keymap.toml`:
|
||||
|
||||
```toml
|
||||
[manager]
|
||||
prepend_keymap = [
|
||||
{ on = [ "E" ], run = "plugin eza-preview", desc = "Toggle tree/list dir preview" },
|
||||
{ on = [ "-" ], run = "plugin eza-preview --args='--inc-level'", desc = "Increment tree level" },
|
||||
{ on = [ "_" ], run = "plugin eza-preview --args='--dec-level'", desc = "Decrement tree level" },
|
||||
{ on = [ "$" ], run = "plugin eza-preview --args='--toggle-follow-symlinks'", desc = "Toggle tree follow symlinks" },
|
||||
]
|
||||
```
|
||||
|
||||
List mode is the default, if you want to have tree mode instead when starting yazi - update `init.lua` with:
|
||||
|
||||
```lua
|
||||
require("eza-preview"):setup({
|
||||
-- Determines the directory depth level to tree preview (default: 3)
|
||||
level = 3,
|
||||
|
||||
-- Whether to follow symlinks when previewing directories (default: false)
|
||||
follow_symlinks = false
|
||||
|
||||
-- Whether to show target file info instead of symlink info (default: false)
|
||||
dereference = false
|
||||
})
|
||||
|
||||
-- Or use default settings with empty table
|
||||
require("eza-preview"):setup({})
|
||||
|
||||
```
|
||||
157
.config/yazi/plugins/eza-preview.yazi/main.lua
Normal file
157
.config/yazi/plugins/eza-preview.yazi/main.lua
Normal file
@@ -0,0 +1,157 @@
|
||||
local M = {}
|
||||
|
||||
local function fail(s, ...)
|
||||
ya.notify({ title = "Eza Preview", content = string.format(s, ...), timeout = 5, level = "error" })
|
||||
end
|
||||
|
||||
local toggle_view_mode = ya.sync(function(state, _)
|
||||
if state.tree == nil then
|
||||
state.tree = false
|
||||
end
|
||||
|
||||
state.tree = not state.tree
|
||||
end)
|
||||
|
||||
local is_tree_view_mode = ya.sync(function(state, _)
|
||||
return state.tree
|
||||
end)
|
||||
|
||||
local set_opts = ya.sync(function(state, opts)
|
||||
if state.opts == nil then
|
||||
state.opts = { level = 3, follow_symlinks = false, dereference = false }
|
||||
end
|
||||
|
||||
for key, value in pairs(opts or {}) do
|
||||
state.opts[key] = value
|
||||
end
|
||||
end)
|
||||
|
||||
local get_opts = ya.sync(function(state)
|
||||
return state.opts
|
||||
end)
|
||||
|
||||
local inc_level = ya.sync(function(state)
|
||||
state.opts.level = state.opts.level + 1
|
||||
end)
|
||||
|
||||
local dec_level = ya.sync(function(state)
|
||||
if state.opts.level > 1 then
|
||||
state.opts.level = state.opts.level - 1
|
||||
end
|
||||
end)
|
||||
|
||||
local toggle_follow_symlinks = ya.sync(function(state)
|
||||
state.opts.follow_symlinks = not state.opts.follow_symlinks
|
||||
end)
|
||||
|
||||
function M:setup(opts)
|
||||
set_opts(opts)
|
||||
|
||||
toggle_view_mode()
|
||||
end
|
||||
|
||||
function M:entry(job)
|
||||
local args = job.args
|
||||
|
||||
if args["inc_level"] ~= nil then
|
||||
inc_level()
|
||||
elseif args["dec_level"] ~= nil then
|
||||
dec_level()
|
||||
elseif args["toggle_follow_symlinks"] ~= nil then
|
||||
toggle_follow_symlinks()
|
||||
else
|
||||
set_opts()
|
||||
toggle_view_mode()
|
||||
end
|
||||
|
||||
ya.manager_emit("seek", { 0 })
|
||||
end
|
||||
|
||||
function M:peek(job)
|
||||
local opts = get_opts()
|
||||
|
||||
local args = {
|
||||
"--all",
|
||||
"--color=always",
|
||||
"--icons=always",
|
||||
"--group-directories-first",
|
||||
"--no-quotes",
|
||||
tostring(job.file.url),
|
||||
}
|
||||
|
||||
if is_tree_view_mode() then
|
||||
table.insert(args, "--tree")
|
||||
table.insert(args, string.format("--level=%d", opts.level))
|
||||
end
|
||||
|
||||
if opts then
|
||||
if opts.follow_symlinks then
|
||||
table.insert(args, "--follow-symlinks")
|
||||
end
|
||||
|
||||
if opts.dereference then
|
||||
table.insert(args, "--dereference")
|
||||
end
|
||||
end
|
||||
|
||||
local child = Command("eza"):args(args):stdout(Command.PIPED):stderr(Command.PIPED):spawn()
|
||||
|
||||
local limit = job.area.h
|
||||
local lines = ""
|
||||
local num_lines = 1
|
||||
local num_skip = 0
|
||||
local empty_output = false
|
||||
|
||||
repeat
|
||||
local line, event = child:read_line()
|
||||
if event == 1 then
|
||||
fail(tostring(event))
|
||||
elseif event ~= 0 then
|
||||
break
|
||||
end
|
||||
|
||||
if num_skip >= job.skip then
|
||||
lines = lines .. line
|
||||
num_lines = num_lines + 1
|
||||
else
|
||||
num_skip = num_skip + 1
|
||||
end
|
||||
until num_lines >= limit
|
||||
|
||||
if num_lines == 1 and not is_tree_view_mode() then
|
||||
empty_output = true
|
||||
elseif num_lines == 2 and is_tree_view_mode() then
|
||||
empty_output = true
|
||||
end
|
||||
|
||||
child:start_kill()
|
||||
if job.skip > 0 and num_lines < limit then
|
||||
ya.manager_emit("peek", {
|
||||
tostring(math.max(0, job.skip - (limit - num_lines))),
|
||||
only_if = tostring(job.file.url),
|
||||
upper_bound = "",
|
||||
})
|
||||
elseif empty_output then
|
||||
ya.preview_widgets(job, {
|
||||
ui.Text({ ui.Line("No items") }):area(job.area):align(ui.Text.CENTER),
|
||||
})
|
||||
else
|
||||
ya.preview_widgets(job, { ui.Text.parse(lines):area(job.area) })
|
||||
end
|
||||
end
|
||||
|
||||
function M:seek(job)
|
||||
local h = cx.active.current.hovered
|
||||
|
||||
if h and h.url == job.file.url then
|
||||
local step = math.floor(job.units * job.area.h / 10)
|
||||
|
||||
ya.manager_emit("peek", {
|
||||
math.max(0, cx.active.preview.skip + step),
|
||||
only_if = tostring(job.file.url),
|
||||
force = true,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user