From c1dd778e473a72389b39fbd0aaea1ce0dd7792cd Mon Sep 17 00:00:00 2001 From: rootiest Date: Thu, 18 Jul 2024 14:14:08 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Checks=20for=20.settings=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Checks for missing files and creates them - More efficient handling of those settings --- lua/config/autocmds.lua | 7 +++++++ lua/config/check-files.lua | 43 ++++++++++++++++++++++++++++++++++++++ lua/config/options.lua | 22 +++++++------------ lua/config/ui.lua | 10 +++++---- lua/config/user.lua | 2 +- lua/plugins/coding.lua | 40 +++++++++++++---------------------- lua/plugins/util.lua | 12 +++++------ 7 files changed, 84 insertions(+), 52 deletions(-) create mode 100644 lua/config/check-files.lua diff --git a/lua/config/autocmds.lua b/lua/config/autocmds.lua index 1ae490a..1b85f20 100644 --- a/lua/config/autocmds.lua +++ b/lua/config/autocmds.lua @@ -9,6 +9,13 @@ vim.api.nvim_create_user_command("Q", function() vim.cmd.qall() end, { force = true }) +-- Restore Colorscheme +vim.api.nvim_create_user_command("RestoreColorscheme", function() + vim.cmd.colorscheme( + STORED_THEME or KITTY_THEME or "catppuccin-frappe" or "tokyonight" + ) +end, { force = true }) + -- ------------------------------ Auto-Commands -------------------------------- -- Autosave Colorscheme -- When the colorscheme changes, store the name in .colorscheme diff --git a/lua/config/check-files.lua b/lua/config/check-files.lua new file mode 100644 index 0000000..555b7ea --- /dev/null +++ b/lua/config/check-files.lua @@ -0,0 +1,43 @@ +-- ----------------------------------------------------------------------------- +-- ------------------------------ CHECK-FILES ---------------------------------- +-- ----------------------------------------------------------------------------- +----- Verify settings files exist and create them if they don't exist ----- +-- ----------------------------------------------------------------------------- + +-- Check if the .leader file exists +if vim.fn.filereadable(vim.fn.stdpath("config") .. "/.leader") ~= 1 then + vim.fn.writefile({ vim.g.mapleader }, vim.fn.stdpath("config") .. "/.leader") +end + +-- Check if the .colorscheme file exists +if vim.fn.filereadable(vim.fn.stdpath("config") .. "/.colorscheme") ~= 1 then + -- Use the kitty theme + if os.getenv("KITTY_THEME") then + KITTY_THEME = os.getenv("KITTY_THEME") + vim.fn.writefile( + { KITTY_THEME }, + vim.fn.stdpath("config") .. "/.colorscheme" + ) + else + -- Use the default colorscheme + vim.fn.writefile( + { vim.g.colors_name }, + vim.fn.stdpath("config") .. "/.colorscheme" + ) + end +end + +-- Check if the .aitool file exists +if vim.fn.filereadable(vim.fn.stdpath("config") .. "/.aitool") ~= 1 then + vim.fn.writefile({ "codeium" }, vim.fn.stdpath("config") .. "/.aitool") +end + +-- Check if the .useimage file exists +if vim.fn.filereadable(vim.fn.stdpath("config") .. "/.useimage") ~= 1 then + vim.fn.writefile({ "true" }, vim.fn.stdpath("config") .. "/.useimage") +end + +-- Check if the .wakatime file exists +if vim.fn.filereadable(vim.fn.stdpath("config") .. "/.wakatime") ~= 1 then + vim.fn.writefile({ "true" }, vim.fn.stdpath("config") .. "/.wakatime") +end diff --git a/lua/config/options.lua b/lua/config/options.lua index 4ccc70e..c8e2aa3 100644 --- a/lua/config/options.lua +++ b/lua/config/options.lua @@ -5,22 +5,14 @@ -- Set Default Leader Key vim.g.mapleader = " " --- Restore Leader Key -if vim.fn.filereadable(vim.fn.stdpath("config") .. "/.leader") == 1 then - -- Load Stored Leader Key - vim.g.mapleader = vim.fn.readfile(vim.fn.stdpath("config") .. "/.leader")[1] -end +-- Correct missing settings files +require("config.check-files") --- Restore Colorscheme to variable -if vim.fn.filereadable(vim.fn.stdpath("config") .. "/.colorscheme") == 1 then - -- Load the stored colorscheme - STORED_THEME = vim.fn.readfile(vim.fn.stdpath("config") .. "/.colorscheme")[1] -else - -- Get the kitty theme - if os.getenv("KITTY_THEME") then - KITTY_THEME = os.getenv("KITTY_THEME") - end -end +-- Load Stored Leader Key +vim.g.mapleader = vim.fn.readfile(vim.fn.stdpath("config") .. "/.leader")[1] + +-- Load the stored colorscheme +STORED_THEME = vim.fn.readfile(vim.fn.stdpath("config") .. "/.colorscheme")[1] -- ----------------------------------- LSP -------------------------------------- vim.g.loaded_perl_provider = 0 diff --git a/lua/config/ui.lua b/lua/config/ui.lua index c39ad3a..a70bdb0 100644 --- a/lua/config/ui.lua +++ b/lua/config/ui.lua @@ -17,13 +17,15 @@ return { update_interval = 2000, set_dark_mode = function() vim.o.background = "dark" - local kitty_theme = os.getenv("KITTY_THEME") - vim.cmd.colorscheme(kitty_theme or "catppuccin-frappe") + vim.cmd.colorscheme( + STORED_THEME or KITTY_THEME or "catppuccin-frappe" or "tokyonight" + ) end, set_light_mode = function() vim.o.background = "light" - local kitty_theme = os.getenv("KITTY_THEME") - vim.cmd.colorscheme(kitty_theme or "catppuccin-latte") + vim.cmd.colorscheme( + STORED_THEME or KITTY_THEME or "catppuccin-frappe" or "tokyonight" + ) end, }, cond = function() -- Not Using SSH diff --git a/lua/config/user.lua b/lua/config/user.lua index f8671a4..34317fb 100644 --- a/lua/config/user.lua +++ b/lua/config/user.lua @@ -1,7 +1,7 @@ -- ----------------------------------------------------------------------------- -- ---------------------------------- USER ------------------------------------- -- ----------------------------------------------------------------------------- - +-- -- ---------------------------------- STYLE ------------------------------------ ----------------------------- Apply the colorscheme ---------------------------- -------- 1. Restore last colorscheme if it exists -------- diff --git a/lua/plugins/coding.lua b/lua/plugins/coding.lua index ad9fe0f..1e2690d 100644 --- a/lua/plugins/coding.lua +++ b/lua/plugins/coding.lua @@ -6,39 +6,33 @@ return { { import = "lazyvim.plugins.extras.coding.codeium", cond = function() - if vim.fn.filereadable(vim.fn.stdpath("config") .. "/.aitool") == 1 then - if - vim.fn.readfile(vim.fn.stdpath("config") .. "/.aitool")[1] - == "codeium" - then - return true - end + if + vim.fn.readfile(vim.fn.stdpath("config") .. "/.aitool")[1] + == "codeium" + then + return true end end, }, { import = "lazyvim.plugins.extras.coding.copilot", cond = function() - if vim.fn.filereadable(vim.fn.stdpath("config") .. "/.aitool") == 1 then - if - vim.fn.readfile(vim.fn.stdpath("config") .. "/.aitool")[1] - == "copilot" - then - return true - end + if + vim.fn.readfile(vim.fn.stdpath("config") .. "/.aitool")[1] + == "copilot" + then + return true end end, }, { import = "lazyvim.plugins.extras.coding.tabnine", cond = function() - if vim.fn.filereadable(vim.fn.stdpath("config") .. "/.aitool") == 1 then - if - vim.fn.readfile(vim.fn.stdpath("config") .. "/.aitool")[1] - == "tabnine" - then - return true - end + if + vim.fn.readfile(vim.fn.stdpath("config") .. "/.aitool")[1] + == "tabnine" + then + return true end end, }, @@ -107,10 +101,6 @@ return { }, }, }, - -- { - -- "vim-scripts/AnsiEsc.vim", - -- event = "VeryLazy", - -- }, { "shellRaining/hlchunk.nvim", event = "BufEnter", diff --git a/lua/plugins/util.lua b/lua/plugins/util.lua index 70eb5c0..c770005 100644 --- a/lua/plugins/util.lua +++ b/lua/plugins/util.lua @@ -14,13 +14,11 @@ return { { "wakatime/vim-wakatime", cond = function() - if vim.fn.filereadable(vim.fn.stdpath("config") .. "/.wakatime") == 1 then - if - vim.fn.readfile(vim.fn.stdpath("config") .. "/.wakatime")[1] - == "true" - then - return true - end + if + vim.fn.readfile(vim.fn.stdpath("config") .. "/.wakatime")[1] + == "true" + then + return true end end, },