feat(compile): Add compile commands

dev
nullchilly 2 years ago
parent 2a235b712b
commit 03535cfc7c

@ -20,8 +20,10 @@ local function load()
if f ~= nil then
io.close(f)
vim.cmd("luafile " .. compiled_path)
vim.api.nvim_exec_autocmds("User", { pattern = "CatppuccinLoaded" })
return
end
end
else
-- colorscheme gets evaluated from mapper.lua
local theme = require("catppuccin.core.mapper").apply()
local utils = require("catppuccin.utils.util")
@ -30,7 +32,6 @@ local function load()
if catppuccin.after_loading ~= nil then
catppuccin.after_loading()
end
end
vim.api.nvim_exec_autocmds("User", { pattern = "CatppuccinLoaded" })
end

@ -112,10 +112,11 @@ local function inspect(t)
return fmt([[{ %s }]], table.concat(list, ", "))
end
function util.compile(theme)
function util.compile()
if vim.fn.has "nvim-0.7" == 0 then
print "Compiling requires neovim 0.7"
end
local theme = require("catppuccin.core.mapper").apply()
local lines = { [[
-- This file is autogenerated by CATPPUCCIN.
-- Do not make changes directly to this file.
@ -162,10 +163,15 @@ vim.g.colors_name = "catppuccin"]] }
end
end
os.execute(string.format("mkdir %s %s", vim.loop.os_uname().sysname == 'Windows' and "" or "-p", config.compile.path))
print(string.format("mkdir %s %s", vim.loop.os_uname().sysname == 'Windows' and "" or "-p", config.compile.path))
local file = io.open(config.compile.path .. (vim.loop.os_uname().sysname == 'Windows' and "\\" or "/") .. vim.g.catppuccin_flavour .. config.compile.suffix .. ".lua", "w")
file:write(table.concat(lines, "\n"))
file:close()
end
function util.clean()
local config = require("catppuccin.config").options
local compiled_path = config.compile.path .. (vim.loop.os_uname().sysname == 'Windows' and "\\" or "/") .. vim.g.catppuccin_flavour .. config.compile.suffix .. ".lua"
os.remove(compiled_path)
end
return util

@ -10,5 +10,7 @@ function! s:ApplyFlavour(args) abort
endfunction
command! -nargs=1 -complete=custom,s:FlavourCompletion Catppuccin call s:ApplyFlavour([<f-args>])
command! CatppuccinCompile lua require("catppuccin.utils.util").compile()
command! CatppuccinClean lua require("catppuccin.utils.util").clean()
let g:loaded_catppuccin = 1

Loading…
Cancel
Save