Super keymaps

This commit is contained in:
2025-12-07 18:47:34 +00:00
parent 2a4578e1eb
commit 256a5695ed

View File

@@ -18,6 +18,96 @@ local function command_with_dir(dir, cmd)
return '!' .. cmd return '!' .. cmd
end end
local function get_scope_from_file(filename)
local ext = filename:match '%.(%w+)$'
local base_name = filename:match '^(%w+)%.?%w*$'
local extensionSuffixes = {
php = { 'Controller', 'Repository', 'StoreRequest', 'UpdateRequest', 'Request', 'Resource', 'Test', 'Observer', 'Policy', 'Seeder', 'Factory' },
['[jt]s'] = { 'Service' },
}
for suffix_type, _ in pairs(extensionSuffixes) do
if ext:match(suffix_type) then
local suffixes = extensionSuffixes[suffix_type]
for _, suffix in ipairs(suffixes) do
local scope = base_name:match('^(%w+)' .. suffix .. '$')
if scope then
return scope
end
end
end
end
return base_name
end
local function navigate_using_suffix(suffix)
local scope = get_scope_from_file(vim.fn.expand '%:t')
local file_name = scope .. suffix
local file_path = vim.system({ 'git', 'ls-files', file_name, '**/' .. file_name }):wait().stdout
if file_path ~= '' then
vim.cmd('edit ' .. file_path)
else
vim.notify('File ' .. file_name .. ' not found in git ls-files', vim.log.levels.ERROR)
end
end
local function create_navigation_maps(maps)
for key, suffix_and_name in pairs(maps) do
map('<Leader>n' .. key, function()
navigate_using_suffix(suffix_and_name[1])
end, { desc = 'Navigate to relevant ' .. suffix_and_name[2] })
end
end
local function create_bookmark(key, bookmark)
map('<Leader>b' .. key, function()
vim.cmd('edit ' .. bookmark)
end, { desc = 'Navigate to ' .. bookmark })
end
local function create_bookmark_maps(maps)
for key, bookmark in pairs(maps) do
create_bookmark(key, bookmark)
end
end
local function laravel_bookmarks_with_dir(dir)
create_bookmark_maps {
['e'] = dir .. '/.env',
['l'] = dir .. '/storage/logs/laravel.log',
['w'] = dir .. '/routes/web.php',
['a'] = dir .. '/routes/api.php',
['m'] = dir .. '/database/migrations',
['dc'] = dir .. '/app/Core/',
['dd'] = dir .. '/app/Data/',
['dE'] = dir .. '/app/Enums/',
['de'] = dir .. '/app/Events/',
['dh'] = dir .. '/app/Http/',
['dj'] = dir .. '/app/Jobs/',
['dl'] = dir .. '/app/Listeners/',
['dM'] = dir .. '/app/Mail/',
['dm'] = dir .. '/app/Models/',
['dn'] = dir .. '/app/Notifications/',
['do'] = dir .. '/app/Observers/',
['dp'] = dir .. '/app/Providers/',
['pa'] = dir .. '/app/Providers/AppServiceProvider.php',
['pe'] = dir .. '/app/Providers/EventServiceProvider.php',
['cA'] = dir .. '/config/app.php',
['ca'] = dir .. '/config/auth.php',
['cb'] = dir .. '/config/broadcasting.php',
['cd'] = dir .. '/config/database.php',
['cf'] = dir .. '/config/filesystems.php',
['ch'] = dir .. '/config/filesystems.php',
['cl'] = dir .. '/config/logging.php',
['cm'] = dir .. '/config/mail.php',
['cq'] = dir .. '/config/queue.php',
['cS'] = dir .. '/config/services.php',
['cs'] = dir .. '/config/session.php',
}
end
local function laravel_keymaps(dir) local function laravel_keymaps(dir)
map('sl ', command_with_dir(dir, 'vendor/bin/sail '), { desc = 'Run sail command' }, 'c') 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('art ', command_with_dir(dir, 'php artisan '), { desc = 'Run artisan command' }, 'c')
@@ -26,6 +116,15 @@ local function laravel_keymaps(dir)
map('<Leader>pm', ':' .. command_with_dir(dir, 'vendor/bin/sail artisan migrate<CR>')) 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>pr', ':' .. command_with_dir(dir, 'vendor/bin/sail artisan migrate:rollback<CR>'))
map('<Leader>pM', ':' .. command_with_dir(dir, 'vendor/bin/sail artisan make:')) map('<Leader>pM', ':' .. command_with_dir(dir, 'vendor/bin/sail artisan make:'))
create_navigation_maps {
['m'] = { '.php', 'model' },
['c'] = { 'Controller.php', 'controller' },
['p'] = { 'Policy.php', 'policy' },
['R'] = { 'Resource.php', 'resource' },
['r'] = { 'Request.php', 'request' },
['t'] = { 'Test.php', 'test file' },
}
laravel_bookmarks_with_dir(dir)
end end
-- Define per-project configuration here. -- Define per-project configuration here.
@@ -65,10 +164,9 @@ local PROJECTS = {
map('<leader>pd', function() map('<leader>pd', function()
helpers.open_term { cmd = 'lazysql mysql://root@localhost:3306/runcats' } helpers.open_term { cmd = 'lazysql mysql://root@localhost:3306/runcats' }
end, { desc = 'Open database manager' }) end, { desc = 'Open database manager' })
map('<leader>E', ':e .env<CR>', { desc = 'Edit .env file' })
map('s ', '!cd server && ', { desc = 'Run command in server directory' }, 'c') map('s ', '!cd server && ', { desc = 'Run command in server directory' }, 'c')
map('c ', '!cd client && ', { desc = 'Run command in client directory' }, 'c') map('c ', '!cd client && ', { desc = 'Run command in client directory' }, 'c')
laravel_keymaps('server') laravel_keymaps 'server'
map('yrn ', '!cd client && yarn ', { desc = 'Run yarn script' }, 'c') map('yrn ', '!cd client && yarn ', { desc = 'Run yarn script' }, 'c')
map('<Leader>pt', ':!cd server && php artisan typescript:transform --format<CR>', { desc = 'Compile typescript' }) map('<Leader>pt', ':!cd server && php artisan typescript:transform --format<CR>', { desc = 'Compile typescript' })
require('conform').formatters.pint = { require('conform').formatters.pint = {
@@ -76,6 +174,12 @@ local PROJECTS = {
'--config=' .. dir .. '/server/pint.json', '--config=' .. dir .. '/server/pint.json',
}, },
} }
create_bookmark('E', dir .. '/client/src/types/api/endpointMap.d.ts')
create_bookmark('q', dir .. '/client/quasar.config.ts')
create_bookmark('db', dir .. '/client/src/boot')
create_bookmark('ds', dir .. '/client/src/stores')
create_bookmark('dS', dir .. '/client/src/services')
end, end,
['hylark'] = function(dir) ['hylark'] = function(dir)
@@ -83,7 +187,6 @@ local PROJECTS = {
map('<leader>pd', function() map('<leader>pd', function()
helpers.open_term { cmd = 'lazysql pgsql://homestead:password@localhost:5432/homestead' } helpers.open_term { cmd = 'lazysql pgsql://homestead:password@localhost:5432/homestead' }
end, { desc = 'Open database manager' }) end, { desc = 'Open database manager' })
map('<leader>E', ':e .env', { desc = 'Edit .env file' })
laravel_keymaps() laravel_keymaps()
map('yrn ', '!cd frontend && yarn ', { desc = 'Run yarn script' }, 'c') map('yrn ', '!cd frontend && yarn ', { desc = 'Run yarn script' }, 'c')
end, end,