feat: refactor

This commit is contained in:
2022-04-23 03:41:04 +02:00
parent 42db054021
commit 4bf6a46a85
35 changed files with 2167 additions and 500 deletions

View 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

View 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

View 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))