Skip to content

Commit

Permalink
feat(neovim): sync colorscheme across all nvim instances
Browse files Browse the repository at this point in the history
  • Loading branch information
olimorris committed Jan 6, 2025
1 parent 9c20a8d commit a80270a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
63 changes: 53 additions & 10 deletions .config/nvim/lua/config/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,59 @@ local conceal_ns = vim.api.nvim_create_namespace("ConcealClassAttribute")
---Use Legendary.nvim to create autocmds
---REF: https://github.com/mrjones2014/legendary.nvim/blob/master/doc/table_structures/AUTOCMDS.md
return {
{
-- Watch for changes in ~/.color_mode
name = "ChangeColorScheme",
{
"VimEnter",
function()
local uv = vim.uv
local handle = uv.new_fs_event()

local path = vim.fn.expand("~/.color_mode")

local flags = {
watch_entry = false, -- true = when dir, watch dir inode, not dir content
stat = false, -- true = don't use inotify/kqueue but periodic check, not implemented
recursive = false, -- true = watch dirs inside dirs
}

local function set_mode(mode)
vim.opt.background = mode or "dark"

if mode == "light" then
vim.cmd([[colorscheme onelight]])
else
vim.cmd([[colorscheme vaporwave]])
end

local utils = require("heirline.utils")
utils.on_colorscheme(require("onedarkpro.helpers").get_colors())
end

local function read_file(file)
local fd = assert(uv.fs_open(file, "r", 438))
local stat = assert(uv.fs_fstat(fd))
local data = assert(uv.fs_read(fd, stat.size, 0))
assert(uv.fs_close(fd))

return vim.trim(data)
end

local event_cb = function(err, filename, events)
if not err then
vim.schedule(function()
local data = read_file(path)
set_mode(data)
end)
end
end

set_mode(read_file(path))
uv.fs_event_start(handle, path, flags, event_cb)
end,
},
},
{
name = "ConcealAttributes",
{
Expand Down Expand Up @@ -58,16 +111,6 @@ return {
},
{
name = "Heirline",
{
"ColorScheme",
function()
local utils = require("heirline.utils")
utils.on_colorscheme(require("onedarkpro.helpers").get_colors())
end,
opts = {
pattern = { "*" },
},
},
{
"User",
function(args)
Expand Down
1 change: 0 additions & 1 deletion .config/nvim/lua/config/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ vb.tabstop = 4 -- Number of spaces in a tab
-- vb.wrapmargin = 1

-- Vim options
vo.background = "dark"
vo.cmdheight = 0 -- Hide the command bar
vo.clipboard = { "unnamedplus" } -- Use the system clipboard
vo.completeopt = { "menuone", "noselect" } -- Completion opions for code completion
Expand Down
1 change: 0 additions & 1 deletion commands/color_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
apps = [
"macos",
"starship",
"neovim",
"fish",
]

Expand Down

0 comments on commit a80270a

Please sign in to comment.