FIX: desactivate if not in tmux
This commit is contained in:
parent
e9afa10b3a
commit
74f4a0a4aa
1 changed files with 24 additions and 8 deletions
|
|
@ -1,5 +1,15 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
-- 🔍 Vérifie si tmux est installé
|
||||||
|
local function is_tmux_installed()
|
||||||
|
return vim.fn.executable("tmux") == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 🔍 Vérifie si on est dans une session tmux
|
||||||
|
local function is_in_tmux()
|
||||||
|
return os.getenv("TMUX") ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
-- 🔎 Récupérer la couleur d'un groupe de highlight
|
-- 🔎 Récupérer la couleur d'un groupe de highlight
|
||||||
local function get_hl_color(hl, attr)
|
local function get_hl_color(hl, attr)
|
||||||
local ok, hl_data = pcall(vim.api.nvim_get_hl, 0, { name = hl })
|
local ok, hl_data = pcall(vim.api.nvim_get_hl, 0, { name = hl })
|
||||||
|
|
@ -12,6 +22,10 @@ end
|
||||||
|
|
||||||
-- 📡 Synchroniser les couleurs avec Tmux selon le mode
|
-- 📡 Synchroniser les couleurs avec Tmux selon le mode
|
||||||
M.set_tmux_status = function(mode)
|
M.set_tmux_status = function(mode)
|
||||||
|
if not (is_tmux_installed() and is_in_tmux()) then
|
||||||
|
return -- 🔒 Ne fait rien si tmux n'est pas dispo
|
||||||
|
end
|
||||||
|
|
||||||
local mode_colors = {
|
local mode_colors = {
|
||||||
n = get_hl_color("MiniStatuslineModeNormal", "bg"),
|
n = get_hl_color("MiniStatuslineModeNormal", "bg"),
|
||||||
i = get_hl_color("MiniStatuslineModeInsert", "bg"),
|
i = get_hl_color("MiniStatuslineModeInsert", "bg"),
|
||||||
|
|
@ -25,10 +39,11 @@ M.set_tmux_status = function(mode)
|
||||||
local color = mode_colors[mode] or get_hl_color("MiniStatuslineModeNormal", "bg")
|
local color = mode_colors[mode] or get_hl_color("MiniStatuslineModeNormal", "bg")
|
||||||
|
|
||||||
-- 🛠️ Commande silencieuse pour changer la couleur de Tmux
|
-- 🛠️ Commande silencieuse pour changer la couleur de Tmux
|
||||||
vim.fn.system({ "tmux", "set-option", "status-bg", color })
|
vim.fn.system({ "tmux", "set-option", "-g", "status-bg", color })
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 🔄 Détecte les changements de mode
|
-- 🔄 Détecte les changements de mode
|
||||||
|
if is_tmux_installed() and is_in_tmux() then
|
||||||
vim.api.nvim_create_autocmd("ModeChanged", {
|
vim.api.nvim_create_autocmd("ModeChanged", {
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
callback = function()
|
callback = function()
|
||||||
|
|
@ -36,5 +51,6 @@ vim.api.nvim_create_autocmd("ModeChanged", {
|
||||||
M.set_tmux_status(mode)
|
M.set_tmux_status(mode)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue