Skip to content

Commit f31d2b4

Browse files
committed
refactor(keymaps): replace utils.vim_cmd and utils.git_cmd with inline functions
Refactored keymap definitions to use inline functions instead of the removed utils.vim_cmd and utils.git_cmd helpers. This change improves clarity and reduces indirection in keymap configuration files. Also removed commented-out code and updated git command handling to use a new local lazy_git_cmd function.
1 parent 6f9cddc commit f31d2b4

File tree

7 files changed

+97
-48
lines changed

7 files changed

+97
-48
lines changed

lua/dcai/keymaps/chat.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ local keymap = {
106106
end,
107107
desc = 'chat finder',
108108
},
109-
-- s = utils.vim_cmd('GpWhisper', 'speech to text'),
110109
----------------------------------------------------------------------------
111110
--- Visual mode below
112111
----------------------------------------------------------------------------

lua/dcai/keymaps/editthings.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ local editthings_keymap = {
7979
function()
8080
-- require('fzf-lua').git_files({ cwd = '~/.config/nvim' })
8181
require('fzf-lua').files({ cwd = '~/.config/nvim' })
82-
-- v = utils.vim_cmd('e ' .. vimrc_to_edit, 'edit vimrc')
8382
end,
8483
desc = 'toggle last used file',
8584
},

lua/dcai/keymaps/git.lua

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
local utils = require('dcai.keymaps.utils')
22

3+
local function lazy_git_cmd(opts, desc)
4+
return utils.lazy_shell_cmd('git', opts, desc)
5+
end
6+
37
local git_keymap = {
48
{ '<leader>g', group = 'git' },
59
{ '<leader>ga', '<cmd>!git add --verbose %<cr>', desc = 'git add' },
@@ -10,21 +14,21 @@ local git_keymap = {
1014
{ '<leader>gc', group = 'git commit' },
1115
{
1216
'<leader>gcU',
13-
utils.git_cmd({
17+
lazy_git_cmd({
1418
args = { 'ciu' },
1519
}),
1620
desc = 'commit all',
1721
},
1822
{
1923
'<leader>gcS',
20-
utils.git_cmd({
24+
lazy_git_cmd({
2125
args = { 'cis' },
2226
}),
2327
desc = 'commit staged',
2428
},
2529
{
2630
'<leader>gcf',
27-
utils.git_cmd({
31+
lazy_git_cmd({
2832
args = { 'commit', '--no-verify', '-a', '--fixup', 'HEAD' },
2933
}),
3034
desc = 'fixup HEAD',
@@ -46,17 +50,17 @@ local git_keymap = {
4650
},
4751
{
4852
'<leader>ghs',
49-
utils.git_cmd({ args = { 'stash' } }),
53+
lazy_git_cmd({ args = { 'stash' } }),
5054
desc = 'git stash',
5155
},
5256
{
5357
'<leader>ghp',
54-
utils.git_cmd({ args = { 'stash', 'pop' } }),
58+
lazy_git_cmd({ args = { 'stash', 'pop' } }),
5559
desc = 'git stash pop',
5660
},
5761
{
5862
'<leader>gj',
59-
utils.git_cmd({
63+
lazy_git_cmd({
6064
args = {
6165
'-c',
6266
'sequence.editor=:',
@@ -112,17 +116,17 @@ local git_keymap = {
112116
},
113117
{
114118
'<leader>gpp',
115-
utils.git_cmd({ args = { 'pull', '--tags', '--rebase' } }),
119+
lazy_git_cmd({ args = { 'pull', '--tags', '--rebase' } }),
116120
desc = 'git pull',
117121
},
118122
{
119123
'<leader>gpP',
120-
utils.git_cmd({ args = { 'push', '-u', '--force-with-lease' } }),
124+
lazy_git_cmd({ args = { 'push', '-u', '--force-with-lease' } }),
121125
desc = 'git push',
122126
},
123127
{
124128
'<leader>gpf',
125-
utils.git_cmd({ args = { 'fetch', '--tags', '--all', '--verbose' } }),
129+
lazy_git_cmd({ args = { 'fetch', '--tags', '--all', '--verbose' } }),
126130
desc = 'git fetch',
127131
},
128132
}

lua/dcai/keymaps/notes.lua

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,34 @@ local notes_keymap = {
1010
end,
1111
desc = 'todo',
1212
},
13-
utils.vim_cmd(
13+
{
1414
'<leader>nb',
15-
'NoteGitBranch',
16-
'create new note for current git branch'
17-
),
18-
utils.vim_cmd('<leader>nc', 'NoteNew', 'create new note'),
19-
utils.vim_cmd(
15+
function()
16+
vim.cmd('NoteGitBranch')
17+
end,
18+
desc = 'create new note for current git branch',
19+
},
20+
{
21+
'<leader>nc',
22+
function()
23+
vim.cmd('NoteNew')
24+
end,
25+
desc = 'create new note',
26+
},
27+
{
2028
'<leader>ng',
21-
'NoteGit',
22-
'create new note for current git repo'
23-
),
24-
utils.vim_cmd('<leader>nt', 'NoteToday', 'create new note for today'),
29+
function()
30+
vim.cmd('NoteGit')
31+
end,
32+
desc = 'create new note for current git repo',
33+
},
34+
{
35+
'<leader>nt',
36+
function()
37+
vim.cmd('NoteToday')
38+
end,
39+
desc = 'create new note for today',
40+
},
2541
{
2642
'<leader>np',
2743
function()

lua/dcai/keymaps/testthings.lua

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,55 @@ local testthings_keymap = {
8989
end,
9090
desc = 'alternate test file',
9191
},
92-
utils.vim_cmd('<leader>th', 'HurlRun', 'run hurl file'),
93-
utils.vim_cmd('<leader>ti', 'VimuxInspectRunner', 'inspect runner'),
94-
utils.vim_cmd('<leader>tp', 'VimuxPromptCommand', 'prompt command'),
95-
utils.vim_cmd('<leader>tq', 'VimuxCloseRunner', 'close runner'),
96-
utils.vim_cmd('<leader>ts', '!%:p', 'run current buffer in shell'),
97-
utils.vim_cmd('<leader>tx', 'call VimuxZoomRunner()', 'zoom in'),
98-
utils.vim_cmd('<leader>tz', 'call LastPath()', 'open last path in runner'),
92+
{
93+
'<leader>th',
94+
function()
95+
vim.cmd('HurlRun')
96+
end,
97+
desc = 'run hurl file',
98+
},
99+
{
100+
'<leader>ti',
101+
function()
102+
vim.cmd('VimuxInspectRunner')
103+
end,
104+
desc = 'inspect runner',
105+
},
106+
{
107+
'<leader>tp',
108+
function()
109+
vim.cmd('VimuxPromptCommand')
110+
end,
111+
desc = 'prompt command',
112+
},
113+
{
114+
'<leader>tq',
115+
function()
116+
vim.cmd('VimuxCloseRunner')
117+
end,
118+
desc = 'close runner',
119+
},
120+
{
121+
'<leader>ts',
122+
function()
123+
vim.cmd('!%:p')
124+
end,
125+
desc = 'run current buffer in shell',
126+
},
127+
{
128+
'<leader>tx',
129+
function()
130+
vim.cmd('call VimuxZoomRunner()')
131+
end,
132+
desc = 'zoom in',
133+
},
134+
{
135+
'<leader>tz',
136+
function()
137+
vim.cmd('call LastPath()')
138+
end,
139+
desc = 'open last path in runner',
140+
},
99141
}
100142

101143
return testthings_keymap

lua/dcai/keymaps/utils.lua

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ end
5757

5858
M.lazy_shell_cmd = lazy_shell_cmd
5959

60-
M.git_cmd = function(opts, desc)
61-
return lazy_shell_cmd('git', opts, desc)
62-
end
63-
6460
M.cmd_with_fidget = function(command, args, opts)
6561
return function()
6662
local plenary_loaded, Job = pcall(require, 'plenary.job')
@@ -126,19 +122,6 @@ M.live_grep = function()
126122
fzf.live_grep({ cwd = vim.g.git_root() })
127123
end
128124

129-
---@param cmd string vim command
130-
M.vim_cmd = function(key, cmd, desc, notify_after)
131-
return {
132-
key,
133-
function()
134-
vim.cmd(cmd)
135-
if notify_after then
136-
vim.notify(notify_after)
137-
end
138-
end,
139-
desc = desc or cmd,
140-
}
141-
end
142125
local function open_git_hosting_web()
143126
-- local mode = vim.fn.mode()
144127
-- if string.lower(mode) == 'v' then

lua/dcai/keymaps/yankthings.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,13 @@ end
6868

6969
local yank_keymap = {
7070
{ '<leader>y', group = 'yank things' },
71-
-- utils.vim_cmd('<leader>yp', 'let @*=expand("%:p")', 'yank file full path'),
72-
-- utils.vim_cmd('<leader>yf', 'let @*=expand("%")', 'yank file name'),
73-
-- utils.vim_cmd('<leader>ym', 'let @*=execute("messages")', 'yank messages'),
71+
{
72+
'<leader>yp',
73+
function()
74+
vim.cmd('let @*=expand("%:p")')
75+
end,
76+
desc = 'yank file full path',
77+
},
7478
{
7579
'<leader>yl',
7680
function()
@@ -98,6 +102,7 @@ local yank_keymap = {
98102
{
99103
'<leader>yf',
100104
function()
105+
-- vim.cmd('let @*=expand("%")')
101106
local filename = vim.fn.expand('%')
102107
put_content(filename)
103108
end,
@@ -106,6 +111,7 @@ local yank_keymap = {
106111
{
107112
'<leader>ym',
108113
function()
114+
-- vim.cmd('let @*=execute("messages")')
109115
local messages = vim.fn.execute('messages')
110116
put_content(vim.split(messages, '\n', { trimempty = true, plain = true }))
111117
end,

0 commit comments

Comments
 (0)