From 02772db785a916e692ec8b03bb68d62d1b19d417 Mon Sep 17 00:00:00 2001 From: Cian Hughes Date: Tue, 22 Apr 2025 14:28:52 +0100 Subject: [PATCH] Moved yazi dotfiles to the dotfiles subrepo --- .gitmodules | 27 +++++++++ dot_config/yazi/flavors/tokyo-night.yazi | 1 + dot_config/yazi/keymap.toml | 60 ++++++++++++++++++- dot_config/yazi/plugins/core | 1 + dot_config/yazi/plugins/glow.yazi/README.md | 30 ++++++++++ dot_config/yazi/plugins/glow.yazi/main.lua | 64 +++++++++++++++++++++ dot_config/yazi/plugins/hexyl.yazi | 1 + dot_config/yazi/plugins/ouch.yazi | 1 + dot_config/yazi/plugins/rich-preview.yazi | 1 + dot_config/yazi/plugins/starship.yazi | 1 + dot_config/yazi/plugins/sudo.yazi | 1 + dot_config/yazi/plugins/wl-clipboard.yazi | 1 + dot_config/yazi/yazi.toml | 22 +++++-- 13 files changed, 204 insertions(+), 7 deletions(-) create mode 160000 dot_config/yazi/flavors/tokyo-night.yazi create mode 160000 dot_config/yazi/plugins/core create mode 100644 dot_config/yazi/plugins/glow.yazi/README.md create mode 100644 dot_config/yazi/plugins/glow.yazi/main.lua create mode 160000 dot_config/yazi/plugins/hexyl.yazi create mode 160000 dot_config/yazi/plugins/ouch.yazi create mode 160000 dot_config/yazi/plugins/rich-preview.yazi create mode 160000 dot_config/yazi/plugins/starship.yazi create mode 160000 dot_config/yazi/plugins/sudo.yazi create mode 160000 dot_config/yazi/plugins/wl-clipboard.yazi diff --git a/.gitmodules b/.gitmodules index eccf83e..48d4ce7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,30 @@ [submodule "dot_config/micro/plug/lsp"] path = dot_config/micro/plug/lsp url = https://github.com/AndCake/micro-plugin-lsp.git +[submodule "dot_config/yazi/plugins/hexyl.yazi"] + path = dot_config/yazi/plugins/hexyl.yazi + url = https://github.com/Reledia/hexyl.yazi +[submodule "dot_config/yazi/flavors/tokyo-night.yazi"] + path = dot_config/yazi/flavors/tokyo-night.yazi + url = https://github.com/BennyOe/tokyo-night.yazi.git +[submodule "dot_config/yazi/plugins/sudo.yazi"] + path = dot_config/yazi/plugins/sudo.yazi + url = https://github.com/TD-Sky/sudo.yazi +[submodule "dot_config/yazi/plugins/core"] + path = dot_config/yazi/plugins/core + url = https://github.com/yazi-rs/plugins +[submodule "dot_config/yazi/plugins/ouch.yazi"] + path = dot_config/yazi/plugins/ouch.yazi + url = https://github.com/ndtoan96/ouch.yazi +[submodule "dot_config/yazi/plugins/starship.yazi"] + path = dot_config/yazi/plugins/starship.yazi + url = https://github.com/Rolv-Apneseth/starship.yazi +[submodule "dot_config/yazi/plugins/glow.yazi"] + path = dot_config/yazi/plugins/glow.yazi + url = https://github.com/Reledia/glow.yazi +[submodule "dot_config/yazi/plugins/wl-clipboard.yazi"] + path = dot_config/yazi/plugins/wl-clipboard.yazi + url = https://github.com/grappas/wl-clipboard.yazi +[submodule "dot_config/yazi/plugins/rich-preview.yazi"] + path = dot_config/yazi/plugins/rich-preview.yazi + url = https://github.com/AnirudhG07/rich-preview.yazi diff --git a/dot_config/yazi/flavors/tokyo-night.yazi b/dot_config/yazi/flavors/tokyo-night.yazi new file mode 160000 index 0000000..695dac6 --- /dev/null +++ b/dot_config/yazi/flavors/tokyo-night.yazi @@ -0,0 +1 @@ +Subproject commit 695dac6bcc605ba4b0bf1b1f56169eaa7cc4bb40 diff --git a/dot_config/yazi/keymap.toml b/dot_config/yazi/keymap.toml index 1408bbf..f24db10 100644 --- a/dot_config/yazi/keymap.toml +++ b/dot_config/yazi/keymap.toml @@ -1,5 +1,3 @@ -"$schema" = "https://yazi-rs.github.io/schemas/keymap.json" - [manager] keymap = [ @@ -257,6 +255,48 @@ keymap = [ # Help { on = "~", run = "help", desc = "Open help" }, { on = "", run = "help", desc = "Open help" }, + + # Sudo + { on = [ + "R", + "p", + "p", + ], run = "plugin sudo -- paste", desc = "sudo paste" }, + { on = [ + "R", + "P", + ], run = "plugin sudo -- paste --force", desc = "sudo paste" }, + { on = [ + "R", + "r", + ], run = "plugin sudo -- rename", desc = "sudo rename" }, + { on = [ + "R", + "p", + "l", + ], run = "plugin sudo -- link", desc = "sudo link" }, + { on = [ + "R", + "p", + "r", + ], run = "plugin sudo -- link --relative", desc = "sudo link relative path" }, + { on = [ + "R", + "p", + "L", + ], run = "plugin sudo -- hardlink", desc = "sudo hardlink" }, + { on = [ + "R", + "a", + ], run = "plugin sudo -- create", desc = "sudo create" }, + { on = [ + "R", + "d", + ], run = "plugin sudo -- remove", desc = "sudo trash" }, + { on = [ + "R", + "D", + ], run = "plugin sudo -- remove --permanently", desc = "sudo delete" }, ] [tasks] @@ -489,3 +529,19 @@ desc = "Chmod on selected files" on = "T" run = "plugin --sync max-preview" desc = "Maximize or restore preview" + +[[manager.prepend_keymap]] +on = "" +run = ["plugin wl-clipboard"] +desc = "Yank to wl-clipboard" + +[[manager.prepend_keymap]] +on = ["C"] +run = "plugin ouch" +desc = "Compress with ouch" + +[opener] +extract = [ + { run = 'ouch d -y "%*"', desc = "Extract here with ouch", for = "windows" }, + { run = 'ouch d -y "$@"', desc = "Extract here with ouch", for = "unix" }, +] diff --git a/dot_config/yazi/plugins/core b/dot_config/yazi/plugins/core new file mode 160000 index 0000000..4b027c7 --- /dev/null +++ b/dot_config/yazi/plugins/core @@ -0,0 +1 @@ +Subproject commit 4b027c79371af963d4ae3a8b69e42177aa3fa6ee diff --git a/dot_config/yazi/plugins/glow.yazi/README.md b/dot_config/yazi/plugins/glow.yazi/README.md new file mode 100644 index 0000000..ba66ae7 --- /dev/null +++ b/dot_config/yazi/plugins/glow.yazi/README.md @@ -0,0 +1,30 @@ +# glow.yazi + +Plugin for [Yazi](https://github.com/sxyazi/yazi) to preview markdown files with [glow](https://github.com/charmbracelet/glow). To install, run the below mentioned command: + +```bash +ya pack -a Reledia/glow +``` + +then include it in your `yazi.toml` to use: + +```toml +[plugin] +prepend_previewers = [ + { name = "*.md", run = "glow" }, +] +``` + +Make sure you have [glow](https://github.com/charmbracelet/glow) installed, and can be found in `PATH`. + +## Feature + ++ You can modify line wrap in `main.lua`, the current value is 55. ++ You can press `ctrl+e` to scroll up and `ctrl+y` to scroll down the readme file in preview panel in yazi: (add this to `keymap.toml`) +```toml +prepend_keymap = [ + # glow.yazi + { on = [""], run = "seek 5" }, + { on = [""], run = "seek -5" }, +] +``` diff --git a/dot_config/yazi/plugins/glow.yazi/main.lua b/dot_config/yazi/plugins/glow.yazi/main.lua new file mode 100644 index 0000000..8883feb --- /dev/null +++ b/dot_config/yazi/plugins/glow.yazi/main.lua @@ -0,0 +1,64 @@ +local M = {} + +function M:peek(job) + -- Set a fixed width of 50 characters for the preview + local preview_width = 55 + + local child = Command("glow") + :args({ + "--style", + "dark", + "--width", + tostring(preview_width), -- Use fixed width instead of job.area.w + tostring(job.file.url), + }) + :env("CLICOLOR_FORCE", "1") + :stdout(Command.PIPED) + :stderr(Command.PIPED) + :spawn() + + if not child then + return require("code").peek(job) + end + + local limit = job.area.h + local i, lines = 0, "" + repeat + local next, event = child:read_line() + if event == 1 then + return require("code").peek(job) + elseif event ~= 0 then + break + end + + i = i + 1 + if i > job.skip then + lines = lines .. next + end + until i >= job.skip + limit + + child:start_kill() + if job.skip > 0 and i < job.skip + limit then + ya.mgr_emit("peek", { + tostring(math.max(0, i - limit)), + only_if = job.file.url, + upper_bound = true + }) + else + lines = lines:gsub("\t", string.rep(" ", rt.preview.tab_size)) + ya.preview_widgets(job, { ui.Text.parse(lines):area(job.area) }) + end +end + +function M:seek(job) + local h = cx.active.current.hovered + if not h or h.url ~= job.file.url then + return + end + ya.mgr_emit('peek', { + math.max(0, cx.active.preview.skip + job.units), + only_if = job.file.url, + }) +end + +return M diff --git a/dot_config/yazi/plugins/hexyl.yazi b/dot_config/yazi/plugins/hexyl.yazi new file mode 160000 index 0000000..016a09b --- /dev/null +++ b/dot_config/yazi/plugins/hexyl.yazi @@ -0,0 +1 @@ +Subproject commit 016a09bcc249dd3ce06267d54cc039e73de9c647 diff --git a/dot_config/yazi/plugins/ouch.yazi b/dot_config/yazi/plugins/ouch.yazi new file mode 160000 index 0000000..2496cd9 --- /dev/null +++ b/dot_config/yazi/plugins/ouch.yazi @@ -0,0 +1 @@ +Subproject commit 2496cd9ac2d1fb52597b22ae84f3af06c826a86d diff --git a/dot_config/yazi/plugins/rich-preview.yazi b/dot_config/yazi/plugins/rich-preview.yazi new file mode 160000 index 0000000..fdcf373 --- /dev/null +++ b/dot_config/yazi/plugins/rich-preview.yazi @@ -0,0 +1 @@ +Subproject commit fdcf37320e35f7c12e8087900eebffcdafaee8cb diff --git a/dot_config/yazi/plugins/starship.yazi b/dot_config/yazi/plugins/starship.yazi new file mode 160000 index 0000000..6fde3b2 --- /dev/null +++ b/dot_config/yazi/plugins/starship.yazi @@ -0,0 +1 @@ +Subproject commit 6fde3b2d9dc9a12c14588eb85cf4964e619842e6 diff --git a/dot_config/yazi/plugins/sudo.yazi b/dot_config/yazi/plugins/sudo.yazi new file mode 160000 index 0000000..af70636 --- /dev/null +++ b/dot_config/yazi/plugins/sudo.yazi @@ -0,0 +1 @@ +Subproject commit af70636fbcf30ef17f77c5ffcfcbf1342c554be1 diff --git a/dot_config/yazi/plugins/wl-clipboard.yazi b/dot_config/yazi/plugins/wl-clipboard.yazi new file mode 160000 index 0000000..c4edc4f --- /dev/null +++ b/dot_config/yazi/plugins/wl-clipboard.yazi @@ -0,0 +1 @@ +Subproject commit c4edc4f6adf088521f11d0acf2b70610c31924f0 diff --git a/dot_config/yazi/yazi.toml b/dot_config/yazi/yazi.toml index b38c22e..3450497 100644 --- a/dot_config/yazi/yazi.toml +++ b/dot_config/yazi/yazi.toml @@ -1,12 +1,24 @@ [plugin] prepend_previewers = [ - { name = "*.md", run = "glow" }, - { name = "*.bin", run = "hexyl" }, + { name = "*.md", run = "glow" }, + { name = "*.bin", run = "hexyl" }, ] append_previewers = [ - { name = "*", run = "hexyl" }, + { name = "*.md", run = "glow" }, + { name = "*.csv", run = "rich-preview" }, + { name = "*.rst", run = "rich-preview" }, + { name = "*.ipynb", run = "rich-preview" }, + { name = "*.json", run = "rich-preview" }, + { 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/x-xz", run = "ouch" }, + { mime = "application/xz", run = "ouch" }, + { name = "*", run = "hexyl" }, ] prepend_fetchers = [ - { id = "git", name = "*", run = "git" }, - { id = "git", name = "*/", run = "git" }, + { id = "git", name = "*", run = "git" }, + { id = "git", name = "*/", run = "git" }, ]