feat: refactor
This commit is contained in:
45
configs/nvim/lua/utils/init.lua
Normal file
45
configs/nvim/lua/utils/init.lua
Normal file
@@ -0,0 +1,45 @@
|
||||
local M = {}
|
||||
local cmd = vim.cmd
|
||||
|
||||
function M.create_augroup(autocmds, name)
|
||||
cmd("augroup " .. name)
|
||||
cmd("autocmd!")
|
||||
for _, autocmd in ipairs(autocmds) do
|
||||
cmd("autocmd " .. table.concat(autocmd, " "))
|
||||
end
|
||||
cmd("augroup END")
|
||||
end
|
||||
|
||||
function M.ReloadConfig()
|
||||
for name, _ in pairs(package.loaded) do
|
||||
if name:match("^cnull") then
|
||||
package.loaded[name] = nil
|
||||
end
|
||||
end
|
||||
|
||||
dofile(vim.env.MYVIMRC)
|
||||
end
|
||||
|
||||
local function dump(o)
|
||||
if type(o) == "table" then
|
||||
local s = "{ "
|
||||
for k, v in pairs(o) do
|
||||
if type(k) ~= "number" then
|
||||
k = '"' .. k .. '"'
|
||||
end
|
||||
s = s .. "[" .. k .. "] = " .. dump(v) .. ","
|
||||
end
|
||||
return s .. "} "
|
||||
else
|
||||
return tostring(o)
|
||||
end
|
||||
end
|
||||
|
||||
M.dump = dump
|
||||
|
||||
function M.has_plugin(pluginName)
|
||||
local status = pcall(require, pluginName)
|
||||
return status
|
||||
end
|
||||
|
||||
return M
|
7
configs/nvim/lua/utils/install-packer.lua
Normal file
7
configs/nvim/lua/utils/install-packer.lua
Normal file
@@ -0,0 +1,7 @@
|
||||
local fn = vim.fn
|
||||
|
||||
local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim'
|
||||
|
||||
if fn.empty(fn.glob(install_path)) > 0 then
|
||||
fn.system({'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path})
|
||||
end
|
35
configs/nvim/lua/utils/theme-reloader.lua
Normal file
35
configs/nvim/lua/utils/theme-reloader.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
-- see if the file exists
|
||||
local function file_exists(file)
|
||||
local f = io.open(file, "rb")
|
||||
if f then f:close() end
|
||||
return f ~= nil
|
||||
end
|
||||
|
||||
-- get all lines from a file, returns an empty
|
||||
-- list/table if the file does not exist
|
||||
local function line_from(file)
|
||||
if not file_exists(file) then return {} end
|
||||
local f = io.open(file) -- 'r' is unnecessary because it's a default value.
|
||||
local line = f:read() -- '*l' is unnecessary because it's a default value.
|
||||
f:close()
|
||||
return line;
|
||||
end
|
||||
|
||||
local filePath = os.getenv("HOME").."/.cache/dark-mode";
|
||||
local function updateTheme()
|
||||
local line = line_from(filePath);
|
||||
if line then
|
||||
local dark = string.find(line, "dark");
|
||||
if dark then
|
||||
vim.cmd("colorscheme nightfox")
|
||||
else
|
||||
vim.cmd("colorscheme dayfox")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
updateTheme()
|
||||
local w = vim.loop.new_fs_event()
|
||||
w:start(filePath, {}, vim.schedule_wrap(updateTheme))
|
Reference in New Issue
Block a user