From f8f6d8e776f2e602668367b28afbc0589f0a16f8 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 7 Nov 2025 14:27:25 +0000 Subject: [PATCH] Quicker and project specific settings --- init.lua | 1 + lua/plugins/codecompanion.lua | 2 - lua/plugins/quicker.lua | 34 +++++++++++++++ lua/projects.lua | 80 +++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 lua/plugins/quicker.lua create mode 100644 lua/projects.lua diff --git a/init.lua b/init.lua index 168ee87..2daeadc 100644 --- a/init.lua +++ b/init.lua @@ -12,6 +12,7 @@ require 'keymap' require 'autocmd' require 'lazy_init' require 'visuals' +require 'projects' require('helpers').edit_cf('v', '/init.lua') diff --git a/lua/plugins/codecompanion.lua b/lua/plugins/codecompanion.lua index 5efe1c9..ba41ea0 100644 --- a/lua/plugins/codecompanion.lua +++ b/lua/plugins/codecompanion.lua @@ -1,5 +1,3 @@ -vim.cmd [[cab cc CodeCompanion]] - return { 'olimorris/codecompanion.nvim', config = function() diff --git a/lua/plugins/quicker.lua b/lua/plugins/quicker.lua new file mode 100644 index 0000000..dcb0445 --- /dev/null +++ b/lua/plugins/quicker.lua @@ -0,0 +1,34 @@ +vim.keymap.set("n", "q", function() + require("quicker").toggle() +end, { desc = "Toggle quickfix" }) +vim.keymap.set("n", "l", function() + require("quicker").toggle({ loclist = true }) +end, { desc = "Toggle loclist" }) + +return { + 'stevearc/quicker.nvim', + ft = 'qf', + ---@module "quicker" + ---@type quicker.SetupOptions + opts = {}, + config = function() + require('quicker').setup({ + keys = { + { + ">", + function() + require("quicker").expand({ before = 2, after = 2, add_to_existing = true }) + end, + desc = "Expand quickfix context", + }, + { + "<", + function() + require("quicker").collapse() + end, + desc = "Collapse quickfix context", + }, + }, + }) + end, +} diff --git a/lua/projects.lua b/lua/projects.lua new file mode 100644 index 0000000..fd0c09b --- /dev/null +++ b/lua/projects.lua @@ -0,0 +1,80 @@ +-- Project specific settings + +local M = {} + +-- Helper to create mappings +local map = require('helpers').map + +-- Get the last folder name from a path +local function project_name_from_cwd(cwd) + return vim.fn.fnamemodify(cwd, ':t') +end + +-- Define per-project configuration here. +-- Keys are folder names (last segment of your cwd). +local PROJECTS = { + -- Example: a repo folder + ['runcats'] = function() + map( + 'pl', + ':cexpr system("cd server && vendor/bin/phpstan analyse --no-progress --error-format=raw --memory-limit=2G -vv") ', + { desc = 'Run lint' } + ) + map('s ', '!cd server && ', { desc = 'Run command in server directory' }, 'c') + map('c ', '!cd client && ', { desc = 'Run command in client directory' }, 'c') + map('sl ', '!cd server && sail ', { desc = 'Run sail command' }, 'c') + map('art ', '!cd server && php artisan ', { desc = 'Run artisan command' }, 'c') + map('sart ', '!cd server && sail artisan ', { desc = 'Run artisan command with sail' }, 'c') + map('cmp ', '!cd server && composer ', { desc = 'Run composer script' }, 'c') + map('yrn ', '!cd client && yarn ', { desc = 'Run yarn script' }, 'c') + map('ts ', '!cd server && php artisan typescript:transform --format', { desc = 'Compile typescript' }, 'c') + end, + + default = function() end, +} + +local last_applied = nil + +function M.apply(cwd) + local dir = cwd or vim.fn.getcwd() + local name = project_name_from_cwd(dir) + if last_applied == name then + return + end + last_applied = name + + local setup = PROJECTS[name] or PROJECTS.default + if type(setup) == 'function' then + setup() + vim.notify(('Project config loaded: %s'):format(name), vim.log.levels.INFO, { title = 'projects.lua' }) + end +end + +-- Apply on startup and when the working directory changes +do + local grp = vim.api.nvim_create_augroup('ProjectConfig', { clear = true }) + + vim.api.nvim_create_autocmd('VimEnter', { + group = grp, + callback = function() + M.apply() + end, + }) + + vim.api.nvim_create_autocmd('DirChanged', { + group = grp, + callback = function(args) + -- args.file is the new cwd for DirChanged + M.apply(args and args.file or nil) + end, + }) +end + +-- Optional command to manually re-apply +vim.api.nvim_create_user_command('ProjectReload', function() + last_applied = nil + M.apply() +end, {}) + +-- Keep your helper line +require('helpers').edit_cf('w', '/lua/projects.lua')