Skip to content

Instantly share code, notes, and snippets.

@bjorntrondsen
Last active March 28, 2024 17:18
Show Gist options
  • Save bjorntrondsen/4ee91256fdc7fc625578137e669a4b63 to your computer and use it in GitHub Desktop.
Save bjorntrondsen/4ee91256fdc7fc625578137e669a4b63 to your computer and use it in GitHub Desktop.
Copilot lualine component

Works in Neovim 0.9.5 if you have copilot enabled by default and toggle it with :Copilot disable/enable. enabled disabled

Create a lualine component file {nvim-dir}/lua/lualine/components/copilot_status.lua

local M = require('lualine.component'):extend()
local highlight = require("lualine.highlight")

function M:init(options)
  options.padding = 2
  M.super.init(self, options)

  self.highlights = {
    enabled = highlight.create_component_highlight_group({ fg = "#50FA7B" }, "copilot_status_enabled", options),
    disabled = highlight.create_component_highlight_group({ fg = "#FA5050" }, "copilot_status_disabled", options),
  }
end

function M:update_status()
  local copilot_enabled = (vim.g.copilot_enabled or 1) == 1
  if copilot_enabled then
    return highlight.component_format_highlight(self.highlights.enabled) .. '󰚩' -- nerdfont dea9
  else
    return highlight.component_format_highlight(self.highlights.disabled) .. '󱚧' -- nerdfont dea7
  end

end

return M

Then add copilot_status to the desired lualine section

require('lualine').setup({
  sections = {
    lualine_x = {
      'copilot_status',
      'encoding',
      'fileformat',
      'filetype'
    },
  },
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment