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

Sat, 11 Mar 2023 21:38:57 -0600

author
Meredith Howard <mhoward@roomag.org>
date
Sat, 11 Mar 2023 21:38:57 -0600
changeset 1078
aa4c1aa529a5
parent 1076
15007f695dfb
child 1085
c2d11f022cf0
permissions
-rw-r--r--

Start porting custom commands 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()
1076
15007f695dfb clean up unused vim fns
Meredith Howard <mhoward@roomag.org>
parents: 1074
diff changeset
27 tig({ fargs = { "blame", "+" .. fn.line("."), "--", fn.expand("%") } })
1074
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()
1076
15007f695dfb clean up unused vim fns
Meredith Howard <mhoward@roomag.org>
parents: 1074
diff changeset
31 tig({ fargs = { "log", "-p", "--", fn.expand("%") } })
1074
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 {
1076
15007f695dfb clean up unused vim fns
Meredith Howard <mhoward@roomag.org>
parents: 1074
diff changeset
36 setup = setup,
1074
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
37 }

mercurial