Skip to content

Commit 19d9a9e

Browse files
committed
fix(keymap.helpers): rewrite toggleterm subfunctions
1 parent 7595b43 commit 19d9a9e

File tree

1 file changed

+50
-42
lines changed

1 file changed

+50
-42
lines changed

lua/keymap/helpers.lua

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -108,65 +108,73 @@ _G._toggle_lazygit = function()
108108
end
109109
end
110110

111-
function _G._toggle_yazi()
112-
if toggleterm_cache.yazi then
113-
toggleterm_cache.lf:toggle()
114-
else
115-
if vim.fn.executable("yazi") then
116-
toggleterm_cache.yazi =
117-
require("toggleterm.terminal").Terminal:new({ cmd = "yazi", hidden = true, direction = "float" })
118-
toggleterm_cache.yazi:toggle()
119-
else
120-
not_found_notify("yazi")
111+
_G._toggle_yazi = function()
112+
if vim.fn.executable("yazi") == 1 then
113+
if not toggleterm_cache.yazi then
114+
toggleterm_cache.yazi = require("toggleterm.terminal").Terminal:new({
115+
cmd = "yazi",
116+
direction = "float",
117+
close_on_exit = true,
118+
hidden = true,
119+
})
121120
end
121+
toggleterm_cache.yazi:toggle()
122+
else
123+
not_found_notify("yazi")
122124
end
123125
end
124126

125-
function _G._toggle_btop()
126-
if toggleterm_cache.btop then
127+
_G._toggle_btop = function()
128+
if vim.fn.executable("btop") == 1 then
129+
if not toggleterm_cache.btop then
130+
toggleterm_cache.btop = require("toggleterm.terminal").Terminal:new({
131+
cmd = "btop",
132+
direction = "float",
133+
close_on_exit = true,
134+
hidden = true,
135+
})
136+
end
127137
toggleterm_cache.btop:toggle()
128138
else
129-
if vim.fn.executable("btop") then
130-
toggleterm_cache.btop =
131-
require("toggleterm.terminal").Terminal:new({ cmd = "btop", hidden = true, direction = "float" })
132-
toggleterm_cache.btop:toggle()
133-
else
134-
not_found_notify("btop")
135-
end
139+
not_found_notify("btop")
136140
end
137141
end
138142

139-
function _G._toggle_py()
140-
if toggleterm_cache.python then
141-
toggleterm_cache.python:toggle()
142-
else
143-
if vim.fn.executable("python3") then
144-
toggleterm_cache.python =
145-
require("toggleterm.terminal").Terminal:new({ cmd = "python3", hidden = true, direction = "float" })
146-
toggleterm_cache.python:toggle()
147-
elseif vim.fn.executable("python") then
148-
toggleterm_cache.python =
149-
require("toggleterm.terminal").Terminal:new({ cmd = "python", hidden = true, direction = "float" })
150-
toggleterm_cache.python:toggle()
151-
else
152-
not_found_notify("python")
143+
_G._toggle_python = function()
144+
if vim.fn.executable("python3") == 1 then
145+
if not toggleterm_cache.python then
146+
toggleterm_cache.python = require("toggleterm.terminal").Terminal:new({
147+
cmd = "python3",
148+
direction = "float",
149+
close_on_exit = true,
150+
hidden = true,
151+
})
152+
elseif vim.fn.executable("python") == 1 then
153+
toggleterm_cache.python = require("toggleterm.terminal").Terminal:new({
154+
cmd = "python",
155+
direction = "float",
156+
close_on_exit = true,
157+
hidden = true,
158+
})
153159
end
160+
toggleterm_cache:python()
161+
else
162+
not_found_notify("python3 or python")
154163
end
155164
end
156165

157-
function _G._toggle_nvsmi()
158-
if toggleterm_cache.nvsmi then
159-
toggleterm_cache.nvsmi:toggle()
160-
else
161-
if vim.fn.executable("nvidia-smi") then
166+
_G._toggle_nvsmi = function()
167+
if vim.fn.executable("nvidia-smi") == 1 then
168+
if not toggleterm_cache.nvsmi then
162169
toggleterm_cache.nvsmi = require("toggleterm.terminal").Terminal:new({
163170
cmd = "watch -n 1 nvidia-smi",
164-
hidden = true,
165171
direction = "float",
172+
close_on_exit = true,
173+
hidden = true,
166174
})
167-
toggleterm_cache.nvsmi:toggle()
168-
else
169-
not_found_notify("nvidia-smi")
170175
end
176+
toggleterm_cache.nvsmi()
177+
else
178+
not_found_notify("nvidia-smi")
171179
end
172180
end

0 commit comments

Comments
 (0)