feat: complete mactag.yazi
This commit is contained in:
@@ -18,4 +18,6 @@ local function entry(st)
|
|||||||
ya.app_emit("resize", {})
|
ya.app_emit("resize", {})
|
||||||
end
|
end
|
||||||
|
|
||||||
return { entry = entry }
|
local function enabled(st) return st.old ~= nil end
|
||||||
|
|
||||||
|
return { entry = entry, enabled = enabled }
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ Bring macOS's awesome tagging feature to Yazi! The plugin it's only available fo
|
|||||||
|
|
||||||
Authors: [@AnirudhG07](https://github.com/AnirudhG07), and [@sxyazi](https://github.com/sxyazi)
|
Authors: [@AnirudhG07](https://github.com/AnirudhG07), and [@sxyazi](https://github.com/sxyazi)
|
||||||
|
|
||||||
Note that this plugin is still under development.
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Install the plugin itself, and [jdberry/tag](https://github.com/jdberry/tag) used to tag files:
|
Install the plugin itself, and [jdberry/tag](https://github.com/jdberry/tag) used to tag files:
|
||||||
@@ -22,6 +20,14 @@ Add the following to your `~/.config/yazi/init.lua`:
|
|||||||
```lua
|
```lua
|
||||||
require("mactag"):setup {
|
require("mactag"):setup {
|
||||||
-- You can change the colors of the tags here
|
-- You can change the colors of the tags here
|
||||||
|
keys = {
|
||||||
|
r = "Red",
|
||||||
|
o = "Orange",
|
||||||
|
y = "Yellow",
|
||||||
|
g = "Green",
|
||||||
|
b = "Blue",
|
||||||
|
p = "Purple",
|
||||||
|
},
|
||||||
colors = {
|
colors = {
|
||||||
Red = "#ee7b70",
|
Red = "#ee7b70",
|
||||||
Orange = "#f5bd5c",
|
Orange = "#f5bd5c",
|
||||||
@@ -29,7 +35,6 @@ require("mactag"):setup {
|
|||||||
Green = "#91fc87",
|
Green = "#91fc87",
|
||||||
Blue = "#5fa3f8",
|
Blue = "#5fa3f8",
|
||||||
Purple = "#cb88f8",
|
Purple = "#cb88f8",
|
||||||
Gray = "#b5b5b9",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -54,14 +59,12 @@ This plugin also provides the functionality to add and remove tags. Add followin
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
[[manager.prepend_keymap]]
|
[[manager.prepend_keymap]]
|
||||||
on = [ "b", "r" ]
|
on = [ "b", "a" ]
|
||||||
run = 'plugin mactag --args="add Red"'
|
run = 'plugin mactag --args="add"'
|
||||||
desc = "Tag selected files with red"
|
desc = "Add tag to selected files"
|
||||||
|
|
||||||
[[manager.prepend_keymap]]
|
[[manager.prepend_keymap]]
|
||||||
on = [ "b", "R" ]
|
on = [ "b", "r" ]
|
||||||
run = 'plugin mactag --args="remove Red"'
|
run = 'plugin mactag --args="remove"'
|
||||||
desc = "Remove red tag from selected files"
|
desc = "Remove tag from selected files"
|
||||||
```
|
```
|
||||||
|
|
||||||
`Red` can be any tag name you like. To add/remove multiple tags at once, use a comma (`,`) to separate them, like `Red,Yellow`.
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local update = ya.sync(function(st, tags)
|
local update = ya.sync(function(st, tags)
|
||||||
for path, tag in pairs(tags) do
|
for path, tag in pairs(tags) do
|
||||||
st.tags[path] = #tag == 0 and nil or tag
|
st.tags[path] = #tag > 0 and tag or nil
|
||||||
end
|
end
|
||||||
ya.render()
|
ya.render()
|
||||||
end)
|
end)
|
||||||
@@ -18,6 +18,7 @@ end)
|
|||||||
|
|
||||||
local function setup(st, opts)
|
local function setup(st, opts)
|
||||||
st.tags = {}
|
st.tags = {}
|
||||||
|
st.keys = opts.keys
|
||||||
st.colors = opts.colors
|
st.colors = opts.colors
|
||||||
|
|
||||||
Linemode:children_add(function(self)
|
Linemode:children_add(function(self)
|
||||||
@@ -63,11 +64,25 @@ local function fetch(self)
|
|||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local cands = ya.sync(function(st)
|
||||||
|
local t = {}
|
||||||
|
for k, v in pairs(st.keys) do
|
||||||
|
t[#t + 1] = { on = k, desc = v }
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end)
|
||||||
|
|
||||||
local function entry(_, args)
|
local function entry(_, args)
|
||||||
assert(args[1] == "add" or args[1] == "remove", "Invalid action")
|
assert(args[1] == "add" or args[1] == "remove", "Invalid action")
|
||||||
assert(args[2], "No tag specified")
|
ya.manager_emit("escape", { visual = true })
|
||||||
|
|
||||||
local t = { args[1] == "remove" and "-r" or "-a", args[2] }
|
local cands = cands()
|
||||||
|
local choice = ya.which { cands = cands }
|
||||||
|
if not choice then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local t = { args[1] == "remove" and "-r" or "-a", cands[choice].desc }
|
||||||
local files = {}
|
local files = {}
|
||||||
for _, url in ipairs(selected_or_hovered()) do
|
for _, url in ipairs(selected_or_hovered()) do
|
||||||
t[#t + 1] = tostring(url)
|
t[#t + 1] = tostring(url)
|
||||||
|
|||||||
@@ -17,4 +17,6 @@ local function entry(st)
|
|||||||
ya.app_emit("resize", {})
|
ya.app_emit("resize", {})
|
||||||
end
|
end
|
||||||
|
|
||||||
return { entry = entry }
|
local function enabled(st) return st.old ~= nil end
|
||||||
|
|
||||||
|
return { entry = entry, enabled = enabled }
|
||||||
|
|||||||
Reference in New Issue
Block a user