diff options
| author | subh <subh@subh.space> | 2026-04-03 14:47:03 +0530 |
|---|---|---|
| committer | subh <subh@subh.space> | 2026-04-03 14:47:03 +0530 |
| commit | 314d760de1922128124f2a9be0494fd4f6f7effb (patch) | |
| tree | 3f4bb374fc89be2b1cd4e2a0a21ae17d4bf83452 /yazi/plugins/chmod.yazi | |
| parent | 0203dd4b8d45c663356f797c11be17fdec6f22f2 (diff) | |
new music bar, auto usb mounting and more
Diffstat (limited to 'yazi/plugins/chmod.yazi')
| -rw-r--r-- | yazi/plugins/chmod.yazi/LICENSE | 21 | ||||
| -rw-r--r-- | yazi/plugins/chmod.yazi/README.md | 28 | ||||
| -rw-r--r-- | yazi/plugins/chmod.yazi/main.lua | 47 |
3 files changed, 96 insertions, 0 deletions
diff --git a/yazi/plugins/chmod.yazi/LICENSE b/yazi/plugins/chmod.yazi/LICENSE new file mode 100644 index 0000000..fb5b1d6 --- /dev/null +++ b/yazi/plugins/chmod.yazi/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 yazi-rs + +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. diff --git a/yazi/plugins/chmod.yazi/README.md b/yazi/plugins/chmod.yazi/README.md new file mode 100644 index 0000000..5a73207 --- /dev/null +++ b/yazi/plugins/chmod.yazi/README.md @@ -0,0 +1,28 @@ +# chmod.yazi + +Execute `chmod` on the selected files to change their mode. This plugin is only available on Unix platforms since it relies on [`chmod(2)`](https://man7.org/linux/man-pages/man2/chmod.2.html). + +https://github.com/yazi-rs/plugins/assets/17523360/7aa3abc2-d057-498c-8473-a6282c59c464 + +## Installation + +```sh +ya pkg add yazi-rs/plugins:chmod +``` + +## Usage + +Add this to your `~/.config/yazi/keymap.toml`: + +```toml +[[mgr.prepend_keymap]] +on = [ "c", "m" ] +run = "plugin chmod" +desc = "Chmod on selected files" +``` + +Note that, the keybindings above are just examples, please tune them up as needed to ensure they don't conflict with your other actions/plugins. + +## License + +This plugin is MIT-licensed. For more information check the [LICENSE](LICENSE) file. diff --git a/yazi/plugins/chmod.yazi/main.lua b/yazi/plugins/chmod.yazi/main.lua new file mode 100644 index 0000000..87af0bf --- /dev/null +++ b/yazi/plugins/chmod.yazi/main.lua @@ -0,0 +1,47 @@ +--- @since 26.1.22 + +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) + +local function fail(s, ...) + ya.notify { + title = "Chmod", + content = string.format(s, ...), + level = "error", + timeout = 5, + } +end + +return { + entry = function() + ya.emit("escape", { visual = true }) + + local urls = selected_or_hovered() + if #urls == 0 then + return ya.notify { title = "Chmod", content = "No file selected", level = "warn", timeout = 5 } + end + + local value, event = ya.input { + title = "Chmod:", + pos = { "top-center", y = 3, w = 40 }, + } + if event ~= 1 then + return + end + + local output, err = Command("chmod"):arg(value):arg(urls):output() + if not output then + fail("Failed to run chmod: %s", err) + elseif not output.status.success then + fail("Chmod failed with stderr:\n%s", output.stderr:gsub("^chmod:%s*", "")) + end + end, +} |
