Diffview auto-refresh, yank file path key bindings
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
-- Custom Diffview auto-refresh config from https://richardgill.org/blog/configuring-neovim-coding-agents
|
||||
-- Source: https://github.com/richardgill/nix/blob/ebdd8260f770d242db7b6163158cfe9ad9784c41/modules/home-manager/dot-files/nvim/lua/plugins/git-diff_diffview.lua
|
||||
|
||||
return {
|
||||
"sindrets/diffview.nvim",
|
||||
cmd = { "DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", "DiffviewFocusFiles" },
|
||||
@@ -5,13 +8,13 @@ return {
|
||||
enhanced_diff_hl = true,
|
||||
keymaps = {
|
||||
view = {
|
||||
["gq"] = "<Cmd>DiffviewClose<CR>",
|
||||
{ "n", "gq", "<cmd>DiffviewClose<cr>", { desc = "Close diffview" } },
|
||||
},
|
||||
file_panel = {
|
||||
["gq"] = "<Cmd>DiffviewClose<CR>",
|
||||
{ "n", "gq", "<cmd>DiffviewClose<cr>", { desc = "Close diffview" } },
|
||||
},
|
||||
file_history_panel = {
|
||||
["gq"] = "<Cmd>DiffviewClose<CR>",
|
||||
{ "n", "gq", "<cmd>DiffviewClose<cr>", { desc = "Close diffview" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -19,6 +22,51 @@ return {
|
||||
{ "<leader>gl", ":'<,'>DiffviewFileHistory<cr>", mode = "v", desc = "Toggle git log of selected lines" },
|
||||
{ "<leader>gL", "<cmd>DiffviewFileHistory<cr>", desc = "Toggle git log of current branch" },
|
||||
{ "<leader>gl", "<cmd>DiffviewFileHistory %<cr>", desc = "Toggle git log of current file history" },
|
||||
{ "<leader>gd", "<cmd>DiffviewOpen<cr>", desc = "Git diff current file against the index" },
|
||||
{ "<leader>gv", "<cmd>DiffviewOpen<cr>", desc = "Open [g]it Diff[v]iew tab" },
|
||||
},
|
||||
config = function(_, opts)
|
||||
require("diffview").setup(opts)
|
||||
|
||||
local watcher = require("custom.directory-watcher")
|
||||
|
||||
local is_git_ignored = function(filepath)
|
||||
vim.fn.system("git check-ignore -q " .. vim.fn.shellescape(filepath))
|
||||
return vim.v.shell_error == 0
|
||||
end
|
||||
|
||||
local update_left_pane = function()
|
||||
pcall(function()
|
||||
local lib = require("diffview.lib")
|
||||
local view = lib.get_current_view()
|
||||
if view then
|
||||
view:update_files()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Register handler for file changes in watched directory
|
||||
watcher.registerOnChangeHandler("diffview", function(filepath, events)
|
||||
local is_in_dot_git_dir = filepath:match("/%.git/") or filepath:match("^%.git/")
|
||||
|
||||
if is_in_dot_git_dir or not is_git_ignored(filepath) then
|
||||
vim.notify("[diffview] File changed: " .. vim.fn.fnamemodify(filepath, ":t"), vim.log.levels.INFO)
|
||||
update_left_pane()
|
||||
end
|
||||
end)
|
||||
|
||||
-- Start watching the current working directory
|
||||
watcher.setup({ path = vim.fn.getcwd() })
|
||||
|
||||
vim.api.nvim_create_autocmd("FocusGained", {
|
||||
callback = update_left_pane,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("User", {
|
||||
pattern = "DiffviewViewLeave",
|
||||
callback = function()
|
||||
watcher.stop()
|
||||
vim.cmd(":DiffviewClose")
|
||||
end,
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
||||
6
lua/plugins/yank-path.lua
Normal file
6
lua/plugins/yank-path.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
return {
|
||||
"ywpkwon/yank-path.nvim",
|
||||
config = function()
|
||||
require("yank-path").setup()
|
||||
end,
|
||||
}
|
||||
9
lua/plugins/yank.lua
Normal file
9
lua/plugins/yank.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
-- Load custom yank keymaps for copying file paths + visual selections
|
||||
-- See lua/custom/yank.lua for implementation
|
||||
return {
|
||||
dir = vim.fn.stdpath("config"),
|
||||
name = "custom-yank",
|
||||
config = function()
|
||||
require("custom.yank")
|
||||
end,
|
||||
}
|
||||
Reference in New Issue
Block a user