nvim: Dynamically source colorscheme from file
Neovim will source the `colorscheme.lua` file in its state directory on startup, as well as whenever the file contents are changed. This allows any colorscheme definition to be put into the file and vim will apply it as soon as the file contents change.
This commit is contained in:
parent
c13db186cc
commit
25d37d17b3
1 changed files with 23 additions and 5 deletions
|
@ -7,10 +7,28 @@ vim.api.nvim_set_var('gruvbox_italic', 1)
|
||||||
vim.api.nvim_set_var('one_allow_italics', 1)
|
vim.api.nvim_set_var('one_allow_italics', 1)
|
||||||
vim.api.nvim_set_var('pencil_terminal_italics', 1)
|
vim.api.nvim_set_var('pencil_terminal_italics', 1)
|
||||||
|
|
||||||
function B16theme(theme)
|
local colorsfile = vim.fn.stdpath('state') .. '/colorscheme.lua'
|
||||||
local base16scheme = b.themes[theme]
|
local function source_colors()
|
||||||
b(base16scheme, true)
|
if vim.fn.filereadable(colorsfile) == 1 then
|
||||||
|
vim.cmd("source " .. colorsfile)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set the default colorscheme
|
-- source colors automatically from colorscheme file on change
|
||||||
B16theme('eighties')
|
local w = vim.loop.new_fs_event()
|
||||||
|
local function on_change(err, fname, status)
|
||||||
|
source_colors()
|
||||||
|
w:stop()
|
||||||
|
Watch_file(fname)
|
||||||
|
end
|
||||||
|
function Watch_file(fname)
|
||||||
|
local fullpath = vim.api.nvim_call_function('fnamemodify', { fname, ':p' })
|
||||||
|
w:start(fullpath, {}, vim.schedule_wrap(function(...)
|
||||||
|
on_change(...)
|
||||||
|
end))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- set on startup
|
||||||
|
source_colors()
|
||||||
|
-- and watch continuously
|
||||||
|
Watch_file(colorsfile)
|
||||||
|
|
Loading…
Reference in a new issue