diff --git a/nvim/.config/nvim/lua/gitlens.lua b/nvim/.config/nvim/lua/gitlens.lua new file mode 100644 index 0000000..bdd715d --- /dev/null +++ b/nvim/.config/nvim/lua/gitlens.lua @@ -0,0 +1,42 @@ +local M = {} +local api = vim.api + +function M.blameVirtText() + + -- get the current file extension + local ft = vim.fn.expand('%:h:t') + + if ft == '' or ft == 'bin' then -- if we are in a scratch buffer, unknown filetype, or nvim's terminal window + return + end + + M.clearBlameVirtText() + + local currFile = vim.fn.expand('%') + local line = api.nvim_win_get_cursor(0) + local blame = vim.fn.system(string.format('git blame -c -L %d,%d %s', line[1], line[1], currFile)) + local hash = vim.split(blame, '%s')[1] + local cmd = string.format("git show %s ", hash).."--format='%an | %ar | %s'" + + if hash == '00000000' then + text = 'Not Committed Yet' + else + text = vim.fn.system(cmd) + text = vim.split(text, '\n')[1] + if text:find("fatal") then -- if the call to git show fails + text = 'Not Committed Yet' + end + end + + -- set virtual text for namespace 2 with the content from git and assign it to the higlight group 'GitLens' + api.nvim_buf_set_virtual_text(0, 2, line[1] - 1, {{ text,'GitLens' }}, {}) + +end + +-- important for clearing out the text when our cursor moves +function M.clearBlameVirtText() + -- clear out virtual text from namespace 2 (the namespace we will set later) + api.nvim_buf_clear_namespace(0, 2, 0, -1) +end + +return M diff --git a/nvim/.config/nvim/lua/scratchpad.lua b/nvim/.config/nvim/lua/scratchpad.lua new file mode 100644 index 0000000..7e58c45 --- /dev/null +++ b/nvim/.config/nvim/lua/scratchpad.lua @@ -0,0 +1,11 @@ +local api = vim.api +local M= {} + +function M.makeScratch() + api.nvim_command('enew') + -- vim.bo[0].bufhidden=hide + vim.bo[0].buftype=nofile + vim.bo[0].swapfile=false +end + +return M diff --git a/nvim/.config/nvim/plugin/personal/gitlens.vim b/nvim/.config/nvim/plugin/personal/gitlens.vim new file mode 100644 index 0000000..250d158 --- /dev/null +++ b/nvim/.config/nvim/plugin/personal/gitlens.vim @@ -0,0 +1,23 @@ +function s:setupGitLens() + " -- disable gitlens unconditionally, and remove virtual text + lua require('gitlens').clearBlameVirtText() + augroup GitLens + autocmd! + augroup END + + " -- if it is wanted enable gitlens on holding the cursor + if g:gitlens_enable + augroup GitLens + autocmd! CursorHold * lua require('gitlens').blameVirtText() + autocmd! CursorMoved * lua require('gitlens').clearBlameVirtText() + autocmd! CursorMovedI * lua require('gitlens').clearBlameVirtText() + augroup END + endif +endfunction + +function s:toggleGitLens() + let g:gitlens_enable = !get(g:, 'gitlens_enable', 1) + call s:setupGitLens() +endfunction + +command! GitLensToggle call s:toggleGitLens() diff --git a/nvim/.config/nvim/plugin/personal/makescratch.vim b/nvim/.config/nvim/plugin/personal/makescratch.vim new file mode 100644 index 0000000..1a5a233 --- /dev/null +++ b/nvim/.config/nvim/plugin/personal/makescratch.vim @@ -0,0 +1,5 @@ +function s:makeScratch() + lua require('scratchpad').makeScratch() +endfunction + +command! ScratchPad call s:makeScratch()