yazi - init commit
This commit is contained in:
7
plugins/wl-clipboard.yazi/LICENSE
Normal file
7
plugins/wl-clipboard.yazi/LICENSE
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright 2024 grappas
|
||||
|
||||
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.
|
||||
34
plugins/wl-clipboard.yazi/README.md
Normal file
34
plugins/wl-clipboard.yazi/README.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# wl-clipboard.yazi
|
||||
|
||||
Forked from: [orhnk/system-clipboard.yazi](https://github.com/orhnk/system-clipboard.yazi) to work with wayland compositors.
|
||||
|
||||
## Demo
|
||||
|
||||
<https://github.com/user-attachments/assets/74d59f49-266a-497e-b67e-d77e64209026>
|
||||
|
||||
## Config
|
||||
|
||||
> [!NOTE]
|
||||
> You need yazi 3.x for this plugin to work.
|
||||
|
||||
> [!Important]
|
||||
> This plugin utilizes ["wl-clipboard" project](https://github.com/bugaevc/wl-clipboard).
|
||||
> You need to have it installed on your system. (Make sure that It's on your $PATH)
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
ya pack -a grappas/wl-clipboard
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Copy or install this plugin and add the following keymap to your `manager.prepend_keymap`:
|
||||
|
||||
```toml
|
||||
on = "<C-y>"
|
||||
run = ["plugin wl-clipboard"]
|
||||
```
|
||||
|
||||
> [!Tip]
|
||||
> If you want to use this plugin with yazi's default yanking behaviour you should use `cx.yanked` instead of `tab.selected` in `init.lua` (See [#1487](https://github.com/sxyazi/yazi/issues/1487))
|
||||
60
plugins/wl-clipboard.yazi/main.lua
Normal file
60
plugins/wl-clipboard.yazi/main.lua
Normal file
@@ -0,0 +1,60 @@
|
||||
-- Meant to run at async context. (yazi system-clipboard)
|
||||
|
||||
local selected_or_hovered = ya.sync(function()
|
||||
local tab, paths = cx.active, {}
|
||||
for _, u in pairs(tab.selected) do
|
||||
paths[#paths + 1] = tostring(u)
|
||||
end
|
||||
if #paths == 0 and tab.current.hovered then
|
||||
paths[1] = tostring(tab.current.hovered.url)
|
||||
end
|
||||
return paths
|
||||
end)
|
||||
|
||||
return {
|
||||
entry = function()
|
||||
ya.manager_emit("escape", { visual = true })
|
||||
|
||||
local urls = selected_or_hovered()
|
||||
|
||||
if #urls == 0 then
|
||||
return ya.notify({ title = "System Clipboard", content = "No file selected", level = "warn", timeout = 5 })
|
||||
end
|
||||
|
||||
-- ya.notify({ title = #urls, content = table.concat(urls, " "), level = "info", timeout = 5 })
|
||||
|
||||
-- Format the URLs for `text/uri-list` specification
|
||||
local function encode_uri(uri)
|
||||
return uri:gsub("([^%w%-%._~:/])", function(c)
|
||||
return string.format("%%%02X", string.byte(c))
|
||||
end)
|
||||
end
|
||||
|
||||
local file_list_formatted = ""
|
||||
for _, path in ipairs(urls) do
|
||||
-- Each file path must be URI-encoded and prefixed with "file://"
|
||||
file_list_formatted = file_list_formatted .. "file://" .. encode_uri(path) .. "\r\n"
|
||||
end
|
||||
|
||||
local status, err =
|
||||
Command("wl-copy"):arg("--type"):arg("text/uri-list"):arg(file_list_formatted):spawn():wait()
|
||||
|
||||
if status or status.succes then
|
||||
ya.notify({
|
||||
title = "System Clipboard",
|
||||
content = "Succesfully copied the file(s) to system clipboard",
|
||||
level = "info",
|
||||
timeout = 5,
|
||||
})
|
||||
end
|
||||
|
||||
if not status or not status.success then
|
||||
ya.notify({
|
||||
title = "System Clipboard",
|
||||
content = string.format("Could not copy selected file(s) %s", status and status.code or err),
|
||||
level = "error",
|
||||
timeout = 5,
|
||||
})
|
||||
end
|
||||
end,
|
||||
}
|
||||
Reference in New Issue
Block a user