ADD: sync tmux colors with nvim
This commit is contained in:
commit
2c6c8163db
3 changed files with 127 additions and 0 deletions
21
LICENSE
Normal file
21
LICENSE
Normal file
|
|
@ -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.
|
||||
66
README
Normal file
66
README
Normal file
|
|
@ -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
|
||||
|
||||
40
lua/tmux-sync.nvim/init.lua
Normal file
40
lua/tmux-sync.nvim/init.lua
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue