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

Sat, 11 Mar 2023 01:51:23 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Sat, 11 Mar 2023 01:51:23 -0500
changeset 1075
3b88450bda15
parent 1074
91b42a87c3d9
child 1076
15007f695dfb
permissions
-rw-r--r--

port custom autocmds to lua

1074
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
1 local api = vim.api
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
2 local fn = vim.fn
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
3
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
4 local function tig(ctx)
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
5 local cmd = ctx.fargs
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
6 local orig_number = vim.wo.number
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
7
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
8 local buf = api.nvim_create_buf(false, true)
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
9 vim.bo[buf].bufhidden = "delete"
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
10
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
11 api.nvim_set_current_buf(buf)
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
12 vim.wo.number = false
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
13
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
14 table.insert(cmd, 1, "tig")
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
15 fn.termopen(cmd, {
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
16 on_exit = function()
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
17 vim.wo.number = orig_number
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
18 vim.cmd.buffer("#")
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
19 end,
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
20 })
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
21 end
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
22
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
23 local function setup(config)
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
24 api.nvim_create_user_command("Tig", tig, { nargs = "*", complete = "file" })
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
25
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
26 api.nvim_create_user_command("TigBlame", function()
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
27 tig({fargs = {"blame", "+" .. fn.line("."), "--", fn.expand("%")}})
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
28 end, {})
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
29
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
30 api.nvim_create_user_command("TigLog", function()
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
31 tig({fargs = {"log", "-p", "--", fn.expand("%")}})
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
32 end, {})
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
33 end
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
34
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
35 return {
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
36 setup = setup
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
37 }

mercurial