diff --git a/.config/nvim/lua/config/autocmds.lua b/.config/nvim/lua/config/autocmds.lua index f365cda..18f81c9 100644 --- a/.config/nvim/lua/config/autocmds.lua +++ b/.config/nvim/lua/config/autocmds.lua @@ -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", { @@ -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) diff --git a/.config/nvim/lua/config/options.lua b/.config/nvim/lua/config/options.lua index 051e738..18a9510 100644 --- a/.config/nvim/lua/config/options.lua +++ b/.config/nvim/lua/config/options.lua @@ -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 diff --git a/commands/color_mode.py b/commands/color_mode.py index 205d2fd..0f332bd 100644 --- a/commands/color_mode.py +++ b/commands/color_mode.py @@ -18,7 +18,6 @@ apps = [ "macos", "starship", - "neovim", "fish", ]