feat: new plugin vcs-files.yazi
This commit is contained in:
21
vcs-files.yazi/LICENSE
Normal file
21
vcs-files.yazi/LICENSE
Normal file
@@ -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.
|
||||||
26
vcs-files.yazi/README.md
Normal file
26
vcs-files.yazi/README.md
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# vcs-files.yazi
|
||||||
|
|
||||||
|
> [!WARNING]
|
||||||
|
> The latest nightly build of Yazi is required at the moment, to use this plugin.
|
||||||
|
|
||||||
|
Show Git changed files in Yazi.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ya pack -a yazi-rs/plugins:vcs-files
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```toml
|
||||||
|
# keymap.toml
|
||||||
|
[[manager.prepend_keymap]]
|
||||||
|
on = [ "g", "c" ]
|
||||||
|
run = "plugin vcs-files"
|
||||||
|
desc = "Show Git changed files"
|
||||||
|
```
|
||||||
|
|
||||||
|
## TODO
|
||||||
|
|
||||||
|
- [ ] Add support for other VCS (e.g. Mercurial, Subversion)
|
||||||
33
vcs-files.yazi/main.lua
Normal file
33
vcs-files.yazi/main.lua
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
--- @since 25.3.7
|
||||||
|
|
||||||
|
local root = ya.sync(function() return cx.active.current.cwd end)
|
||||||
|
|
||||||
|
local function fail(content) return ya.notify { title = "VCS Files", content = content, timeout = 5, level = "error" } end
|
||||||
|
|
||||||
|
local function entry()
|
||||||
|
local root = root()
|
||||||
|
local output, err = Command("git"):cwd(tostring(root)):args({ "diff", "--name-only", "HEAD" }):output()
|
||||||
|
if err then
|
||||||
|
return fail("Failed to run `git diff`, error: " .. err)
|
||||||
|
elseif not output.status.success then
|
||||||
|
return fail("Failed to run `git diff`, stderr: " .. output.stderr)
|
||||||
|
end
|
||||||
|
|
||||||
|
local id = ya.id("ft")
|
||||||
|
local cwd = root:to_search("Git changes")
|
||||||
|
ya.mgr_emit("cd", { Url(cwd) })
|
||||||
|
ya.mgr_emit("update_files", { op = fs.op("part", { id = id, url = Url(cwd), files = {} }) })
|
||||||
|
|
||||||
|
local files = {}
|
||||||
|
for line in output.stdout:gmatch("[^\r\n]+") do
|
||||||
|
local url = root:join(line)
|
||||||
|
local cha = fs.cha(url, true)
|
||||||
|
if cha then
|
||||||
|
files[#files + 1] = File { url = url, cha = cha }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
ya.mgr_emit("update_files", { op = fs.op("part", { id = id, url = Url(cwd), files = files }) })
|
||||||
|
ya.mgr_emit("update_files", { op = fs.op("done", { id = id, url = cwd, cha = Cha { kind = 16 } }) })
|
||||||
|
end
|
||||||
|
|
||||||
|
return { entry = entry }
|
||||||
Reference in New Issue
Block a user