summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyren223 <contact@kyren.codes>2026-08-04 01:47:23 +0300
committerKyren223 <contact@kyren.codes>2026-08-04 01:47:23 +0300
commitbbab705ca72572c74f4ad613c7a88870357bdb17 (patch)
tree19779605018d646a8bec43da3d8af45ca18dac16
parentf6fbee45c91de948c9cb940f0c7a4d895c1767e3 (diff)
Add scratch buffers and automatic insertion of first section in buffers
to the git commit
-rw-r--r--.config/k/config.toml4
-rw-r--r--.config/nvim/lua/extra.lua90
2 files changed, 92 insertions, 2 deletions
diff --git a/.config/k/config.toml b/.config/k/config.toml
index 00bece9..9b8d6dd 100644
--- a/.config/k/config.toml
+++ b/.config/k/config.toml
@@ -85,6 +85,7 @@ jellyfin
nss-tools
# opensnitch-1.8.0-1.x86_64.rpm opensnitch-ui-1.8.0-1.noarch.rpm
# Portmaster-2.1.19-1.x86_64.rpm
+# littlesnitch-1.0.9-1.x86_64.rpm
entr
chafa
kitten # Fix fastfetch not rendering images properly inside tmux
@@ -135,6 +136,9 @@ qemu-kvm libvirt virt-manager
gmp-devel libmpc-devel mpfr-devel
grub2-pc
+# Gamedev
+raylib-devel
+
kopia kopia-ui
'''
diff --git a/.config/nvim/lua/extra.lua b/.config/nvim/lua/extra.lua
index 067f63e..3af98a7 100644
--- a/.config/nvim/lua/extra.lua
+++ b/.config/nvim/lua/extra.lua
@@ -192,8 +192,7 @@ vim.api.nvim_create_autocmd({ 'BufNewFile', 'BufEnter' }, {
if project_name == 'krypton' then
copyright = {
- '// Copyright (c) Kyren223',
- '// Licensed under the MIT license (https://opensource.org/license/mit/)',
+ '// Copyright (c) 2026 Kyren <contact@kyren.codes>. All rights reserved.',
'',
}
@@ -946,5 +945,92 @@ vim.api.nvim_create_autocmd({ 'TextChanged', 'TextChangedI', 'BufEnter', 'BufWri
require('lsphover')
----------------------------------------------------------------------------
+-- NOTE: Global and per-project Scratch buffers
+----------------------------------------------------------------------------
+
+local global_scratch_path = '$HOME/personal/grimoire/scratch.md'
+local workspace_scratch_path = '.scratch.md'
+
+local function open_scratch_buffer(is_global)
+ local scratch_file = is_global and global_scratch_path or vim.fn.fnamemodify(workspace_scratch_path, ':p')
+ scratch_file = vim.fn.expand(scratch_file)
+
+ -- Open the file in a new tab
+ vim.cmd('tabedit ' .. vim.fn.fnameescape(scratch_file))
+ vim.bo.filetype = 'markdown' -- syntax highlighting
+
+ -- Map `q` in normal mode to save and close the tab (buffer-local)
+ vim.keymap.set('n', 'q', function()
+ vim.cmd('silent! write')
+ vim.cmd('tabclose')
+ end, { buffer = true, silent = true })
+
+ -- Enable auto-saving on text change or leaving the buffer
+ vim.api.nvim_create_autocmd({ 'TextChanged', 'TextChangedI', 'BufLeave' }, {
+ buffer = 0,
+ callback = function()
+ vim.cmd('silent! write')
+ end,
+ })
+end
+
+local function open_scratch_buffer_map(is_global)
+ return function()
+ open_scratch_buffer(is_global)
+ end
+end
+
+vim.keymap.set('n', '<leader>ge', open_scratch_buffer_map(true))
+vim.keymap.set('n', '<leader>we', open_scratch_buffer_map(false))
+
+----------------------------------------------------------------------------
+-- NOTE: Insert commit msg into commit buffer in neogit
+----------------------------------------------------------------------------
+
+local commit_msg = 'Your default commit message\nTest\nMultiline'
+
+local group = vim.api.nvim_create_augroup('NeogitCommitMessage', { clear = true })
+
+vim.api.nvim_create_autocmd('FileType', {
+ group = group,
+ pattern = 'gitcommit',
+ callback = function(args)
+ local buf = args.buf
+
+ local line = vim.api.nvim_buf_get_lines(buf, 0, 1, false)[1]
+ if line ~= '' then
+ return
+ end
+
+ local path = vim.fn.fnamemodify(workspace_scratch_path, ':p')
+ local lines = vim.fn.readfile(path)
+ local scratch_bufnr = vim.fn.bufnr(path)
+ if scratch_bufnr ~= -1 and vim.api.nvim_buf_is_loaded(scratch_bufnr) then
+ lines = vim.api.nvim_buf_get_lines(scratch_bufnr, 0, -1, false)
+ end
+
+ vim.notify('path:' .. path)
+ vim.notify('file:' .. vim.inspect(vim.fn.readfile(path)))
+ vim.notify('lines:' .. vim.inspect(lines))
+
+ local commit_lines = {}
+ for _, line in ipairs(lines) do
+ if line:find('---', 1, true) then
+ break
+ end
+ table.insert(commit_lines, line)
+ end
+
+ vim.notify('commit_lines:' .. vim.inspect(commit_lines))
+
+ if #commit_lines > 0 then
+ vim.api.nvim_buf_set_lines(buf, 0, 1, false, commit_lines)
+ -- Place cursor at end of first line
+ vim.api.nvim_win_set_cursor(0, { 1, #commit_lines[#commit_lines] })
+ end
+ end,
+})
+
+----------------------------------------------------------------------------
-- NOTE:
----------------------------------------------------------------------------