From 65917d380a5a97351f3d0e062a77f264436d831c Mon Sep 17 00:00:00 2001 From: rootiest Date: Fri, 4 Oct 2024 10:11:16 -0400 Subject: [PATCH] feat: Add user customization and refactor for readability - Add user customization via automatically detected user.lua file - Reorganize config options into separate files - Reorganize plugin loaders into separate files --- .gitignore | 3 + config/colors.lua | 66 +++++++++++ config/font.lua | 39 +++++++ configs.lua => config/keys.lua | 165 ++++------------------------ platform.lua => config/platform.lua | 40 ++++--- config/window.lua | 50 +++++++++ opts.lua | 34 ++++++ plugins/resurrect.lua | 24 ++++ plugs.lua | 17 +++ wezterm.lua | 15 ++- 10 files changed, 286 insertions(+), 167 deletions(-) create mode 100644 config/colors.lua create mode 100644 config/font.lua rename configs.lua => config/keys.lua (69%) rename platform.lua => config/platform.lua (60%) create mode 100644 config/window.lua create mode 100644 opts.lua create mode 100644 plugs.lua diff --git a/.gitignore b/.gitignore index 9dea3eb..6d7874c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ dev/ +user/ +dev.lua +user.lua diff --git a/config/colors.lua b/config/colors.lua new file mode 100644 index 0000000..0beba62 --- /dev/null +++ b/config/colors.lua @@ -0,0 +1,66 @@ +-- ╭─────────────────────────────────────────────────────────╮ +-- │ COLORS │ +-- ╰─────────────────────────────────────────────────────────╯ +-- Load WezTerm module +local wezterm = WEZTERM + +local types = require("types") + +local cur_hour = wezterm.time.now():format("%H") + +local hour_angle = require("funcs").get_hour_angle(cur_hour) + +local opts = { + -- Color Scheme + color_scheme = "Catppuccin Mocha", + -- Tab Bar Colors + colors = { + -- Compose Cursor + compose_cursor = "#a5e3a0", + -- Visual Bell + visual_bell = "#E78284", + }, + -- Command Palette Colors + command_palette_bg_color = "#232634", -- Command Palette Background + command_palette_fg_color = "#C6D0F5", -- Command Palette Foreground + -- Titlebar and Frame Colors + window_frame = { + active_titlebar_bg = "#232634", + inactive_titlebar_bg = "#303446", + inactive_titlebar_fg = "#484D69", + active_titlebar_fg = "#C6D0F5", + inactive_titlebar_border_bottom = "#3b3052", + active_titlebar_border_bottom = "#3b3052", + button_fg = "#C6D0F5", + button_bg = "#3b3052", + button_hover_fg = "#C6D0F5", + button_hover_bg = "#2b2042", + font = wezterm.font(types.win_font), + -- Tab Font Size + font_size = 10, + }, + -- Inactive Pane Filter + inactive_pane_hsb = { + saturation = 1.0, + brightness = 0.5, + }, + window_background_gradient = { + orientation = { + Linear = { + angle = hour_angle, + }, + }, + colors = { + -- "#303446", + "#24273a", + "#1e1e2e", + }, + interpolation = "CatmullRom", + blend = "Oklab", + noise = 128, + segment_size = 7, + segment_smoothness = 1.0, + }, +} + +return opts diff --git a/config/font.lua b/config/font.lua new file mode 100644 index 0000000..5bf0b37 --- /dev/null +++ b/config/font.lua @@ -0,0 +1,39 @@ +-- ╭─────────────────────────────────────────────────────────╮ +-- │ FONT │ +-- ╰─────────────────────────────────────────────────────────╯ + +-- Load WezTerm module +local wezterm = WEZTERM + +local types = require("types") + +local opts = { + -- Terminal Font Size + font_size = 12.0, + -- Terminal Font + font = wezterm.font_with_fallback(types.rootiest_font), + -- Cell Sizing + cell_width = 1.0, + line_height = 1.0, + -- ANSI Colors + bold_brightens_ansi_colors = "BrightAndBold", + -- FreeType Load Flags + freetype_load_flags = "DEFAULT", + -- FreeType Load Target + freetype_load_target = "Normal", + -- Default Cursor Shape + default_cursor_style = "BlinkingBar", + -- Set the initial size + initial_cols = 180, + initial_rows = 38, + + tab_max_width = 60, + tab_bar_at_bottom = false, + + unicode_version = 14, + + -- Resize by cell + use_resize_increments = true, +} + +return opts diff --git a/configs.lua b/config/keys.lua similarity index 69% rename from configs.lua rename to config/keys.lua index 42efc0c..cdf037d 100644 --- a/configs.lua +++ b/config/keys.lua @@ -1,136 +1,13 @@ -- ╭─────────────────────────────────────────────────────────╮ --- │ CONFIG │ +-- │ KEYMAPS │ -- ╰─────────────────────────────────────────────────────────╯ + local wezterm = WEZTERM local act = wezterm.action --- local gpus = wezterm.gui.enumerate_gpus() -local types = require("types") -local cur_hour = wezterm.time.now():format("%H") - -local hour_angle = require("funcs").get_hour_angle(cur_hour) +local resurrect = wezterm.plugin.require("https://github.com/MLFlexer/resurrect.wezterm") local opts = { - -- Color Scheme - color_scheme = "Catppuccin Mocha", - -- Tab Bar Colors - colors = { - -- Compose Cursor - compose_cursor = "#a5e3a0", - -- Visual Bell - visual_bell = "#E78284", - }, - -- Command Palette Colors - command_palette_bg_color = "#232634", -- Command Palette Background - command_palette_fg_color = "#C6D0F5", -- Command Palette Foreground - -- Titlebar and Frame Colors - window_frame = { - active_titlebar_bg = "#232634", - inactive_titlebar_bg = "#303446", - inactive_titlebar_fg = "#484D69", - active_titlebar_fg = "#C6D0F5", - inactive_titlebar_border_bottom = "#3b3052", - active_titlebar_border_bottom = "#3b3052", - button_fg = "#C6D0F5", - button_bg = "#3b3052", - button_hover_fg = "#C6D0F5", - button_hover_bg = "#2b2042", - font = wezterm.font(types.win_font), - -- Tab Font Size - font_size = 10, - }, - -- Inactive Pane Filter - inactive_pane_hsb = { - saturation = 1.0, - brightness = 0.5, - }, - window_background_gradient = { - orientation = { - Linear = { - angle = hour_angle, - }, - }, - colors = { - -- "#303446", - "#24273a", - "#1e1e2e", - }, - interpolation = "CatmullRom", - blend = "Oklab", - noise = 128, - segment_size = 7, - segment_smoothness = 1.0, - }, - -- Terminal Font Size - font_size = 12.0, - -- Terminal Font - font = wezterm.font_with_fallback(types.rootiest_font), - -- Cell Sizing - cell_width = 1.0, - line_height = 1.0, - -- ANSI Colors - bold_brightens_ansi_colors = "BrightAndBold", - -- FreeType Load Flags - freetype_load_flags = "DEFAULT", - -- FreeType Load Target - freetype_load_target = "Normal", - -- Default Cursor Shape - default_cursor_style = "BlinkingBar", - -- Set the initial size - initial_cols = 180, - initial_rows = 38, - - tab_max_width = 60, - tab_bar_at_bottom = false, - - unicode_version = 14, - - -- Resize by cell - use_resize_increments = true, - - -- Use Retro tab bar - use_fancy_tab_bar = false, - - -- Set the window padding - window_padding = { - left = "0%", - right = "0%", - top = "0%", - bottom = "0%", - }, - - -- Set the animation framerate - animation_fps = 120, - - -- Window Decorations - window_decorations = "TITLE | RESIZE", - - -- Visual Bell - visual_bell = { - fade_in_duration_ms = 75, - fade_out_duration_ms = 75, - target = "CursorColor", - }, - - -- Audible Bell - audible_bell = "SystemBeep", - - -- Terminal Variable - term = "wezterm", - - --Honor kitty protocol inputs - enable_kitty_keyboard = true, - - -- Rendering - front_end = "WebGpu", - -- webgpu_power_preference = "HighPerformance", - -- webgpu_power_preference = "LowPower", - -- webgpu_preferred_adapter = gpus[1], - -- front_end = "OpenGL", - - -- Scrollback Lines - scrollback_lines = 20000, - -- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Leader key ━━━━━━━━━━━━━━━━━━━━━━━━━━ leader = { key = " ", mods = "CTRL", timeout_milliseconds = 1500 }, -- ━━━━━━━━━━━━━━━━━━━━━━━━━ Global Key Mappings ━━━━━━━━━━━━━━━━━━━━━ @@ -243,13 +120,25 @@ local opts = { end), }), }, + { -- Save [w]orkspace State + key = "w", + mods = "ALT", + action = wezterm.action_callback(function() + resurrect.save_state(resurrect.workspace_state.get_workspace_state()) + end), + }, + { -- Save [W]indow State + key = "W", + mods = "ALT", + action = resurrect.window_state.save_window_action(), + }, { -- [S]ave Session key = "s", mods = "ALT", action = act.Multiple({ wezterm.action_callback(function(_, _) - RESURRECT.save_state(RESURRECT.workspace_state.get_workspace_state()) - RESURRECT.window_state.save_window_action() + resurrect.save_state(resurrect.workspace_state.get_workspace_state()) + resurrect.window_state.save_window_action() end), }), }, @@ -257,24 +146,24 @@ local opts = { key = "r", mods = "ALT", action = wezterm.action_callback(function(win, pane) - RESURRECT.fuzzy_load(win, pane, function(id) + resurrect.fuzzy_load(win, pane, function(id) local type = string.match(id, "^([^/]+)") -- match before '/' id = string.match(id, "([^/]+)$") -- match after '/' id = string.match(id, "(.+)%..+$") -- remove file extension local state if type == "workspace" then - state = RESURRECT.load_state(id, "workspace") - RESURRECT.workspace_state.restore_workspace(state, { + state = resurrect.load_state(id, "workspace") + resurrect.workspace_state.restore_workspace(state, { relative = true, restore_text = true, - on_pane_restore = RESURRECT.tab_state.default_on_pane_restore, + on_pane_restore = resurrect.tab_state.default_on_pane_restore, }) elseif type == "window" then - state = RESURRECT.load_state(id, "window") - RESURRECT.window_state.restore_window(pane:window(), state, { + state = resurrect.load_state(id, "window") + resurrect.window_state.restore_window(pane:window(), state, { relative = true, restore_text = true, - on_pane_restore = RESURRECT.tab_state.default_on_pane_restore, + on_pane_restore = resurrect.tab_state.default_on_pane_restore, -- uncomment this line to use active tab when restoring -- tab = win:active_tab(), }) @@ -347,10 +236,4 @@ local opts = { }, } --- merge the table in os_opts.lua into opts -local os_opts = require("platform") -for k, v in pairs(os_opts) do - opts[k] = v -end - return opts diff --git a/platform.lua b/config/platform.lua similarity index 60% rename from platform.lua rename to config/platform.lua index b596b3e..98b48a5 100644 --- a/platform.lua +++ b/config/platform.lua @@ -9,26 +9,30 @@ local wezterm = WEZTERM local opts = {} -- -- Get the OS string --- local os_string = wezterm.target_triple:lower() --- local myos = "" +local os_string = wezterm.target_triple:lower() +local myos = "" -- -- -- Determine the OS --- if os_string:find("windows") then --- myos = "win" --- else --- if os_string:find("darwin") then --- myos = "mac" --- else --- myos = "linux" --- end --- end --- --- -- Set OS-specific options --- if myos == "win" then --- opts.default_prog = { "pwsh.exe" } --- opts.window_background_opacity = 0 --- opts.win32_system_backdrop = "Mica" --- end +if os_string:find("windows") then + myos = "win" +else + if os_string:find("darwin") then + myos = "mac" + else + myos = "linux" + end +end + +-- Set OS-specific options +if myos == "win" then + opts.default_prog = { "pwsh.exe" } +elseif myos == "mac" then + opts.default_prog = { "zsh" } +else + opts.default_prog = { "fish" } +end + +MYOS = myos -- Return the opts table return opts diff --git a/config/window.lua b/config/window.lua new file mode 100644 index 0000000..603ffca --- /dev/null +++ b/config/window.lua @@ -0,0 +1,50 @@ +-- ╭─────────────────────────────────────────────────────────╮ +-- │ WINDOW │ +-- ╰─────────────────────────────────────────────────────────╯ + +local opts = { + -- Use Retro tab bar + use_fancy_tab_bar = false, + + -- Set the window padding + window_padding = { + left = "0%", + right = "0%", + top = "0%", + bottom = "0%", + }, + + -- Set the animation framerate + animation_fps = 120, + + -- Window Decorations + window_decorations = "TITLE | RESIZE", + + -- Visual Bell + visual_bell = { + fade_in_duration_ms = 75, + fade_out_duration_ms = 75, + target = "CursorColor", + }, + + -- Audible Bell + audible_bell = "SystemBeep", + + -- Terminal Variable + term = "wezterm", + + --Honor kitty protocol inputs + enable_kitty_keyboard = true, + + -- Rendering + front_end = "WebGpu", + -- webgpu_power_preference = "HighPerformance", + -- webgpu_power_preference = "LowPower", + -- webgpu_preferred_adapter = gpus[1], + -- front_end = "OpenGL", + + -- Scrollback Lines + scrollback_lines = 20000, +} + +return opts diff --git a/opts.lua b/opts.lua new file mode 100644 index 0000000..9edaaaf --- /dev/null +++ b/opts.lua @@ -0,0 +1,34 @@ +-- ╭─────────────────────────────────────────────────────────╮ +-- │ CONFIG │ +-- ╰─────────────────────────────────────────────────────────╯ + +local opts = {} + +-- Function to merge tables into opts +local function merge_into_opts(mod) + for k, v in pairs(require("config." .. mod)) do + opts[k] = v + end +end + +-- List of config modules to merge +local modules = { + "colors", + "font", + "keys", + "window", + "platform", +} + +-- If USERCONFIG is true, merge userconfig +if USERCONFIG then + merge_into_opts("user") +end + +-- Merge all modules into opts +for _, mod in ipairs(modules) do + merge_into_opts(mod) +end + +-- Return config options +return opts diff --git a/plugins/resurrect.lua b/plugins/resurrect.lua index d98996b..a56aaf2 100644 --- a/plugins/resurrect.lua +++ b/plugins/resurrect.lua @@ -7,6 +7,30 @@ local M = {} -- Load Resurrect plugin RESURRECT = WEZTERM.plugin.require("https://github.com/MLFlexer/resurrect.wezterm") +-- Set the keyfile +local key = WEZTERM.home_dir .. "/.config/.private/key.txt" + +---@function Check if a file exists +---@param file string The file path to check +---@return boolean exists True if the file exists, false otherwise +local function file_exists(file) + local f = io.open(file, "r") + if f then + f:close() + return true + end + return false +end + +if file_exists(key) then + RESURRECT.set_encryption({ + enable = true, + method = "age", -- "age" is the default encryption method, but you can also specify "rage" or "gpg" + private_key = key, -- if using "gpg", you can omit this + public_key = "age1q80h5jsp9d48kggf9kra82xkgyaqdnehqenm003ftapem9re7ytqp9hr6h", + }) +end + -- Set the periodic save interval RESURRECT.periodic_save({ interval_seconds = 60, save_workspaces = true, save_windows = true }) diff --git a/plugs.lua b/plugs.lua new file mode 100644 index 0000000..71eb5d5 --- /dev/null +++ b/plugs.lua @@ -0,0 +1,17 @@ +-- ╭─────────────────────────────────────────────────────────╮ +-- │ PLUGINS │ +-- ╰─────────────────────────────────────────────────────────╯ + +-- List of plugins to load +local plugins = { + "battery", + "hyperlinks", + "resurrect", + "smart_splits", + "tabline", +} + +-- Load all plugins +for _, plugin in ipairs(plugins) do + require("plugins." .. plugin) +end diff --git a/wezterm.lua b/wezterm.lua index cd347bb..63b3719 100644 --- a/wezterm.lua +++ b/wezterm.lua @@ -16,22 +16,21 @@ WEZTERM = require("wezterm") CONFIG = WEZTERM.config_builder() -- Load Options -local configs = require("configs") +local opts = require("opts") -- Apply config -for k, v in pairs(configs) do +for k, v in pairs(opts) do CONFIG[k] = v end -- Check for dev-modes DEVMODE = pcall(require, "dev") --- Load Plugins -require("plugins.battery") -require("plugins.hyperlinks") -require("plugins.resurrect") -require("plugins.smart_splits") -require("plugins.tabline") +-- Check for user-configs +USERCONFIG = pcall(require, "user") + +-- Load plugins +require("plugs") --------- Update Plugins ---------- ---Running this may cause slowdowns