local helper = require("kyoh86.plug.ddu.helper") ---@type LazySpec local spec = { { "tennashi/ddu-source-git", dependencies = { "Shougo/ddu.vim", "Shougo/ddu-kind-file", "kyoh86/ddu-source-git_diff_tree" }, config = function() do local source = "git_status" local name = "git-status" helper.map_start("fgs", name, { sources = { { name = source } }, sourceOptions = { _ = { converters = { "git_status_highlight" }, }, }, kindOptions = { git_working_tree = { defaultAction = "custom:edit", }, }, }) local opener = function(command) ---@param args DduActionArguments return function(args) if #args.items ~= 1 then vim.notify("invalid action: it can edit only one file at once", vim.log.levels.WARN, {}) return 1 end vim.cmd[command](args.items[1].action.fileStatus.path) return 0 end end kyoh86.fa.ddu.custom.action("kind", "git_working_tree", "custom:edit", opener("edit")) kyoh86.fa.ddu.custom.action("kind", "git_working_tree", "custom:vnew", opener("vnew")) kyoh86.fa.ddu.custom.action("kind", "git_working_tree", "custom:new", opener("new")) helper.map_ff(name, function(map) map("x", helper.action("itemAction", { name = "custom:new" })) map("v", helper.action("itemAction", { name = "custom:vnew" })) map("a", helper.action("itemAction", { name = "add" })) map("r", helper.action("itemAction", { name = "restore" })) end) end do local source = "git_ref" local name = "git-ref" helper.map_start("fgr", name, { sources = { { name = source } }, kindOptions = { git_branch = { defaultAction = "switch" }, git_tag = { defaultAction = "switch" }, }, }) helper.map_ff(name, function(map) map("d", helper.action("itemAction", { name = "delete" })) end) end do ---@param args DduActionArguments local custom_files = function(args) if #args.items ~= 1 then vim.notify("invalid action: it can edit only one file at once", vim.log.levels.WARN, {}) return 1 end kyoh86.fa.ddu.start({ name = args.options.name, push = true, sources = { { name = "git_diff_tree", params = { commitHash = args.items[1].action.commitHash } } }, }) return 0 end kyoh86.fa.ddu.custom.action("kind", "git_commit", "custom:files", custom_files) local source = "git_log" local name = "git-log" helper.map_start("fgl", name, { sources = { { name = source } }, kindOptions = { git_commit = { defaultAction = "custom:files" }, }, }) helper.map_ff_file(name, function(map) map("f", helper.action("itemAction", { name = "fixupTo" })) end) end end, }, { "kyoh86/ddu-source-git_diff_tree", }, } return spec