Skip to content

Commit b5acf38

Browse files
authored
feat: added terminal_cmd to config, if set, exec in terminal and not a buffer (#534)
1 parent bd76b9b commit b5acf38

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ For overriding the default mappings when using `lazy.nvim` [check out our wiki p
239239
bin = "kubediff" -- or any other binary
240240
},
241241
kubectl_cmd = { cmd = "kubectl", env = {}, args = {}, persist_context_change = false },
242+
terminal_cmd = nil, -- Exec will launch in a terminal if set, i.e. "ghostty -e"
242243
namespace = "All",
243244
namespace_fallback = {}, -- If you have limited access you can list all the namespaces here
244245
hints = true,

lua/kubectl/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local M = {}
33
---@class KubectlOptions
44
---@field log_level number
55
---@field auto_refresh { enabled: boolean, interval: number }
6+
---@field terminal_cmd string?
67
---@field namespace string
78
---@field namespace_fallback string[]
89
---@field headers boolean
@@ -29,6 +30,7 @@ local defaults = {
2930
-- NOTE: Some executions using the io.open and vim.fn.terminal will still have default shell environments,
3031
-- in that case, the environments below will not override the defaults and should not be in your .zshrc/.bashrc files
3132
kubectl_cmd = { cmd = "kubectl", env = {}, args = {}, persist_context_change = false },
33+
terminal_cmd = nil, -- Exec will launch in a terminal if set, i.e. "ghostty -e"
3234
namespace = "All",
3335
namespace_fallback = {},
3436
headers = true,

lua/kubectl/views/containers/init.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ function M.View(pod, ns)
2222
end
2323

2424
function M.exec(pod, ns)
25-
buffers.floating_buffer("k8s_container_exec", "ssh " .. M.selection)
26-
commands.execute_terminal("kubectl", { "exec", "-it", pod, "-n", ns, "-c ", M.selection, "--", "/bin/sh" })
25+
local args = { "exec", "-it", pod, "-n", ns, "-c ", M.selection, "--", "/bin/sh" }
26+
local cmd = "kubectl"
27+
28+
if config.options.terminal_cmd then
29+
local command = commands.configure_command(cmd, {}, args)
30+
vim.fn.jobstart(config.options.terminal_cmd .. " " .. table.concat(command.args, " "))
31+
else
32+
buffers.floating_buffer("k8s_container_exec", "ssh " .. M.selection)
33+
commands.execute_terminal(cmd, args)
34+
end
2735
end
2836

2937
function M.debug(pod, ns)

0 commit comments

Comments
 (0)