From 9dd074cca2c8dc588254c5560b15e5b937850901 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Fri, 15 Jul 2022 20:08:07 +0100 Subject: [PATCH 1/8] fix(compiler): Match 'Windows_NT' uname On Windows 11, the uname returned is 'Windows_NT' and therefore, this commit includes 'Windows_NT' within the check so that the compiler works properly on Windows operating systems. --- lua/catppuccin/lib/compiler.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lua/catppuccin/lib/compiler.lua b/lua/catppuccin/lib/compiler.lua index c49665a..e0fb9db 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 sysname = vim.loop.os_uname().sysname + local function inspect(t) local list = {} for k, v in pairs(t) do @@ -68,11 +70,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) + string.format( + "mkdir %s %s", + (sysname == "Windows" or sysname == "Windows_NT") and "" or "-p", + config.compile.path + ) ) local file = io.open( config.compile.path - .. (vim.loop.os_uname().sysname == "Windows" and "\\" or "/") + .. ((sysname == "Windows" or sysname == "Windows_NT") and "\\" or "/") .. vim.g.catppuccin_flavour .. config.compile.suffix .. ".lua", @@ -85,7 +91,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 "/") + .. ((sysname == "Windows" or sysname == "Windows_NT") and "\\" or "/") .. vim.g.catppuccin_flavour .. config.compile.suffix .. ".lua" From cefc77ac7c00143d4b03e8db3a8c0feb29a23b99 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Sat, 16 Jul 2022 02:17:05 +0100 Subject: [PATCH 2/8] fix(compiler): Enable default support for Windows Currently, the default path for compiling goes to '/catppuccin', unfortunately this assumes that all users are on *nix based systems which they are not. This commit ensures that the path is correctly formatted if the user is on Windows by performing a global substitution --- lua/catppuccin/lib/compiler.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/catppuccin/lib/compiler.lua b/lua/catppuccin/lib/compiler.lua index e0fb9db..ac7f148 100644 --- a/lua/catppuccin/lib/compiler.lua +++ b/lua/catppuccin/lib/compiler.lua @@ -29,6 +29,10 @@ end vim.g.colors_name = "catppuccin"]], } local config = require("catppuccin.config").options + if sysname == "Windows" or sysname == "Windows_NT" 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)) From 0307daeb045340a6e89cc38395061ccea1601db1 Mon Sep 17 00:00:00 2001 From: nullchilly Date: Sat, 16 Jul 2022 12:14:47 +0700 Subject: [PATCH 3/8] chore(readme): Fix compile section --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f888b3d..6e43ddd 100644 --- a/README.md +++ b/README.md @@ -331,7 +331,7 @@ By default catppuccin writes the compiled results into the system's cache direct - It's recommended to add `:CatppuccinCompile` to post-install/update hooks. For example: -#### Packer.nvim +**Packer.nvim** ```lua use { @@ -341,7 +341,7 @@ use { } ``` -#### Vim-plug +**Vim-plug** ```lua Plug 'catppuccin/nvim', {'as': 'catppuccin', 'do': 'CatppuccinCompile'} @@ -349,7 +349,7 @@ Plug 'catppuccin/nvim', {'as': 'catppuccin', 'do': 'CatppuccinCompile'} - To auto-compile everytime you update your config: -#### Packer.nvim +**Packer.nvim** Create an autocmd `User PackerCompileDone` to update it every time packer is compiled: @@ -362,7 +362,7 @@ vim.api.nvim_create_autocmd("User", { }) ``` -#### Vim-plug +**Vim-plug** Auto compile on save if catppuccin config is in `init.vim` From e412bf67e7bacda906249e3a43a2f702646f0d19 Mon Sep 17 00:00:00 2001 From: nullchilly Date: Sat, 16 Jul 2022 12:17:34 +0700 Subject: [PATCH 4/8] chore(readme): Merge plugin manager section --- README.md | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 6e43ddd..ffa8c48 100644 --- a/README.md +++ b/README.md @@ -329,31 +329,18 @@ 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: **Packer.nvim** ```lua +- It's recommended to add `:CatppuccinCompile` to post-install/update hooks. For example: 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 vim.api.nvim_create_autocmd("User", { pattern = "PackerCompileDone", callback = function() @@ -364,9 +351,10 @@ vim.api.nvim_create_autocmd("User", { **Vim-plug** -Auto compile on save if catppuccin config is in `init.vim` - -```lua +```bash +# Create an autocmd `User PackerCompileDone` to update it every time packer is compiled: +Plug 'catppuccin/nvim', {'as': 'catppuccin', 'do': 'CatppuccinCompile'} +# Auto compile on save if catppuccin config is in `init.vim` autocmd BufWritePost init.vim :CatppuccinCompile ``` From 462639f611786593ffda2ed15f48b5dac0458c26 Mon Sep 17 00:00:00 2001 From: nullchilly Date: Sat, 16 Jul 2022 12:21:57 +0700 Subject: [PATCH 5/8] chore(readme): Fix vimscript syntax highlighting --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ffa8c48..425ca1a 100644 --- a/README.md +++ b/README.md @@ -329,18 +329,19 @@ By default catppuccin writes the compiled results into the system's cache direct :CatppuccinClean # Delete compiled file ``` +- To auto-compile everytime you update your config: **Packer.nvim** ```lua -- It's recommended to add `:CatppuccinCompile` to post-install/update hooks. For example: +-- It's recommended to add `:CatppuccinCompile` to post-install/update hooks use { "catppuccin/nvim", as = "catppuccin", run = "CatppuccinCompile", } -- To auto-compile everytime you update your config: +# Create an autocmd `User PackerCompileDone` to update it every time packer is compiled: vim.api.nvim_create_autocmd("User", { pattern = "PackerCompileDone", callback = function() @@ -351,8 +352,8 @@ vim.api.nvim_create_autocmd("User", { **Vim-plug** -```bash -# Create an autocmd `User PackerCompileDone` to update it every time packer is compiled: +```vim +# 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 From 052c0d0a75efb161d0aa5c8fa623a516475c8c19 Mon Sep 17 00:00:00 2001 From: nullchilly Date: Sat, 16 Jul 2022 12:23:00 +0700 Subject: [PATCH 6/8] chore(readme): Revert vim syntax highlighting because its terrible --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 425ca1a..9229161 100644 --- a/README.md +++ b/README.md @@ -341,7 +341,7 @@ use { run = "CatppuccinCompile", } -# Create an autocmd `User PackerCompileDone` to update it every time packer is compiled: +-- Create an autocmd `User PackerCompileDone` to update it every time packer is compiled: vim.api.nvim_create_autocmd("User", { pattern = "PackerCompileDone", callback = function() @@ -352,7 +352,7 @@ vim.api.nvim_create_autocmd("User", { **Vim-plug** -```vim +```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` From f34f19fae6e3fb05c3e6b6517d22792631af1984 Mon Sep 17 00:00:00 2001 From: nullchilly Date: Sat, 16 Jul 2022 12:30:46 +0700 Subject: [PATCH 7/8] fix(compiler): Missing is_windows --- README.md | 2 +- lua/catppuccin/init.lua | 2 +- lua/catppuccin/lib/compiler.lua | 18 ++++++------------ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9229161..f7216f6 100644 --- a/README.md +++ b/README.md @@ -355,7 +355,7 @@ vim.api.nvim_create_autocmd("User", { ```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` +# 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..4f63e92 100644 --- a/lua/catppuccin/init.lua +++ b/lua/catppuccin/init.lua @@ -40,7 +40,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" diff --git a/lua/catppuccin/lib/compiler.lua b/lua/catppuccin/lib/compiler.lua index ac7f148..748dd5a 100644 --- a/lua/catppuccin/lib/compiler.lua +++ b/lua/catppuccin/lib/compiler.lua @@ -2,7 +2,7 @@ local M = {} -- Credit: https://github.com/EdenEast/nightfox.nvim local fmt = string.format -local sysname = vim.loop.os_uname().sysname +local is_windows = vim.startswith(vim.loop.os_uname().sysname, "Windows") local function inspect(t) local list = {} @@ -20,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 @@ -29,7 +29,7 @@ end vim.g.colors_name = "catppuccin"]], } local config = require("catppuccin.config").options - if sysname == "Windows" or sysname == "Windows_NT" then + if is_windows then config.compile.path = config.compile.path:gsub("/", "\\") end @@ -73,16 +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", - (sysname == "Windows" or sysname == "Windows_NT") 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 - .. ((sysname == "Windows" or sysname == "Windows_NT") and "\\" or "/") + .. (is_windows and "\\" or "/") .. vim.g.catppuccin_flavour .. config.compile.suffix .. ".lua", @@ -95,7 +89,7 @@ end function M.clean() local config = require("catppuccin.config").options local compiled_path = config.compile.path - .. ((sysname == "Windows" or sysname == "Windows_NT") and "\\" or "/") + .. (is_windows and "\\" or "/") .. vim.g.catppuccin_flavour .. config.compile.suffix .. ".lua" From 5daefaf006be38b5b28e4a709e984fd1ab51cbd7 Mon Sep 17 00:00:00 2001 From: nullchilly Date: Sat, 16 Jul 2022 12:46:20 +0700 Subject: [PATCH 8/8] feat(compiler): Only set compile commands when enabled = true --- lua/catppuccin/init.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lua/catppuccin/init.lua b/lua/catppuccin/init.lua index 4f63e92..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") @@ -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