Sat, 11 Mar 2023 01:51:23 -0500
port custom autocmds to lua
1074 | 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 | local function setup(config) | |
24 | api.nvim_create_user_command("Tig", tig, { nargs = "*", complete = "file" }) | |
25 | ||
26 | api.nvim_create_user_command("TigBlame", function() | |
27 | tig({fargs = {"blame", "+" .. fn.line("."), "--", fn.expand("%")}}) | |
28 | end, {}) | |
29 | ||
30 | api.nvim_create_user_command("TigLog", function() | |
31 | tig({fargs = {"log", "-p", "--", fn.expand("%")}}) | |
32 | end, {}) | |
33 | end | |
34 | ||
35 | return { | |
36 | setup = setup | |
37 | } |