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

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

@ -10,5 +10,7 @@ function! s:ApplyFlavour(args) abort
endfunction endfunction
command! -nargs=1 -complete=custom,s:FlavourCompletion Catppuccin call s:ApplyFlavour([<f-args>]) 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 let g:loaded_catppuccin = 1

Loading…
Cancel
Save