From 2c6c8163dbea85206c14c8acb072d213bda245c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Lam=C3=A9?= Date: Wed, 15 Jan 2025 14:41:33 +0100 Subject: [PATCH] ADD: sync tmux colors with nvim --- LICENSE | 21 ++++++++++++ README | 66 +++++++++++++++++++++++++++++++++++++ lua/tmux-sync.nvim/init.lua | 40 ++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 LICENSE create mode 100644 README create mode 100644 lua/tmux-sync.nvim/init.lua diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..42950bf --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Lomig + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README b/README new file mode 100644 index 0000000..e2be815 --- /dev/null +++ b/README @@ -0,0 +1,66 @@ +# tmux-sync.nvim + + **Synchronisation automatique des couleurs entre Neovim et Tmux** selon le mode d'édition. + + **Modes pris en charge :** +- **Normal** → Couleur synchronisée avec le mode Normal de Neovim. +- **Insert** → Couleur synchronisée avec le mode Insert. +- **Visual** → Couleur synchronisée avec le mode Visual. +- **Command** → Couleur synchronisée avec le mode Command. + +--- + +## **Fonctionnalités** + +- Synchronisation **en temps réel** de la couleur de la **status bar Tmux** avec Neovim. +- Intégration directe avec **`mini.statusline`**. +- Ultra léger et sans configuration obligatoire. + +--- + +## **Installation** + +### Avec **Lazy.nvim** + +```lua +{ + "L0m1g/tmux-sync.nvim", + dependencies = { + "echasnovski/mini.statusline", -- Nécessaire pour récupérer les couleurs + }, + config = function() + require("tmux-sync") + end, +} +``` + +### Avec **Packer.nvim** + +```lua +use({ + "L0m1g/tmux-sync.nvim", + requires = { "echasnovski/mini.statusline" }, + config = function() + require("tmux-sync") + end, +}) +``` + +## Configuration + +Aucune configuration n’est nécessaire, mais tu peux personnaliser les couleurs avec mini.statusline si besoin. + +## Fonctionnement + +Le plugin écoute les changements de mode dans Neovim et met à jour la couleur de la status bar de Tmux. + +Exemple de synchronisation : + • Mode Normal → Orange + • Mode Insert → Vert + • Mode Visual → Rouge + • Mode Command → Bleu + +## Licence + +Distribué sous Licence MIT + diff --git a/lua/tmux-sync.nvim/init.lua b/lua/tmux-sync.nvim/init.lua new file mode 100644 index 0000000..8c77da5 --- /dev/null +++ b/lua/tmux-sync.nvim/init.lua @@ -0,0 +1,40 @@ +local M = {} + +-- 🔎 Récupérer la couleur d'un groupe de highlight +local function get_hl_color(hl, attr) + local ok, hl_data = pcall(vim.api.nvim_get_hl, 0, { name = hl }) + if ok and hl_data[attr] then + return string.format("#%06x", hl_data[attr]) + else + return "#444444" -- Gris par défaut si rien trouvé + end +end + +-- 📡 Synchroniser les couleurs avec Tmux selon le mode +M.set_tmux_status = function(mode) + local mode_colors = { + n = get_hl_color("MiniStatuslineModeNormal", "bg"), + i = get_hl_color("MiniStatuslineModeInsert", "bg"), + v = get_hl_color("MiniStatuslineModeVisual", "bg"), + V = get_hl_color("MiniStatuslineModeVisual", "bg"), + [""] = get_hl_color("MiniStatuslineModeVisual", "bg"), + R = get_hl_color("MiniStatuslineModeReplace", "bg"), + c = get_hl_color("MiniStatuslineModeCommand", "bg"), + } + + local color = mode_colors[mode] or get_hl_color("MiniStatuslineModeNormal", "bg") + + -- 🛠️ Commande silencieuse pour changer la couleur de Tmux + vim.fn.system({ "tmux", "set-option", "status-bg", color }) +end + +-- 🔄 Détecte les changements de mode +vim.api.nvim_create_autocmd("ModeChanged", { + pattern = "*", + callback = function() + local mode = vim.fn.mode() + M.set_tmux_status(mode) + end, +}) + +return M