feat(lazygit): configure lazygit nvim-remote as editor and enable nerdfont icons

can be disabled with `vim.g.lazygit_config = false`
This commit is contained in:
Folke Lemaitre 2024-03-26 19:53:38 +01:00
parent 55c2527dfe
commit 426cd3ed91
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
3 changed files with 35 additions and 12 deletions

10
NEWS.md
View file

@ -2,11 +2,19 @@
## 10.x ## 10.x
- The **lazygit** integration now configures:
- the theme based on the colorscheme
- nerd font icons (v3)
- editor preset is set to `nvim-remote` for better interop with Neovim
- The option `vim.g.lazygit_theme` was renamed to `vim.g.lazygit_config`
- **lazygit** now automatically uses the colors of your current colorscheme. - **lazygit** now automatically uses the colors of your current colorscheme.
This is enabled by default. To disable, add the below to your `options.lua`: This is enabled by default. To disable, add the below to your `options.lua`:
```lua ```lua
vim.g.lazygit_theme = false vim.g.lazygit_config = false
``` ```
- Added support for `basedpyright` to the **python** extra. - Added support for `basedpyright` to the **python** extra.

View file

@ -12,10 +12,12 @@ vim.g.autoformat = true
-- * a function with signature `function(buf) -> string|string[]` -- * a function with signature `function(buf) -> string|string[]`
vim.g.root_spec = { "lsp", { ".git", "lua" }, "cwd" } vim.g.root_spec = { "lsp", { ".git", "lua" }, "cwd" }
-- LazyVim automatically configures the lazygit theme, -- LazyVim automatically configures lazygit:
-- based on the active colorscheme. -- * theme, based on the active colorscheme.
-- * editorPreset to nvim-remote
-- * enables nerd font icons
-- Set to false to disable. -- Set to false to disable.
vim.g.lazygit_theme = true vim.g.lazygit_config = true
-- Optionally setup the terminal to use -- Optionally setup the terminal to use
-- This sets `vim.o.shell` and does some additional configuration for: -- This sets `vim.o.shell` and does some additional configuration for:

View file

@ -9,7 +9,7 @@ local M = setmetatable({}, {
M.theme_path = vim.fn.stdpath("cache") .. "/lazygit-theme.yml" M.theme_path = vim.fn.stdpath("cache") .. "/lazygit-theme.yml"
-- re-create theme file on startup -- re-create config file on startup
M.dirty = true M.dirty = true
-- re-create theme file on ColorScheme change -- re-create theme file on ColorScheme change
@ -22,19 +22,26 @@ vim.api.nvim_create_autocmd("ColorScheme", {
-- Opens lazygit -- Opens lazygit
---@param opts? LazyTermOpts | {args?: string[]} ---@param opts? LazyTermOpts | {args?: string[]}
function M.open(opts) function M.open(opts)
if vim.g.lazygit_theme ~= nil then
LazyVim.deprecate("vim.g.lazygit_theme", "vim.g.lazygit_config")
end
opts = vim.tbl_deep_extend("force", {}, { opts = vim.tbl_deep_extend("force", {}, {
esc_esc = false, esc_esc = false,
ctrl_hjkl = false, ctrl_hjkl = false,
}, opts or {}) }, opts or {})
local cmd = { "lazygit" } local cmd = { "lazygit" }
if vim.g.lazygit_theme then vim.list_extend(cmd, opts.args or {})
if vim.g.lazygit_config then
if M.dirty then if M.dirty then
M.update_theme() M.update_config()
end end
M.config_dir = M.config_dir or vim.trim(vim.fn.system("lazygit -cd")) M.config_dir = M.config_dir or vim.trim(vim.fn.system("lazygit -cd"))
vim.env.LG_CONFIG_FILE = M.config_dir .. "/config.yml" .. "," .. M.theme_path vim.env.LG_CONFIG_FILE = M.config_dir .. "/config.yml" .. "," .. M.theme_path
end end
vim.list_extend(cmd, opts.args or {})
return LazyVim.terminal(cmd, opts) return LazyVim.terminal(cmd, opts)
end end
@ -42,7 +49,7 @@ function M.set_ansi_color(idx, color)
io.write(("\27]4;%d;%s\7"):format(idx, color)) io.write(("\27]4;%d;%s\7"):format(idx, color))
end end
function M.update_theme() function M.update_config()
-- LazyGit uses color 241 a lot, so also set it to a nice color -- LazyGit uses color 241 a lot, so also set it to a nice color
-- pcall, since some terminals don't like this -- pcall, since some terminals don't like this
pcall(M.set_ansi_color, 241, LazyVim.ui.color("Special") or "blue") pcall(M.set_ansi_color, 241, LazyVim.ui.color("Special") or "blue")
@ -58,17 +65,23 @@ function M.update_theme()
selectedLineBgColor = { LazyVim.ui.color("CursorLine", true) }, -- set to `default` to have no background colour selectedLineBgColor = { LazyVim.ui.color("CursorLine", true) }, -- set to `default` to have no background colour
unstagedChangesColor = { "red" }, unstagedChangesColor = { "red" },
} }
local config = [[
os:
editPreset: "nvim-remote"
gui:
nerdFontsVersion: 3
theme:
]]
---@type string[] ---@type string[]
local lines = {} local lines = {}
lines[#lines + 1] = "gui:"
lines[#lines + 1] = " theme:"
for k, v in pairs(theme) do for k, v in pairs(theme) do
lines[#lines + 1] = (" %s:"):format(k) lines[#lines + 1] = (" %s:"):format(k)
for _, c in ipairs(v) do for _, c in ipairs(v) do
lines[#lines + 1] = (" - %q"):format(c) lines[#lines + 1] = (" - %q"):format(c)
end end
end end
local config = table.concat(lines, "\n") config = config .. table.concat(lines, "\n")
require("lazy.util").write_file(M.theme_path, config) require("lazy.util").write_file(M.theme_path, config)
M.dirty = false M.dirty = false
end end