.config/nvim/lua/local/tig.lua

changeset 1160
28e64ed03c25
parent 1159
9a19621f294c
child 1161
2543467f42da
equal deleted inserted replaced
1159:9a19621f294c 1160:28e64ed03c25
1 local api = vim.api
2 local fn = vim.fn
3
4 local function tig(ctx)
5 local cmd = ctx.fargs
6 local orig_number = vim.wo.number
7
8 local buf = api.nvim_create_buf(false, true)
9 vim.bo[buf].bufhidden = "delete"
10
11 api.nvim_set_current_buf(buf)
12 vim.wo.number = false
13
14 table.insert(cmd, 1, "tig")
15 fn.termopen(cmd, {
16 on_exit = function()
17 vim.wo.number = orig_number
18 vim.cmd.buffer("#")
19 end,
20 })
21 end
22
23 api.nvim_create_user_command("Tig", tig, { nargs = "*", complete = "file" })
24
25 api.nvim_create_user_command("TigBlame", function()
26 tig({ fargs = { "blame", "+" .. fn.line("."), "--", fn.expand("%") } })
27 end, {})
28
29 api.nvim_create_user_command("TigLog", function()
30 tig({ fargs = { "log", "-p", "--", fn.expand("%") } })
31 end, {})

mercurial