Ramilito / kubectl.nvim

Apache License 2.0
168 stars 5 forks source link

customize ftplugin #339

Closed mosheavni closed 1 day ago

mosheavni commented 1 day ago

I want to extend the k8s_fallback ftplugin to add some custom usages. for example, if the resource is Applications.argoproj.io, I can click on the app and it will open a browser window of the argo app selected.

I created my own ftplugin/k8s_fallback.lua that looks like this:

local commands = require 'kubectl.actions.commands'
local tables = require 'kubectl.utils.tables'

vim.schedule(function()
  vim.api.nvim_buf_set_keymap(0, 'n', '<Plug>(kubectl.select)', '', {
    noremap = true,
    silent = true,
    desc = 'Go to application',
    callback = function()
      local _, buf_name = pcall(vim.api.nvim_buf_get_var, 0, 'buf_name')
      local lower_buf_name = string.lower(buf_name)

      if lower_buf_name == 'applications.argoproj.io' then
        local name = tables.getCurrentSelection(1)
        if not name then
          return
        end
        local ingress_host = commands.shell_command(
          'kubectl',
          { 'get', 'ingress', '-n', 'argocd', '-l', 'app.kubernetes.io/component=server', '-o', 'jsonpath={.items[].spec.rules[].host}' }
        )

        local final_host = string.format('https://%s/applications/argocd/%s', ingress_host, name)
        vim.notify('Opening ' .. final_host)
        vim.ui.open(final_host)
      end
    end,
  })
end)

but something weird is happening, the lines are wrapped when they are supposed to be not wrapped (i.e :set nowrap): https://github.com/Ramilito/kubectl.nvim/blob/372d2c6559801eb7a7f5dee892eb8f7af8250e15/lua/kubectl/actions/layout.lua#L9

What can cause my config's wrap be set AFTER the plugin's wrap when I define my own ftplugin?

Ramilito commented 1 day ago

That shouldn't happen imo, sure the ftplugin runs after bufenter so it can change it but you haven't added such code, I also tried with your ftplugin and options from your dotfiles but not getting any wrapping.

Also that's a great way to customize this plugin 👏

mosheavni commented 1 day ago

can you create a Wiki and give me write permissions? we can start collecting cool stuff there

Ramilito commented 1 day ago

Done! Let me know if it's not working!

mosheavni commented 1 day ago

Done! Let me know if it's not working!

yay thanks!

mosheavni commented 1 day ago

also the wrapping issue doesn't happen anymore :)

Ramilito commented 1 day ago

Took a look at the wiki page, really nice post!