fennelize wezterm config

This commit is contained in:
LordMZTE 2023-02-19 14:44:15 +01:00
parent c79c74d23c
commit bf4a37cfdb
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
2 changed files with 55 additions and 104 deletions

View file

@ -1,111 +1,46 @@
local wt = require "wezterm" ;<! tmpl:setPostProcessor(opt.fennelCompile) !>
local keys = { (local wt (require :wezterm))
-- splitting
{
key = "h",
mods = "LEADER",
action = wt.action.SplitVertical {},
},
{
key = "v",
mods = "LEADER",
action = wt.action.SplitHorizontal {},
},
-- tabs (macro kmap [key mods act args]
{ (if args
key = "t", `{:key ,key :mods ,mods :action ((. wt :action ,act) ,args)}
mods = "CTRL|SHIFT", `{:key ,key :mods ,mods :action (. wt :action ,act)}))
action = wt.action.SpawnTab "CurrentPaneDomain",
},
{
key = "t",
mods = "CTRL",
action = wt.action.ActivateTabRelative(1),
},
-- font size (var keys
{ [;; splitting
key = "+", (kmap :h :LEADER :SplitVertical {})
mods = "CTRL", (kmap :v :LEADER :SplitHorizontal {})
action = wt.action.IncreaseFontSize, ;; tabs
}, (kmap :t :CTRL|SHIFT :SpawnTab :CurrentPaneDomain)
{ (kmap :t :CTRL :ActivateTabRelative 1)
key = "-", ;; font size
mods = "CTRL", (kmap "+" :CTRL :IncreaseFontSize)
action = wt.action.DecreaseFontSize, (kmap "-" :CTRL :DecreaseFontSize)
}, ;; moving panes
(kmap :r :LEADER :RotatePanes :Clockwise)
(kmap :m :LEADER :PaneSelect {:mode :SwapWithActive})
;; scrolling
(kmap :PageUp :ALT :ScrollByPage -1)
(kmap :PageDown :ALT :ScrollByPage 1)
;; copying
(kmap :C :CTRL|SHIFT :CopyTo :ClipboardAndPrimarySelection)])
-- moving panes (local directions [[:h :Left] [:j :Down] [:k :Up] [:l :Right]])
{
key = "r",
mods = "LEADER",
action = wt.action.RotatePanes "Clockwise",
},
{
key = "m",
mods = "LEADER",
action = wt.action.PaneSelect {
mode = "SwapWithActive",
},
},
-- scrolling (each [_ dir (ipairs directions)]
{ (let [(dir-key dir-name) (table.unpack dir)]
key = "PageUp", ;; switching panes
mods = "ALT", (table.insert keys (kmap dir-key :ALT :ActivatePaneDirection dir-name))
action = wt.action.ScrollByPage(-1), ;; resize double in horizontal directions so the absolute amounts are constant
}, (local resize-amt (if (or (= dir-name :Up) (= dir-name :Down)) 2 4))
{ (table.insert keys (kmap dir-key :ALT|SHIFT :AdjustPaneSize
key = "PageDown", [dir-name resize-amt]))))
mods = "ALT",
action = wt.action.ScrollByPage(1),
},
-- copying {:color_scheme "Dracula (Official)"
{ :font (wt.font "<% opt.term_font %>")
key = "C", :window_background_opacity 0.8
mods = "CTRL|SHIFT", :disable_default_key_bindings true
action = wt.action.CopyTo "ClipboardAndPrimarySelection", :leader {:key :a :mods :CTRL :timeout_milliseconds 2000}
} : keys}
}
local directions = {
{ "h", "Left" },
{ "j", "Down" },
{ "k", "Up" },
{ "l", "Right" },
}
for _, dir in pairs(directions) do
local dir_key = dir[1]
local dir_name = dir[2]
-- switching panes
table.insert(keys, {
key = dir_key,
mods = "ALT",
action = wt.action.ActivatePaneDirection(dir_name),
})
-- resize double in horizontal directions so the absolute amounts are constant
local resize_amount = (dir_name == "Up" or dir_name == "Down") and 2 or 4
-- resizing panes
table.insert(keys, {
key = dir_key,
mods = "ALT|SHIFT",
action = wt.action.AdjustPaneSize { dir_name, resize_amount },
})
end
return {
color_scheme = "Dracula (Official)",
font = wt.font "<% opt.term_font %>",
window_background_opacity = 0.8,
disable_default_key_bindings = true,
leader = { key = "a", mods = "CTRL", timeout_milliseconds = 2000 },
keys = keys,
}

View file

@ -33,3 +33,19 @@ end
cg.opt.luaCompile = function(lua) cg.opt.luaCompile = function(lua)
return string.dump(loadstring(lua), true) return string.dump(loadstring(lua), true)
end end
-- Compile the input as fennel. Meant to be used as a post-processor.
cg.opt.fennelCompile = function(fnl)
local handle = io.popen("fennel -c - > /tmp/cgfnl", "w")
if handle == nil then
error "Failed to spawn fennel"
end
handle:write(fnl)
handle:close()
local f = io.open "/tmp/cgfnl"
local res = f:read "*a"
f:close()
return res
end