.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

local api = vim.api
local fn = vim.fn

local function tig(ctx)
  local cmd = ctx.fargs
  local orig_number = vim.wo.number

  local buf = api.nvim_create_buf(false, true)
  vim.bo[buf].bufhidden = "delete"

  api.nvim_set_current_buf(buf)
  vim.wo.number = false

  table.insert(cmd, 1, "tig")
  fn.termopen(cmd, {
    on_exit = function()
      vim.wo.number = orig_number
      vim.cmd.buffer("#")
    end,
  })
end

local function setup(config)
  api.nvim_create_user_command("Tig", tig, { nargs = "*", complete = "file" })

  api.nvim_create_user_command("TigBlame", function()
    tig({fargs = {"blame", "+" .. fn.line("."), "--", fn.expand("%")}})
  end, {})

  api.nvim_create_user_command("TigLog", function()
    tig({fargs = {"log", "-p", "--", fn.expand("%")}})
  end, {})
end

return {
  setup = setup
}

mercurial