refactor(wezterm): major library improvements
This commit is contained in:
parent
0ee9ab366d
commit
839a8bb618
@ -80,7 +80,7 @@ M.setup = function()
|
||||
opt.completeopt = 'menuone,noselect'
|
||||
|
||||
-- Set max text width
|
||||
opt.textwidth = 120
|
||||
opt.textwidth = 80
|
||||
|
||||
-- Highlight cursor line
|
||||
opt.cursorline = true
|
||||
|
@ -1,4 +1,5 @@
|
||||
local wezterm = require("wezterm")
|
||||
local lib = require("wlib")
|
||||
|
||||
return {
|
||||
-- use_cap_height_to_scale_fallback_fonts = true,
|
||||
@ -23,5 +24,9 @@ return {
|
||||
-- <built-in>, BuiltIn
|
||||
"Last Resort High-Efficiency",
|
||||
}),
|
||||
font_dirs = {
|
||||
lib.determine_home_path() .. "/.config/fonts",
|
||||
},
|
||||
font_locator = "ConfigDirsOnly",
|
||||
font_size = 14,
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
local wezterm = require("wezterm")
|
||||
|
||||
return {
|
||||
-- disable_default_key_bindings = true,
|
||||
disable_default_key_bindings = true,
|
||||
leader = { key = "a", mods = "CTRL", timeout_milliseconds = 100000 },
|
||||
keys = {
|
||||
{ key = "r", mods = "SUPER", action = "ReloadConfiguration" },
|
||||
|
@ -1,15 +0,0 @@
|
||||
local mergeable_table = {}
|
||||
|
||||
function mergeable_table.merge(...)
|
||||
local ret = {}
|
||||
for _, tbl in ipairs({ ... }) do
|
||||
for k, v in pairs(tbl) do
|
||||
ret[k] = v
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
return {
|
||||
mergeable_table = mergeable_table,
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
local mergeable_table = require("lib").mergeable_table
|
||||
local Table = require("wlib").new_table()
|
||||
|
||||
-- NOTE: Should be merged
|
||||
local events = require("config.events")
|
||||
@ -9,5 +9,5 @@ local rendering = require("config.rendering")
|
||||
local keybinds = require("config.keybinds")
|
||||
local misc = require("config.misc")
|
||||
|
||||
local config = mergeable_table.merge(events, fonts, theme, tabbar, misc, rendering, keybinds)
|
||||
local config = Table.merge(events, fonts, theme, tabbar, misc, rendering, keybinds)
|
||||
return config
|
||||
|
89
.config/wezterm/wlib.lua
Normal file
89
.config/wezterm/wlib.lua
Normal file
@ -0,0 +1,89 @@
|
||||
local os = require("os")
|
||||
local M = {}
|
||||
|
||||
--- Creates a new custom table that allows
|
||||
--- usage of lua's `table` attributes
|
||||
---
|
||||
--- This is done really oddly such that we create a local table instance for
|
||||
--- each invocation, but also get methods for each new table in a lua style
|
||||
---
|
||||
---@return table
|
||||
function M.new_table()
|
||||
local t = {}
|
||||
|
||||
--- Dump a table into a json-ish string format,
|
||||
--- shamelessly taken from https://stackoverflow.com/a/27028488
|
||||
---@param o table
|
||||
local function dump(o)
|
||||
if type(o) == "table" then
|
||||
local s = "{\n"
|
||||
for k, v in pairs(o) do
|
||||
if type(k) ~= "number" then
|
||||
k = '"' .. k .. '"'
|
||||
end
|
||||
s = s .. " [" .. k .. "] = " .. dump(v) .. ",\n"
|
||||
end
|
||||
return s .. "} "
|
||||
else
|
||||
return tostring(o)
|
||||
end
|
||||
end
|
||||
|
||||
--- Simple wrapper around dump function
|
||||
---@return string
|
||||
function t.dump()
|
||||
return dump(t)
|
||||
end
|
||||
|
||||
--- Allows the combining of multiple tables, where the last table given has the highest
|
||||
--- priority (it overrides the keys of other tables)
|
||||
---@vararg table
|
||||
---@return table
|
||||
function t.merge(...)
|
||||
local ret = {}
|
||||
for _, tbl in ipairs({ ... }) do
|
||||
for k, v in pairs(tbl) do
|
||||
ret[k] = v
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
--- Returns the path to the users home, note this string needs to be regularized as
|
||||
--- this is used on both windows and unix.
|
||||
--- @return string
|
||||
function M.determine_home_path()
|
||||
-- This helps give a better error message
|
||||
-- if we are unable to find their home dir
|
||||
-- from a environment variable
|
||||
local checked_env_vars = M.new_table()
|
||||
|
||||
-- Attempt to get UNIX home
|
||||
local unix_home_var = "HOM"
|
||||
local unix_home = os.getenv(unix_home_var)
|
||||
table.insert(checked_env_vars, unix_home_var)
|
||||
-- This style is chosen as a guard so it's easier
|
||||
-- to extend in the future
|
||||
if unix_home then
|
||||
return unix_home
|
||||
end
|
||||
|
||||
-- Attempt to get Windows home
|
||||
local win_home_drive = os.getenv("HOMEDRIVE")
|
||||
local win_home = os.getenv("HOMEPATH")
|
||||
if win_home then
|
||||
return win_home_drive .. win_home
|
||||
end
|
||||
|
||||
-- NOTE: This will error if it cannot determine the home path
|
||||
error(
|
||||
"Unable to determine user's home directory, checked environment variables:\n\n"
|
||||
.. checked_env_vars.dump()
|
||||
.. "\n\n"
|
||||
)
|
||||
end
|
||||
|
||||
return M
|
Loading…
Reference in New Issue
Block a user