Fri, 10 Mar 2023 18:38:00 -0500
port tig plugin to lua
.config/nvim/init.lua | file | annotate | diff | comparison | revisions | |
.config/nvim/lua/local/tig.lua | file | annotate | diff | comparison | revisions | |
.config/nvim/plugin/tig.vim | file | annotate | diff | comparison | revisions |
--- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -4,6 +4,7 @@ require("config.options") require("lazy-bootstrap") require("config.maps") require("config.lsp") +require("local.tig").setup() -- >> Builtin g.netrw_altfile = 1
new file mode 100644 --- /dev/null +++ b/.config/nvim/lua/local/tig.lua @@ -0,0 +1,37 @@ +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 +}
deleted file mode 100644 --- a/.config/nvim/plugin/tig.vim +++ /dev/null @@ -1,18 +0,0 @@ -func! tig#Tig(...) abort - enew - setl nonumber - call termopen(["tig"] + a:000, {'on_exit': 'tig#TigExit'}) -endfunc - -func! tig#TigBlame() abort - call tig#Tig('blame', '+' . line('.'), '--', expand('%')) -endfunc - -func! tig#TigExit(...) abort - buffer # -endfunc - -command! -nargs=* -complete=file Tig call tig#Tig(<f-args>) -command! TigBlame call tig#TigBlame() -command! TigLog call tig#Tig('log', '-p', '--', expand('%')) -