feat(wezterm): plugin & config_builder
This commit is contained in:
parent
11ce0bbd3c
commit
83e6afe0ae
5 changed files with 125 additions and 136 deletions
|
@ -2,7 +2,10 @@ local wezterm = require("wezterm")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.config = {
|
-- default configuration
|
||||||
|
local config = {
|
||||||
|
position = "bottom",
|
||||||
|
max_width = 32,
|
||||||
dividers = "slant_right",
|
dividers = "slant_right",
|
||||||
indicator = {
|
indicator = {
|
||||||
leader = {
|
leader = {
|
||||||
|
@ -33,6 +36,9 @@ M.config = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- parsed config
|
||||||
|
local C = {}
|
||||||
|
|
||||||
local function tableMerge(t1, t2)
|
local function tableMerge(t1, t2)
|
||||||
for k, v in pairs(t2) do
|
for k, v in pairs(t2) do
|
||||||
if type(v) == "table" then
|
if type(v) == "table" then
|
||||||
|
@ -48,10 +54,6 @@ local function tableMerge(t1, t2)
|
||||||
return t1
|
return t1
|
||||||
end
|
end
|
||||||
|
|
||||||
local C = {}
|
|
||||||
|
|
||||||
M.setup = function(config)
|
|
||||||
M.config = tableMerge(M.config, config)
|
|
||||||
local dividers = {
|
local dividers = {
|
||||||
slant_right = {
|
slant_right = {
|
||||||
left = utf8.char(0xe0be),
|
left = utf8.char(0xe0be),
|
||||||
|
@ -71,43 +73,58 @@ M.setup = function(config)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- conforming to https://github.com/wez/wezterm/commit/e4ae8a844d8feaa43e1de34c5cc8b4f07ce525dd
|
||||||
|
-- exporting an apply_to_config function, even though we don't change the users config
|
||||||
|
M.apply_to_config = function(c, opts)
|
||||||
|
-- make the opts arg optional
|
||||||
|
if not opts then
|
||||||
|
opts = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- combine user config with defaults
|
||||||
|
config = tableMerge(config, opts)
|
||||||
C.div = {
|
C.div = {
|
||||||
l = "",
|
l = "",
|
||||||
r = "",
|
r = "",
|
||||||
}
|
}
|
||||||
if M.config.dividers then
|
|
||||||
C.div.l = dividers[M.config.dividers].left
|
if config.dividers then
|
||||||
C.div.r = dividers[M.config.dividers].right
|
C.div.l = dividers[config.dividers].left
|
||||||
|
C.div.r = dividers[config.dividers].right
|
||||||
end
|
end
|
||||||
|
|
||||||
C.leader = {
|
C.leader = {
|
||||||
enabled = M.config.indicator.leader.enabled or true,
|
enabled = config.indicator.leader.enabled or true,
|
||||||
off = M.config.indicator.leader.off,
|
off = config.indicator.leader.off,
|
||||||
on = M.config.indicator.leader.on,
|
on = config.indicator.leader.on,
|
||||||
}
|
}
|
||||||
|
|
||||||
C.mode = {
|
C.mode = {
|
||||||
enabled = M.config.indicator.mode.enabled,
|
enabled = config.indicator.mode.enabled,
|
||||||
names = M.config.indicator.mode.names,
|
names = config.indicator.mode.names,
|
||||||
}
|
}
|
||||||
|
|
||||||
C.tabs = {
|
C.tabs = {
|
||||||
numerals = M.config.tabs.numerals,
|
numerals = config.tabs.numerals,
|
||||||
pane_count_style = M.config.tabs.pane_count,
|
pane_count_style = config.tabs.pane_count,
|
||||||
brackets = {
|
brackets = {
|
||||||
active = M.config.tabs.brackets.active,
|
active = config.tabs.brackets.active,
|
||||||
inactive = M.config.tabs.brackets.inactive,
|
inactive = config.tabs.brackets.inactive,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
C.clock = {
|
C.clock = {
|
||||||
enabled = M.config.clock.enabled,
|
enabled = config.clock.enabled,
|
||||||
format = M.config.clock.format,
|
format = config.clock.format,
|
||||||
}
|
}
|
||||||
|
|
||||||
C.p = (M.config.dividers == "rounded") and "" or " "
|
-- set the right-hand padding to 0 spaces, if the rounded style is active
|
||||||
|
C.p = (config.dividers == "rounded") and "" or " "
|
||||||
|
|
||||||
wezterm.log_info(C)
|
-- set wezterm config options according to the parsed config
|
||||||
|
c.use_fancy_tab_bar = false
|
||||||
|
c.tab_bar_at_bottom = config.position == "bottom"
|
||||||
|
c.tab_max_width = config.max_width
|
||||||
end
|
end
|
||||||
|
|
||||||
-- superscript/subscript
|
-- superscript/subscript
|
||||||
|
@ -171,8 +188,8 @@ local roman_numerals = {
|
||||||
-- custom tab bar
|
-- custom tab bar
|
||||||
wezterm.on(
|
wezterm.on(
|
||||||
"format-tab-title",
|
"format-tab-title",
|
||||||
function(tab, tabs, panes, config, hover, max_width)
|
function(tab, tabs, _panes, conf, _hover, _max_width)
|
||||||
local colours = config.resolved_palette.tab_bar
|
local colours = conf.resolved_palette.tab_bar
|
||||||
|
|
||||||
local active_tab_index = 0
|
local active_tab_index = 0
|
||||||
for _, t in ipairs(tabs) do
|
for _, t in ipairs(tabs) do
|
||||||
|
@ -181,13 +198,14 @@ wezterm.on(
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO: make colors configurable
|
||||||
local rainbow = {
|
local rainbow = {
|
||||||
config.resolved_palette.ansi[2],
|
conf.resolved_palette.ansi[2],
|
||||||
config.resolved_palette.indexed[16],
|
conf.resolved_palette.indexed[16],
|
||||||
config.resolved_palette.ansi[4],
|
conf.resolved_palette.ansi[4],
|
||||||
config.resolved_palette.ansi[3],
|
conf.resolved_palette.ansi[3],
|
||||||
config.resolved_palette.ansi[5],
|
conf.resolved_palette.ansi[5],
|
||||||
config.resolved_palette.ansi[6],
|
conf.resolved_palette.ansi[6],
|
||||||
}
|
}
|
||||||
|
|
||||||
local i = tab.tab_index % 6
|
local i = tab.tab_index % 6
|
||||||
|
@ -244,6 +262,7 @@ wezterm.on(
|
||||||
index_i = tab.tab_index + 1
|
index_i = tab.tab_index + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local index
|
||||||
if tab.is_active then
|
if tab.is_active then
|
||||||
index = string.format(
|
index = string.format(
|
||||||
"%s%s%s ",
|
"%s%s%s ",
|
||||||
|
@ -264,8 +283,8 @@ wezterm.on(
|
||||||
local fillerwidth = 2 + string.len(index) + string.len(pane_count) + 2
|
local fillerwidth = 2 + string.len(index) + string.len(pane_count) + 2
|
||||||
|
|
||||||
local tabtitle = tab.active_pane.title
|
local tabtitle = tab.active_pane.title
|
||||||
local width = config.tab_max_width - fillerwidth - 1
|
local width = conf.tab_max_width - fillerwidth - 1
|
||||||
if (#tabtitle + fillerwidth) > config.tab_max_width then
|
if (#tabtitle + fillerwidth) > conf.tab_max_width then
|
||||||
tabtitle = wezterm.truncate_right(tabtitle, width) .. "…"
|
tabtitle = wezterm.truncate_right(tabtitle, width) .. "…"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -282,8 +301,7 @@ wezterm.on(
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
-- custom status
|
wezterm.on("update-status", function(window, _pane)
|
||||||
wezterm.on("update-status", function(window, pane)
|
|
||||||
local active_kt = window:active_key_table() ~= nil
|
local active_kt = window:active_key_table() ~= nil
|
||||||
local show = C.leader.enabled or (active_kt and C.mode.enabled)
|
local show = C.leader.enabled or (active_kt and C.mode.enabled)
|
||||||
if not show then
|
if not show then
|
||||||
|
@ -291,7 +309,11 @@ wezterm.on("update-status", function(window, pane)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local palette = window:effective_config().resolved_palette
|
local present, conf = pcall(window.effective_config, window)
|
||||||
|
if not present then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local palette = conf.resolved_palette
|
||||||
|
|
||||||
local leader = ""
|
local leader = ""
|
||||||
if C.leader.enabled then
|
if C.leader.enabled then
|
||||||
|
|
|
@ -46,4 +46,10 @@ wezterm.on("switch-font", function(window, _)
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
wezterm.GLOBAL = { font = "berkeley" }
|
||||||
|
M.apply = function(c)
|
||||||
|
c.font = M.get_font(wezterm.GLOBAL.font).font
|
||||||
|
c.font_size = M.get_font(wezterm.GLOBAL.font).size
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
@ -13,6 +13,7 @@ local map = function(key, mods, action)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
wezterm.GLOBAL.enable_tab_bar = true
|
||||||
local toggleTabBar = wezterm.action_callback(function(window)
|
local toggleTabBar = wezterm.action_callback(function(window)
|
||||||
wezterm.GLOBAL.enable_tab_bar = not wezterm.GLOBAL.enable_tab_bar
|
wezterm.GLOBAL.enable_tab_bar = not wezterm.GLOBAL.enable_tab_bar
|
||||||
window:set_config_overrides({
|
window:set_config_overrides({
|
||||||
|
@ -113,9 +114,11 @@ for k, _ in pairs(key_tables) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
local M = {}
|
||||||
leader = { key = "s", mods = "CTRL", timeout_milliseconds = 5000 },
|
M.apply = function(c)
|
||||||
keys = shortcuts,
|
c.leader = { key = "s", mods = "CTRL", timeout_milliseconds = 5000 }
|
||||||
disable_default_key_bindings = true,
|
c.keys = shortcuts
|
||||||
key_tables = key_tables,
|
c.disable_default_key_bindings = true
|
||||||
}
|
c.key_tables = key_tables
|
||||||
|
end
|
||||||
|
return M
|
||||||
|
|
|
@ -25,4 +25,12 @@ M.get_custom_colorschemes = function()
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M.apply = function(c)
|
||||||
|
c.color_schemes = M.get_custom_colorschemes()
|
||||||
|
c.color_scheme = M.scheme_for_appearance(wezterm.gui.get_appearance(), {
|
||||||
|
dark = "Catppuccin Americano",
|
||||||
|
light = "Catppuccin Latte",
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
@ -1,85 +1,35 @@
|
||||||
local wezterm = require("wezterm")
|
local wezterm = require("wezterm")
|
||||||
local theme = require("theme")
|
|
||||||
require("bar").setup({
|
|
||||||
dividers = "slant_right", -- or "slant_left", "arrows", "rounded", false
|
|
||||||
indicator = {
|
|
||||||
leader = {
|
|
||||||
enabled = true,
|
|
||||||
off = " ",
|
|
||||||
on = " ",
|
|
||||||
},
|
|
||||||
mode = {
|
|
||||||
enabled = true,
|
|
||||||
names = {
|
|
||||||
resize_mode = "RESIZE",
|
|
||||||
copy_mode = "VISUAL",
|
|
||||||
search_mode = "SEARCH",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
tabs = {
|
|
||||||
numerals = "arabic", -- or "roman"
|
|
||||||
pane_count = "superscript", -- or "subscript", false
|
|
||||||
brackets = {
|
|
||||||
active = { "", ":" },
|
|
||||||
inactive = { "", ":" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
clock = { -- note that this overrides the whole set_right_status
|
|
||||||
enabled = true,
|
|
||||||
format = "%H:%M", -- use https://wezfurlong.org/wezterm/config/lua/wezterm.time/Time/format.html
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
wezterm.GLOBAL = {
|
local c = wezterm.config_builder()
|
||||||
font = "berkeley",
|
c:set_strict_mode(true)
|
||||||
enable_tab_bar = true,
|
|
||||||
}
|
|
||||||
local font = require("fonts").get_font(wezterm.GLOBAL.font)
|
|
||||||
|
|
||||||
local options = {
|
require("fonts").apply(c)
|
||||||
set_environment_variables = {
|
require("keys").apply(c)
|
||||||
|
require("theme").apply(c)
|
||||||
|
|
||||||
|
-- set up terminfo on nix
|
||||||
|
c.set_environment_variables = {
|
||||||
TERMINFO_DIRS = wezterm.home_dir .. "/.nix-profile/share/terminfo",
|
TERMINFO_DIRS = wezterm.home_dir .. "/.nix-profile/share/terminfo",
|
||||||
},
|
}
|
||||||
-- font
|
|
||||||
font = font.font,
|
|
||||||
font_size = font.size,
|
|
||||||
-- window
|
-- window
|
||||||
window_decorations = "RESIZE",
|
c.window_decorations = "RESIZE"
|
||||||
window_padding = {
|
c.window_padding = {
|
||||||
left = 0,
|
left = 0,
|
||||||
right = 0,
|
right = 0,
|
||||||
top = 0,
|
top = 0,
|
||||||
bottom = 0,
|
bottom = 0,
|
||||||
},
|
}
|
||||||
inactive_pane_hsb = {
|
-- dim unfocused panes
|
||||||
|
c.inactive_pane_hsb = {
|
||||||
saturation = 1.0,
|
saturation = 1.0,
|
||||||
brightness = 0.6,
|
brightness = 0.6,
|
||||||
},
|
|
||||||
-- theme
|
|
||||||
color_schemes = theme.get_custom_colorschemes(),
|
|
||||||
color_scheme = theme.scheme_for_appearance(wezterm.gui.get_appearance(), {
|
|
||||||
dark = "Catppuccin Americano",
|
|
||||||
light = "Catppuccin Latte",
|
|
||||||
}),
|
|
||||||
-- tab bar
|
|
||||||
tab_bar_at_bottom = true,
|
|
||||||
tab_max_width = 32,
|
|
||||||
use_fancy_tab_bar = false,
|
|
||||||
window_background_opacity = 1.00,
|
|
||||||
hide_tab_bar_if_only_one_tab = false,
|
|
||||||
enable_tab_bar = wezterm.GLOBAL.tab_bar_hidden,
|
|
||||||
-- etc.
|
|
||||||
adjust_window_size_when_changing_font_size = false,
|
|
||||||
use_resize_increments = false,
|
|
||||||
audible_bell = "Disabled",
|
|
||||||
clean_exit_codes = { 130 },
|
|
||||||
default_cursor_style = "BlinkingBar",
|
|
||||||
enable_scroll_bar = false,
|
|
||||||
}
|
}
|
||||||
|
-- etc.
|
||||||
|
c.adjust_window_size_when_changing_font_size = false
|
||||||
|
c.audible_bell = "Disabled"
|
||||||
|
c.clean_exit_codes = { 130 }
|
||||||
|
c.default_cursor_style = "BlinkingBar"
|
||||||
|
|
||||||
for k, v in pairs(require("keys")) do
|
require("bar").apply_to_config(c)
|
||||||
options[k] = v
|
|
||||||
end
|
|
||||||
|
|
||||||
return options
|
return c
|
||||||
|
|
Loading…
Reference in a new issue