-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): added multiple options for diff command
- Loading branch information
Showing
6 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ end | |
|
||
M.keys = { | ||
hover = "K", | ||
diff = "d", | ||
close = "q", | ||
details = "<cr>", | ||
profile_sort = "<C-s>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
local Util = require("lazy.util") | ||
|
||
local M = {} | ||
|
||
---@alias LazyDiff {commit:string} | {from:string, to:string} | ||
---@alias LazyDiffFun fun(plugin:LazyPlugin, diff:LazyDiff) | ||
|
||
M.handlers = { | ||
|
||
---@type LazyDiffFun | ||
browser = function(plugin, diff) | ||
if plugin.url then | ||
local url = plugin.url:gsub("%.git$", "") | ||
if diff.commit then | ||
Util.open(url .. "/commit/" .. diff.commit) | ||
else | ||
Util.open(url .. "/compare/" .. diff.from .. ".." .. diff.to) | ||
end | ||
else | ||
Util.error("No url for " .. plugin.name) | ||
end | ||
end, | ||
|
||
---@type LazyDiffFun | ||
["diffview.nvim"] = function(plugin, diff) | ||
if diff.commit then | ||
vim.cmd.DiffviewOpen(("-C=%s"):format(plugin.dir) .. " " .. diff.commit) | ||
else | ||
vim.cmd.DiffviewOpen(("-C=%s"):format(plugin.dir) .. " " .. diff.from .. ".." .. diff.to) | ||
end | ||
end, | ||
|
||
---@type LazyDiffFun | ||
git = function(plugin, diff) | ||
local cmd = { "git", "diff" } | ||
if diff.commit then | ||
cmd[#cmd + 1] = diff.commit | ||
else | ||
cmd[#cmd + 1] = diff.from | ||
cmd[#cmd + 1] = diff.to | ||
end | ||
Util.open_cmd(cmd, { cwd = plugin.dir, filetype = "git" }) | ||
end, | ||
|
||
---@type LazyDiffFun | ||
terminal_git = function(plugin, diff) | ||
local cmd = { "git", "diff" } | ||
if diff.commit then | ||
cmd[#cmd + 1] = diff.commit | ||
else | ||
cmd[#cmd + 1] = diff.from | ||
cmd[#cmd + 1] = diff.to | ||
end | ||
Util.open_cmd(cmd, { cwd = plugin.dir, terminal = true, env = { PAGER = "cat" } }) | ||
end, | ||
} | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters