summaryrefslogtreecommitdiffstats
path: root/.config/nvim/plugin/50-git.lua
blob: ee5da4666821128a78ee82dae889a75b0e78c42a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
--
-- Git-related utilities
--

vim.pack.add({ "https://github.com/airblade/vim-gitgutter" }) -- Show git status in the gutter

local function git_blame(file, line)
	local sys = vim.system({
		"bash",
		"-c",
		string.format('grep -E "^author |^summary " <(git blame -L %d,%d --porcelain -- %s)', line, line, file),
	}):wait()
	if sys.stdout then
		vim.notify(sys.stdout, vim.log.levels.INFO)
	end
	if sys.code ~= 0 then
		local err_msg = "git blame failed (" .. sys.code .. ")\n" .. sys.stderr
		vim.notify(err_msg, vim.log.levels.ERROR)
	end
end

vim.api.nvim_create_user_command("GitBlame", function()
	git_blame(vim.api.nvim_buf_get_name(0), vim.api.nvim_win_get_cursor(0)[1])
end, { desc = "Show current line git blame" })