Skip to content

Commit

Permalink
function to handle buffer rename better
Browse files Browse the repository at this point in the history
  • Loading branch information
h4ckm1n-dev committed Jun 9, 2024
1 parent f27d3b2 commit 11da7d9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lua/kube-utils-nvim/kubectl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,20 @@ Kubectl.select_crd = function()
return
end

-- Step 5: Open the CRD details in a new buffer and save it
-- Function to safely rename buffer
local function safe_set_buf_name(buf, name)
local ok, err = pcall(vim.api.nvim_buf_set_name, buf, name)
if not ok then
print("Failed to rename buffer: " .. err)
end
end

-- Step 5: Open the CRD details in a new buffer with a vertical split and save it
vim.api.nvim_command("vsplit")
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_set_current_buf(buf)
vim.api.nvim_buf_set_lines(buf, 0, -1, false, vim.split(crd_details, "\n"))
vim.api.nvim_buf_set_name(buf, selected_crd .. ".yaml")
safe_set_buf_name(buf, selected_crd .. ".yaml")
vim.bo[buf].filetype = "yaml"
end)
end)
Expand Down

0 comments on commit 11da7d9

Please sign in to comment.