mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-24 09:48:59 +02:00
feat(lazygit): lazygit now automatically uses colors from your Neovim colorscheme
Disable by setting `vim.g.lazygit_theme = false` in your `options.lua`
This commit is contained in:
parent
c00e3aa6b1
commit
7d0dbc6ded
5 changed files with 101 additions and 3 deletions
17
NEWS.md
17
NEWS.md
|
@ -2,6 +2,23 @@
|
||||||
|
|
||||||
## 10.x
|
## 10.x
|
||||||
|
|
||||||
|
- **lazygit** now automatically uses the colors of your current colorscheme.
|
||||||
|
This is enabled by default. To disable, add the below to your `options.lua`:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
vim.g.lazygit_theme = false
|
||||||
|
```
|
||||||
|
|
||||||
|
- Added support for `basedpyright` to the **python** extra.
|
||||||
|
Enable in your `options.lua` with:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
vim.g.lazyvim_python_lsp = "basedpyright"
|
||||||
|
```
|
||||||
|
|
||||||
|
Be aware that `basedpyright` is still in development and
|
||||||
|
may not work exactly the same as `pyright`.
|
||||||
|
|
||||||
- User extras under `lua/plugins/extras` can now also be managed
|
- User extras under `lua/plugins/extras` can now also be managed
|
||||||
with **LazyExtras**
|
with **LazyExtras**
|
||||||
|
|
||||||
|
|
|
@ -125,12 +125,12 @@ map("n", "<leader>uT", function() if vim.b.ts_highlight then vim.treesitter.stop
|
||||||
map("n", "<leader>ub", function() LazyVim.toggle("background", false, {"light", "dark"}) end, { desc = "Toggle Background" })
|
map("n", "<leader>ub", function() LazyVim.toggle("background", false, {"light", "dark"}) end, { desc = "Toggle Background" })
|
||||||
|
|
||||||
-- lazygit
|
-- lazygit
|
||||||
map("n", "<leader>gg", function() LazyVim.terminal({ "lazygit" }, { cwd = LazyVim.root.git(), esc_esc = false, ctrl_hjkl = false }) end, { desc = "Lazygit (root dir)" })
|
map("n", "<leader>gg", function() LazyVim.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (root dir)" })
|
||||||
map("n", "<leader>gG", function() LazyVim.terminal({ "lazygit" }, {esc_esc = false, ctrl_hjkl = false}) end, { desc = "Lazygit (cwd)" })
|
map("n", "<leader>gG", function() LazyVim.lazygit() end, { desc = "Lazygit (cwd)" })
|
||||||
|
|
||||||
map("n", "<leader>gf", function()
|
map("n", "<leader>gf", function()
|
||||||
local git_path = vim.api.nvim_buf_get_name(0)
|
local git_path = vim.api.nvim_buf_get_name(0)
|
||||||
LazyVim.terminal({ "lazygit", "-f", vim.trim(git_path) }, { esc_esc = false, ctrl_hjkl = false })
|
LazyVim.lazygit({args = { "-f", vim.trim(git_path) }})
|
||||||
end, { desc = "Lazygit current file history" })
|
end, { desc = "Lazygit current file history" })
|
||||||
|
|
||||||
-- quit
|
-- quit
|
||||||
|
|
|
@ -12,6 +12,11 @@ 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,
|
||||||
|
-- based on the active colorscheme.
|
||||||
|
-- Set to false to disable.
|
||||||
|
vim.g.lazygit_theme = 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:
|
||||||
-- * pwsh
|
-- * pwsh
|
||||||
|
|
|
@ -6,6 +6,7 @@ local LazyUtil = require("lazy.core.util")
|
||||||
---@field root lazyvim.util.root
|
---@field root lazyvim.util.root
|
||||||
---@field telescope lazyvim.util.telescope
|
---@field telescope lazyvim.util.telescope
|
||||||
---@field terminal lazyvim.util.terminal
|
---@field terminal lazyvim.util.terminal
|
||||||
|
---@field lazygit lazyvim.util.lazygit
|
||||||
---@field toggle lazyvim.util.toggle
|
---@field toggle lazyvim.util.toggle
|
||||||
---@field format lazyvim.util.format
|
---@field format lazyvim.util.format
|
||||||
---@field plugin lazyvim.util.plugin
|
---@field plugin lazyvim.util.plugin
|
||||||
|
|
75
lua/lazyvim/util/lazygit.lua
Normal file
75
lua/lazyvim/util/lazygit.lua
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
---@class lazyvim.util.lazygit
|
||||||
|
---@field config_dir? string
|
||||||
|
---@overload fun(cmd: string|string[], opts: LazyTermOpts): LazyFloat
|
||||||
|
local M = setmetatable({}, {
|
||||||
|
__call = function(m, ...)
|
||||||
|
return m.open(...)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
M.theme_path = vim.fn.stdpath("cache") .. "/lazygit-theme.yml"
|
||||||
|
|
||||||
|
-- re-create theme file on startup
|
||||||
|
M.dirty = true
|
||||||
|
|
||||||
|
-- re-create theme file on ColorScheme change
|
||||||
|
vim.api.nvim_create_autocmd("ColorScheme", {
|
||||||
|
callback = function()
|
||||||
|
M.dirty = true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Opens lazygit
|
||||||
|
---@param opts? LazyTermOpts | {args?: string[]}
|
||||||
|
function M.open(opts)
|
||||||
|
opts = vim.tbl_deep_extend("force", {}, opts or {}, {
|
||||||
|
esc_esc = false,
|
||||||
|
ctrl_hjkl = false,
|
||||||
|
})
|
||||||
|
local cmd = { "lazygit" }
|
||||||
|
if vim.g.lazygit_theme then
|
||||||
|
if M.dirty then
|
||||||
|
M.update_theme()
|
||||||
|
end
|
||||||
|
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
|
||||||
|
end
|
||||||
|
vim.list_extend(cmd, opts.args or {})
|
||||||
|
return LazyVim.terminal(cmd, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.set_ansi_color(idx, color)
|
||||||
|
io.write(("\27]4;%d;%s\7"):format(idx, color))
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.update_theme()
|
||||||
|
-- LazyGit uses color 241 a lot, so also set it to a nice color
|
||||||
|
M.set_ansi_color(241, LazyVim.ui.color("Special") or "blue")
|
||||||
|
|
||||||
|
local theme = {
|
||||||
|
activeBorderColor = { LazyVim.ui.color("MatchParen") or "orange", "bold" },
|
||||||
|
cherryPickedCommitBgColor = { "cyan" },
|
||||||
|
cherryPickedCommitFgColor = { "blue" },
|
||||||
|
defaultFgColor = { "default" },
|
||||||
|
inactiveBorderColor = { LazyVim.ui.color("FloatBorder") or "blue" },
|
||||||
|
optionsTextColor = { "blue" },
|
||||||
|
searchingActiveBorderColor = { LazyVim.ui.color("MatchParen") or "orange", "bold" },
|
||||||
|
selectedLineBgColor = { LazyVim.ui.color("CursorLine", true) }, -- set to `default` to have no background colour
|
||||||
|
unstagedChangesColor = { "red" },
|
||||||
|
}
|
||||||
|
---@type string[]
|
||||||
|
local lines = {}
|
||||||
|
lines[#lines + 1] = "gui:"
|
||||||
|
lines[#lines + 1] = " theme:"
|
||||||
|
for k, v in pairs(theme) do
|
||||||
|
lines[#lines + 1] = (" %s:"):format(k)
|
||||||
|
for _, c in ipairs(v) do
|
||||||
|
lines[#lines + 1] = (" - %q"):format(c)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local config = table.concat(lines, "\n")
|
||||||
|
require("lazy.util").write_file(M.theme_path, config)
|
||||||
|
M.dirty = false
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
Loading…
Add table
Add a link
Reference in a new issue