Skip to content

Commit 065103b

Browse files
committed
refactor(keymaps/utils): replace lazy_shell_cmd with lazy_cmd_with_window and update usages
Replaces the `lazy_shell_cmd` function with `lazy_cmd_with_window` for improved naming and consistency. Updates all keymap modules to use the new function. Also refactors `cmd_with_fidget` to `lazy_cmd_with_fidget` and updates its implementation and usages accordingly. Removes redundant error handling for required modules.
1 parent f31d2b4 commit 065103b

File tree

4 files changed

+10
-26
lines changed

4 files changed

+10
-26
lines changed

lua/dcai/keymaps/git.lua

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

33
local function lazy_git_cmd(opts, desc)
4-
return utils.lazy_shell_cmd('git', opts, desc)
4+
return utils.lazy_cmd_with_window('git', opts, desc)
55
end
66

77
local git_keymap = {
@@ -35,7 +35,7 @@ local git_keymap = {
3535
},
3636
{
3737
'<leader>gG',
38-
utils.cmd_with_fidget('git', { 'auto-commit-and-push' }),
38+
utils.lazy_cmd_with_fidget('git', { 'auto-commit-and-push' }),
3939
desc = 'git ai commit and push',
4040
},
4141
{ '<leader>gd', '<cmd>Git diff<cr>', desc = 'fugitive diff' },

lua/dcai/keymaps/notes.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ local notes_keymap = {
4646
vim.g.logger.warn('must be markdown file')
4747
return
4848
end
49-
utils.lazy_shell_cmd(
49+
utils.lazy_cmd_with_window(
5050
'doku-publish.py',
5151
-- args should be evaluated when the function is called
5252
{ disable_popup = false, args = { vim.fn.expand('%:p') } }

lua/dcai/keymaps/openthings.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ local openthings_keymap = {
2121
'<leader>od',
2222
function()
2323
-- has to be wrapped because dir must be lazy evaluated
24-
utils.lazy_shell_cmd(
24+
utils.lazy_cmd_with_window(
2525
'open',
2626
{ disable_popup = true, args = { vim.fn.expand('%:p:h') } },
2727
'open folder'
@@ -33,7 +33,7 @@ local openthings_keymap = {
3333
'<leader>of',
3434
function()
3535
-- has to be wrapped because filename must be lazy evaluated
36-
utils.lazy_shell_cmd(
36+
utils.lazy_cmd_with_window(
3737
zed,
3838
{ disable_popup = true, args = { vim.fn.expand('%:p') } },
3939
'open file in zed'

lua/dcai/keymaps/utils.lua

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local M = {}
22

3-
local function lazy_shell_cmd(command, opts, desc)
3+
local function lazy_cmd_with_window(command, opts, desc)
44
return function()
55
local plenary_loaded, Job = pcall(require, 'plenary.job')
66
if not plenary_loaded then
@@ -54,28 +54,12 @@ local function lazy_shell_cmd(command, opts, desc)
5454
:start()
5555
end
5656
end
57+
M.lazy_cmd_with_window = lazy_cmd_with_window
5758

58-
M.lazy_shell_cmd = lazy_shell_cmd
59-
60-
M.cmd_with_fidget = function(command, args, opts)
59+
M.lazy_cmd_with_fidget = function(command, args, opts)
6160
return function()
62-
local plenary_loaded, Job = pcall(require, 'plenary.job')
63-
if not plenary_loaded then
64-
vim.notify(
65-
'plenary.nvim is required for cmd_with_fidget',
66-
vim.log.levels.ERROR
67-
)
68-
return
69-
end
70-
71-
local fidget_loaded, fidget_progress = pcall(require, 'fidget.progress')
72-
if not fidget_loaded then
73-
vim.notify(
74-
'fidget.nvim is required for cmd_with_fidget',
75-
vim.log.levels.ERROR
76-
)
77-
return
78-
end
61+
local Job = require('plenary.job')
62+
local fidget_progress = require('fidget.progress')
7963

8064
opts = opts or {}
8165
local cwd = opts.cwd or vim.fn.getcwd()

0 commit comments

Comments
 (0)