refactor(lua): reformat and clean up Lua configuration files

This commit is contained in:
Prad Nukala committed 2025-10-24 09:34:24 -04:00
1 parent b4b165fb96
commit 54444c9f33
7 files changed
+771 -825

No files matched your search

+22 -65
View File
@@ -16,7 +16,7 @@ return {
"AstroNvim/astrocore",
---@type AstroCoreOpts
opts = {
sessions = {
-- Configure auto saving
autosave = {
@@ -86,9 +86,15 @@ return {
local filepath = vim.fn.expand "%:p"
local filename = vim.fn.expand "%:t"
-- If no file is open, show Nvim only
-- If no file is open, try to show just the repo name
if filename == "" then
vim.opt.titlestring = "Nvim"
local cwd = vim.fn.getcwd()
local github_match = cwd:match "github%.com/([^/]+/[^/]+)"
if github_match then
vim.opt.titlestring = github_match
else
vim.opt.titlestring = "Nvim"
end
return
end
@@ -96,8 +102,8 @@ return {
local github_match = filepath:match "github%.com/([^/]+/[^/]+)"
if github_match then
-- Format: filename (org/repo) | Nvim
vim.opt.titlestring = string.format("%s (%s) | Nvim", filename, github_match)
-- Format: filename | org/repo
vim.opt.titlestring = string.format("%s | %s", filename, github_match)
else
-- Fallback: filename | Nvim
vim.opt.titlestring = string.format("%s | Nvim", filename)
@@ -105,13 +111,13 @@ return {
end,
},
},
-- Show recent files or git repos on startup
-- Show smart picker on startup
startup_picker = {
{
event = "VimEnter",
desc = "Show recent files for git repo or git repos picker on startup",
desc = "Show smart picker on startup",
callback = function()
-- Skip if opening with arguments (files, directories, stdin)
-- Skip if opening with arguments
if vim.fn.argc() > 0 then return end
-- Skip if current buffer has content
@@ -120,58 +126,8 @@ return {
-- Delay to ensure everything is loaded
vim.defer_fn(function()
-- Check if we're in a git repo
local git_dir = vim.fn.systemlist("git rev-parse --git-dir 2>/dev/null")[1]
local is_git_repo = vim.v.shell_error == 0 and git_dir ~= nil and git_dir ~= ""
if is_git_repo then
-- In a git repo: show recent files
require("snacks").picker.recent()
else
-- Not in a git repo: show git repos using ghq
if vim.fn.executable "ghq" == 1 then
-- Get list of repos from ghq
local repos = vim.fn.systemlist "ghq list --full-path"
if #repos > 0 then
-- Build items list with formatted display
local items = {}
for _, repo_path in ipairs(repos) do
-- Extract org/repo from path
local display = repo_path:match "github%.com/([^/]+/[^/]+)" or vim.fn.fnamemodify(repo_path, ":t")
table.insert(items, {
text = display,
path = repo_path,
})
end
-- Use snacks picker to show repos
require("snacks").picker({
title = "Git Repositories",
layout = { preview = false },
items = items,
format = function(item)
return { { item.text } }
end,
confirm = function(picker, item)
picker:close()
-- Change to the selected repo directory
vim.cmd("cd " .. item.path)
-- Show recent files from the new directory
vim.defer_fn(function()
require("snacks").picker.recent()
end, 50)
end,
})
else
-- Fallback to recent files if no repos found
require("snacks").picker.recent()
end
else
-- ghq not available, just show recent files
require("snacks").picker.recent()
end
end
end, 10)
require("snacks").picker.smart()
end, 50)
end,
},
},
@@ -511,10 +467,10 @@ return {
},
-- AI/Assistant mappings (Claude Code)
["<C-a>"] = { nil, desc = "AI/Claude Code" },
["<C-a><C-a>"] = { function() _G.claude_at_root("ClaudeCode")() end, desc = "Toggle Claude" },
["<C-a>f"] = { function() _G.claude_at_root("ClaudeCodeFocus")() end, desc = "Focus Claude" },
["<C-a>C"] = { function() _G.claude_at_root("ClaudeCode --resume")() end, desc = "Resume Claude" },
["<C-a>c"] = { function() _G.claude_at_root("ClaudeCode --continue")() end, desc = "Continue Claude" },
["<C-a><C-a>"] = { function() _G.claude_at_root "ClaudeCode"() end, desc = "Toggle Claude" },
["<C-a>f"] = { function() _G.claude_at_root "ClaudeCodeFocus"() end, desc = "Focus Claude" },
["<C-a>C"] = { function() _G.claude_at_root "ClaudeCode --resume"() end, desc = "Resume Claude" },
["<C-a>c"] = { function() _G.claude_at_root "ClaudeCode --continue"() end, desc = "Continue Claude" },
["<C-a>m"] = { "<cmd>ClaudeCodeSelectModel<cr>", desc = "Select Claude model" },
["<C-a>b"] = { "<cmd>ClaudeCodeAdd %<cr>", desc = "Add current buffer" },
["<C-a>y"] = { "<cmd>ClaudeCodeDiffAccept<cr>", desc = "Accept diff" },
@@ -575,7 +531,8 @@ return {
},
["<leader>ua"] = {
function() require("snacks").toggle.animate():toggle() end,
desc = "Toggle Animations", },
desc = "Toggle Animations",
},
["<leader>uS"] = {
function() require("snacks").toggle.scroll():toggle() end,
desc = "Toggle Smooth Scroll",
+664 -702
View File
File diff suppressed because it is too large. Load diff
+1 -3
View File
@@ -12,9 +12,7 @@ return {
-- Helper function to get git root and change directory
local function ensure_git_root()
local git_root = vim.fn.systemlist("git rev-parse --show-toplevel")[1]
if git_root and vim.v.shell_error == 0 then
vim.api.nvim_set_current_dir(git_root)
end
if git_root and vim.v.shell_error == 0 then vim.api.nvim_set_current_dir(git_root) end
end
-- Wrapper function to run commands at git root
+34
View File
@@ -0,0 +1,34 @@
-- Customize Mason
-- This file configures non-LSP tools (formatters, linters, debuggers, etc.)
-- LSP servers are configured in astrolsp.lua via mason-lspconfig
---@type LazySpec
return {
-- use mason-tool-installer for automatically installing Mason packages
{
"WhoIsSethDaniel/mason-tool-installer.nvim",
-- overrides `require("mason-tool-installer").setup(...)`
opts = {
-- Make sure to use the names found in `:Mason`
ensure_installed = {
-- Formatters (non-LSP)
"stylua",
"rustfmt",
"taplo",
-- Linters
"stylelint",
"markdownlint",
-- Debuggers
"debugpy",
-- Other tools
"tree-sitter-cli",
-- Note: oxlint and oxfmt should be installed separately via cargo/npm
-- Note: LSP servers are configured in astrolsp.lua
},
},
},
}
+1 -1
View File
@@ -36,7 +36,7 @@ return {
self.esc_timer = self.esc_timer or (vim.uv or vim.loop).new_timer()
if self.esc_timer:is_active() then
self.esc_timer:stop()
vim.cmd("stopinsert")
vim.cmd "stopinsert"
else
self.esc_timer:start(200, 0, function() end)
return "<esc>"
+48 -53
View File
@@ -23,6 +23,52 @@ return {
template.register("{{_dir_}}", function() return vim.fn.expand "%:p:h" end)
template.register("{{_project_}}", function() return vim.fn.fnamemodify(vim.fn.getcwd(), ":t") end)
-- Helper function to insert template
local function insert_template(lines)
local cursor_line = nil
local processed = {}
for i, line in ipairs(lines) do
-- Replace template markers
line = line:gsub("{{_date_}}", os.date "%Y-%m-%d %H:%M:%S")
line = line:gsub("{{_author_}}", "Prad")
line = line:gsub("{{_email_}}", "prad@sonr.io")
line = line:gsub("{{_file_name_}}", vim.fn.expand "%:t:r")
line = line:gsub("{{_upper_file_}}", vim.fn.expand("%:t:r"):upper())
-- Convert snake_case to CamelCase
local file_name = vim.fn.expand "%:t:r"
local camel_case = file_name:gsub("_(%w)", function(c) return c:upper() end)
camel_case = camel_case:gsub("^%w", string.upper)
line = line:gsub("{{_camel_case_file_}}", camel_case)
-- Handle lua expressions
line = line:gsub("{{_lua:(.-)_}}", function(expr)
local func = load("return " .. expr)
if func then
local ok, result = pcall(func)
if ok then return tostring(result) end
end
return ""
end)
-- Track cursor position
if line:match "{{_cursor_}}" then
cursor_line = i
line = line:gsub("{{_cursor_}}", "")
end
table.insert(processed, line)
end
-- Insert lines at cursor
local row = vim.api.nvim_win_get_cursor(0)[1]
vim.api.nvim_buf_set_lines(0, row - 1, row - 1, false, processed)
-- Set cursor position if marker found
if cursor_line then vim.api.nvim_win_set_cursor(0, { row + cursor_line - 1, 0 }) end
end
-- Custom template picker using Snacks
vim.api.nvim_create_user_command("TemplateSnacks", function(opts)
local temp_dir = vim.fn.stdpath "config" .. "/templates"
@@ -36,7 +82,6 @@ return {
for _, file in ipairs(template_files) do
if vim.fn.isdirectory(file) == 0 then
local filename = vim.fn.fnamemodify(file, ":t")
local relative_path = vim.fn.fnamemodify(file, ":~:.")
local category = vim.fn.fnamemodify(file, ":h:t")
-- Extract filetype from template
@@ -90,9 +135,7 @@ return {
-- Skip filetype marker line
if not line:match "^;; %w+" then
-- Check for variable placeholder
if line:match "{{_variable_}}" and not variable_name then
needs_variable = true
end
if line:match "{{_variable_}}" and not variable_name then needs_variable = true end
table.insert(processed, line)
end
end
@@ -120,54 +163,6 @@ return {
}
end, { nargs = "?", desc = "Open template picker" })
-- Helper function to insert template
function insert_template(lines)
local cursor_line = nil
local processed = {}
for i, line in ipairs(lines) do
-- Replace template markers
line = line:gsub("{{_date_}}", os.date "%Y-%m-%d %H:%M:%S")
line = line:gsub("{{_author_}}", "Prad")
line = line:gsub("{{_email_}}", "prad@sonr.io")
line = line:gsub("{{_file_name_}}", vim.fn.expand "%:t:r")
line = line:gsub("{{_upper_file_}}", vim.fn.expand("%:t:r"):upper())
-- Convert snake_case to CamelCase
local file_name = vim.fn.expand "%:t:r"
local camel_case = file_name:gsub("_(%w)", function(c) return c:upper() end)
camel_case = camel_case:gsub("^%w", string.upper)
line = line:gsub("{{_camel_case_file_}}", camel_case)
-- Handle lua expressions
line = line:gsub("{{_lua:(.-)_}}", function(expr)
local func, err = load("return " .. expr)
if func then
local ok, result = pcall(func)
if ok then return tostring(result) end
end
return ""
end)
-- Track cursor position
if line:match "{{_cursor_}}" then
cursor_line = i
line = line:gsub("{{_cursor_}}", "")
end
table.insert(processed, line)
end
-- Insert lines at cursor
local row = vim.api.nvim_win_get_cursor(0)[1]
vim.api.nvim_buf_set_lines(0, row - 1, row - 1, false, processed)
-- Set cursor position if marker found
if cursor_line then
vim.api.nvim_win_set_cursor(0, { row + cursor_line - 1, 0 })
end
end
-- Command to create new templates easily
vim.api.nvim_create_user_command("TemplateCreate", function(opts)
local temp_dir = vim.fn.stdpath "config" .. "/templates"
@@ -199,7 +194,7 @@ return {
vim.notify("Created template: " .. template_path, vim.log.levels.INFO)
end, {
nargs = "+",
complete = function(_, line)
complete = function(_, _line)
local temp_dir = vim.fn.stdpath "config" .. "/templates"
local categories = {}