diff --git a/README.md b/README.md index f888b3d..f7216f6 100644 --- a/README.md +++ b/README.md @@ -329,31 +329,19 @@ By default catppuccin writes the compiled results into the system's cache direct :CatppuccinClean # Delete compiled file ``` -- It's recommended to add `:CatppuccinCompile` to post-install/update hooks. For example: +- To auto-compile everytime you update your config: -#### Packer.nvim +**Packer.nvim** ```lua +-- It's recommended to add `:CatppuccinCompile` to post-install/update hooks use { "catppuccin/nvim", as = "catppuccin", run = "CatppuccinCompile", } -``` - -#### Vim-plug - -```lua -Plug 'catppuccin/nvim', {'as': 'catppuccin', 'do': 'CatppuccinCompile'} -``` - -- To auto-compile everytime you update your config: - -#### Packer.nvim -Create an autocmd `User PackerCompileDone` to update it every time packer is compiled: - -```lua +-- Create an autocmd `User PackerCompileDone` to update it every time packer is compiled: vim.api.nvim_create_autocmd("User", { pattern = "PackerCompileDone", callback = function() @@ -362,11 +350,12 @@ vim.api.nvim_create_autocmd("User", { }) ``` -#### Vim-plug - -Auto compile on save if catppuccin config is in `init.vim` +**Vim-plug** -```lua +```bash +# It's recommended to add `:CatppuccinCompile` to post-install/update hooks +Plug 'catppuccin/nvim', {'as': 'catppuccin', 'do': 'CatppuccinCompile'} +# Auto compile on save if catppuccin config is in init.vim autocmd BufWritePost init.vim :CatppuccinCompile ``` diff --git a/lua/catppuccin/init.lua b/lua/catppuccin/init.lua index 6b2e58b..896fa86 100644 --- a/lua/catppuccin/init.lua +++ b/lua/catppuccin/init.lua @@ -20,14 +20,6 @@ end, { end, }) -command("CatppuccinCompile", function() - require("catppuccin.lib.compiler").compile() -end, {}) - -command("CatppuccinClean", function() - require("catppuccin.lib.compiler").clean() -end, {}) - function M.load() local catppuccin = require("catppuccin") @@ -40,7 +32,7 @@ function M.load() if config.compile.enabled == true then local compiled_path = config.compile.path - .. (vim.loop.os_uname().sysname == "Windows" and "\\" or "/") + .. (vim.startswith(vim.loop.os_uname().sysname, "Windows") and "\\" or "/") .. vim.g.catppuccin_flavour .. config.compile.suffix .. ".lua" @@ -65,6 +57,17 @@ end function M.setup(custom_opts) require("catppuccin.config").set_options(custom_opts) + + -- Only set compile commands when enabled = true + if custom_opts.compile.enabled == true then + command("CatppuccinCompile", function() + require("catppuccin.lib.compiler").compile() + end, {}) + + command("CatppuccinClean", function() + require("catppuccin.lib.compiler").clean() + end, {}) + end end return M diff --git a/lua/catppuccin/lib/compiler.lua b/lua/catppuccin/lib/compiler.lua index c49665a..748dd5a 100644 --- a/lua/catppuccin/lib/compiler.lua +++ b/lua/catppuccin/lib/compiler.lua @@ -2,6 +2,8 @@ local M = {} -- Credit: https://github.com/EdenEast/nightfox.nvim local fmt = string.format +local is_windows = vim.startswith(vim.loop.os_uname().sysname, "Windows") + local function inspect(t) local list = {} for k, v in pairs(t) do @@ -18,7 +20,7 @@ function M.compile() local lines = { [[ -- This file is autogenerated by CATPPUCCIN. --- Do not make changes directly to this file. +-- DO NOT make changes directly to this file. vim.cmd("hi clear") if vim.fn.exists("syntax_on") then @@ -27,6 +29,10 @@ end vim.g.colors_name = "catppuccin"]], } local config = require("catppuccin.config").options + if is_windows then + config.compile.path = config.compile.path:gsub("/", "\\") + end + for property, value in pairs(theme.properties) do if type(value) == "string" then table.insert(lines, fmt('vim.o.%s = "%s"', property, value)) @@ -67,12 +73,10 @@ vim.g.colors_name = "catppuccin"]], table.insert(lines, fmt('vim.g.%s = "%s"', k, v)) 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", is_windows and "" or "-p", config.compile.path)) local file = io.open( config.compile.path - .. (vim.loop.os_uname().sysname == "Windows" and "\\" or "/") + .. (is_windows and "\\" or "/") .. vim.g.catppuccin_flavour .. config.compile.suffix .. ".lua", @@ -85,7 +89,7 @@ end function M.clean() local config = require("catppuccin.config").options local compiled_path = config.compile.path - .. (vim.loop.os_uname().sysname == "Windows" and "\\" or "/") + .. (is_windows and "\\" or "/") .. vim.g.catppuccin_flavour .. config.compile.suffix .. ".lua"