kitchen sink cause I'm too lazy to sort through this junk

This commit is contained in:
2023-08-11 20:43:58 -04:00
parent b8d70ed288
commit 590f030999
23 changed files with 463 additions and 206 deletions

View File

@ -7,6 +7,7 @@ a.nvim_create_augroup('bufcheck', {clear = true})
auto('TextYankPost', { -- highlight yanks
group = 'bufcheck',
pattern = '*',
desc = 'Highlight on yank.',
callback = function()
vim.highlight.on_yank{ timeout = 250 }
end
@ -15,68 +16,20 @@ auto('TextYankPost', { -- highlight yanks
auto('FileType', { -- start git messages in insert mode
group = 'bufcheck',
pattern = { 'gitcommit', 'gitrebase', },
desc = 'Start git messages in insert mode.',
command = 'startinsert | 1'
})
auto('FileType', { -- show git cached diff
group = 'bufcheck',
pattern = { 'gitcommit', 'gitrebase', },
callback = function()
local function lower(a, b)
if a > b then
return b
else
return a
end
end
local function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
local diff = io.popen('git diff --cached', "r")
local diffl = {}
for i in diff:lines() do
table.insert(diffl, i)
end
diff:close()
if next(diffl) == nil then
vim.notify('No diff to show :(', vim.log.levels.INFO, {
title = 'Neovim Config' })
return
end
local buf = a.nvim_create_buf(true, false)
a.nvim_buf_set_lines(buf, 0, -1, false, diffl)
a.nvim_buf_set_name(buf, 'Git Commit Diff')
a.nvim_buf_set_option(buf, 'ft', 'diff')
a.nvim_buf_set_option(buf, 'readonly', true)
a.nvim_buf_set_option(buf, 'modifiable', false)
a.nvim_buf_set_option(buf, 'modified', false)
local win = a.nvim_open_win(buf, false, {
row = 1,
col = 80,
relative = 'win',
width = 80,
height = lower(vim.o.lines - vim.o.cmdheight - 4, tablelength(diffl)),
border = 'shadow',
style = 'minimal',
})
end,
})
auto('BufRead', { -- return to last place
pattern = '*',
command = [[call setpos(".", getpos("'\""))]]
command = [[call setpos(".", getpos("'\""))]],
desc = 'Return to the last place the buffer was closed in.',
})
auto('TermOpen', { -- start terminal in insert mode
group = 'bufcheck',
pattern = '*',
desc = 'Start terminal in insert mode.',
callback = function()
vim.cmd('startinsert | set winfixheight')
o.winfixheight = true
@ -87,6 +40,7 @@ auto('TermOpen', { -- start terminal in insert mode
auto('TermClose', { -- close terminal buffers after shell dies
group = 'bufcheck',
pattern = 'term://*',
desc = 'Close terminal after shell dies.',
callback = function()
vim.cmd('call nvim_input("<CR>")')
o.cmdheight = 1
@ -95,6 +49,7 @@ auto('TermClose', { -- close terminal buffers after shell dies
auto('InsertEnter', { -- toggle things when entering insert mode
group = 'bufcheck',
desc = 'Turn things on insert mode.',
callback = function()
o.colorcolumn = { 80 }
end
@ -102,6 +57,7 @@ auto('InsertEnter', { -- toggle things when entering insert mode
auto('InsertLeave', { -- toggle things when exiting insert mode
group = 'bufcheck',
desc = 'Turn things off insert mode.',
callback = function()
o.colorcolumn = { 0 }
end
@ -110,6 +66,7 @@ auto('InsertLeave', { -- toggle things when exiting insert mode
auto('BufWritePre', { -- make dirs when they don't exist
pattern = '*',
group = vim.api.nvim_create_augroup('auto_create_dir', { clear = true }),
desc = 'Basically mkdir -p.',
callback = function(ctx)
local dir = vim.fn.fnamemodify(ctx.file, ':p:h')
vim.fn.mkdir(dir, 'p')