2025-11-07 14:27:25 +00:00
|
|
|
-- Project specific settings
|
|
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
|
|
-- Helper to create mappings
|
2025-11-07 22:10:53 +00:00
|
|
|
local helpers = require 'helpers'
|
|
|
|
|
local map = helpers.map
|
2025-11-07 14:27:25 +00:00
|
|
|
|
|
|
|
|
-- Get the last folder name from a path
|
|
|
|
|
local function project_name_from_cwd(cwd)
|
|
|
|
|
return vim.fn.fnamemodify(cwd, ':t')
|
|
|
|
|
end
|
|
|
|
|
|
2025-11-16 10:01:02 +00:00
|
|
|
local function command_with_dir(dir, cmd)
|
|
|
|
|
if dir then
|
|
|
|
|
return '!cd ' .. dir .. ' && ' .. cmd
|
|
|
|
|
end
|
|
|
|
|
return '!' .. cmd
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function laravel_keymaps(dir)
|
|
|
|
|
map('sl ', command_with_dir(dir, 'vendor/bin/sail '), { desc = 'Run sail command' }, 'c')
|
|
|
|
|
map('art ', command_with_dir(dir, 'php artisan '), { desc = 'Run artisan command' }, 'c')
|
|
|
|
|
map('sart ', command_with_dir(dir, 'vendor/bin/sail artisan '), { desc = 'Run artisan command with sail' }, 'c')
|
|
|
|
|
map('cmp ', command_with_dir(dir, 'composer '), { desc = 'Run composer script' }, 'c')
|
|
|
|
|
map('<Leader>pm', ':'..command_with_dir(dir, 'vendor/bin/sail artisan migrate<CR>'))
|
|
|
|
|
map('<Leader>pr', ':'..command_with_dir(dir, 'vendor/bin/sail artisan migrate:rollback<CR>'))
|
|
|
|
|
map('<Leader>pM', ':'..command_with_dir(dir, 'vendor/bin/sail artisan make:'))
|
|
|
|
|
end
|
|
|
|
|
|
2025-11-07 14:27:25 +00:00
|
|
|
-- Define per-project configuration here.
|
|
|
|
|
-- Keys are folder names (last segment of your cwd).
|
|
|
|
|
local PROJECTS = {
|
|
|
|
|
-- Example: a repo folder
|
2025-11-09 23:03:51 +00:00
|
|
|
['runcats'] = function(dir)
|
|
|
|
|
-- local dump_buf = vim.api.nvim_create_buf(false, true)
|
|
|
|
|
-- vim.api.nvim_set_option_value('bufhidden', 'hide', { buf = dump_buf })
|
|
|
|
|
-- vim.api.nvim_set_option_value('modifiable', false, { buf = dump_buf })
|
|
|
|
|
--
|
|
|
|
|
-- vim.fn.jobstart('cd server && sail artisan dump-server', {
|
|
|
|
|
-- term = true,
|
|
|
|
|
-- })
|
|
|
|
|
|
|
|
|
|
-- map('<leader>dd', function()
|
|
|
|
|
-- local height = math.ceil(vim.o.lines * 0.8)
|
|
|
|
|
-- local width = math.ceil(vim.o.columns * 0.8)
|
|
|
|
|
-- vim.api.nvim_open_win(dump_buf, true, {
|
|
|
|
|
-- style = 'minimal',
|
|
|
|
|
-- relative = 'editor',
|
|
|
|
|
-- width = width,
|
|
|
|
|
-- height = height,
|
|
|
|
|
-- row = math.ceil((vim.o.lines - height) / 2),
|
|
|
|
|
-- col = math.ceil((vim.o.columns - width) / 2),
|
|
|
|
|
-- border = 'single',
|
|
|
|
|
-- })
|
|
|
|
|
--
|
|
|
|
|
-- vim.cmd.startinsert()
|
|
|
|
|
-- end, { desc = 'Open the dump-server window' })
|
|
|
|
|
|
2025-11-07 14:27:25 +00:00
|
|
|
map(
|
2025-11-12 09:21:21 +00:00
|
|
|
'<leader>pl',
|
2025-11-07 14:27:25 +00:00
|
|
|
':cexpr system("cd server && vendor/bin/phpstan analyse --no-progress --error-format=raw --memory-limit=2G -vv") <CR>',
|
|
|
|
|
{ desc = 'Run lint' }
|
|
|
|
|
)
|
2025-11-12 09:21:21 +00:00
|
|
|
map('<leader>pd', function()
|
2025-11-07 22:10:53 +00:00
|
|
|
helpers.open_term { cmd = 'lazysql mysql://root@localhost:3306/runcats' }
|
|
|
|
|
end, { desc = 'Open database manager' })
|
2025-11-11 21:51:41 +00:00
|
|
|
map('<leader>E', ':e .env<CR>', { desc = 'Edit .env file' })
|
2025-11-07 14:27:25 +00:00
|
|
|
map('s ', '!cd server && ', { desc = 'Run command in server directory' }, 'c')
|
|
|
|
|
map('c ', '!cd client && ', { desc = 'Run command in client directory' }, 'c')
|
2025-11-16 10:01:02 +00:00
|
|
|
laravel_keymaps('server')
|
2025-11-07 14:27:25 +00:00
|
|
|
map('yrn ', '!cd client && yarn ', { desc = 'Run yarn script' }, 'c')
|
|
|
|
|
map('ts ', '!cd server && php artisan typescript:transform --format', { desc = 'Compile typescript' }, 'c')
|
2025-11-09 23:03:51 +00:00
|
|
|
require('conform').formatters.pint = {
|
|
|
|
|
append_args = {
|
|
|
|
|
'--config=' .. dir .. '/server/pint.json',
|
|
|
|
|
},
|
|
|
|
|
}
|
2025-11-07 14:27:25 +00:00
|
|
|
end,
|
|
|
|
|
|
2025-11-12 09:21:21 +00:00
|
|
|
['hylark'] = function(dir)
|
|
|
|
|
map('<leader>pl', ':cexpr system("vendor/bin/phpstan analyse --no-progress --error-format=raw --memory-limit=2G -vv") <CR>', { desc = 'Run lint' })
|
|
|
|
|
map('<leader>pd', function()
|
|
|
|
|
helpers.open_term { cmd = 'lazysql pgsql://homestead:password@localhost:5432/homestead' }
|
|
|
|
|
end, { desc = 'Open database manager' })
|
|
|
|
|
map('<leader>E', ':e .env', { desc = 'Edit .env file' })
|
2025-11-16 10:01:02 +00:00
|
|
|
laravel_keymaps()
|
2025-11-12 09:21:21 +00:00
|
|
|
map('yrn ', '!cd frontend && yarn ', { desc = 'Run yarn script' }, 'c')
|
|
|
|
|
end,
|
|
|
|
|
|
2025-11-07 14:27:25 +00:00
|
|
|
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
|
2025-11-09 23:03:51 +00:00
|
|
|
setup(dir)
|
2025-11-07 14:27:25 +00:00
|
|
|
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')
|