From bf4a37cfdb3ea9b25ca4218ea599b8d15f479ebc Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Sun, 19 Feb 2023 14:44:15 +0100 Subject: [PATCH] fennelize wezterm config --- .config/wezterm/wezterm.lua.cgt | 143 +++++++++----------------------- confgen.lua | 16 ++++ 2 files changed, 55 insertions(+), 104 deletions(-) diff --git a/.config/wezterm/wezterm.lua.cgt b/.config/wezterm/wezterm.lua.cgt index 9683d7f..b5ba27b 100644 --- a/.config/wezterm/wezterm.lua.cgt +++ b/.config/wezterm/wezterm.lua.cgt @@ -1,111 +1,46 @@ -local wt = require "wezterm" +; -local keys = { - -- splitting - { - key = "h", - mods = "LEADER", - action = wt.action.SplitVertical {}, - }, - { - key = "v", - mods = "LEADER", - action = wt.action.SplitHorizontal {}, - }, +(local wt (require :wezterm)) - -- tabs - { - key = "t", - mods = "CTRL|SHIFT", - action = wt.action.SpawnTab "CurrentPaneDomain", - }, - { - key = "t", - mods = "CTRL", - action = wt.action.ActivateTabRelative(1), - }, +(macro kmap [key mods act args] + (if args + `{:key ,key :mods ,mods :action ((. wt :action ,act) ,args)} + `{:key ,key :mods ,mods :action (. wt :action ,act)})) - -- font size - { - key = "+", - mods = "CTRL", - action = wt.action.IncreaseFontSize, - }, - { - key = "-", - mods = "CTRL", - action = wt.action.DecreaseFontSize, - }, +(var keys + [;; splitting + (kmap :h :LEADER :SplitVertical {}) + (kmap :v :LEADER :SplitHorizontal {}) + ;; tabs + (kmap :t :CTRL|SHIFT :SpawnTab :CurrentPaneDomain) + (kmap :t :CTRL :ActivateTabRelative 1) + ;; font size + (kmap "+" :CTRL :IncreaseFontSize) + (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 - { - key = "r", - mods = "LEADER", - action = wt.action.RotatePanes "Clockwise", - }, - { - key = "m", - mods = "LEADER", - action = wt.action.PaneSelect { - mode = "SwapWithActive", - }, - }, +(local directions [[:h :Left] [:j :Down] [:k :Up] [:l :Right]]) - -- scrolling - { - key = "PageUp", - mods = "ALT", - action = wt.action.ScrollByPage(-1), - }, - { - key = "PageDown", - mods = "ALT", - action = wt.action.ScrollByPage(1), - }, +(each [_ dir (ipairs directions)] + (let [(dir-key dir-name) (table.unpack dir)] + ;; switching panes + (table.insert keys (kmap dir-key :ALT :ActivatePaneDirection dir-name)) + ;; 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 + [dir-name resize-amt])))) - -- copying - { - key = "C", - mods = "CTRL|SHIFT", - action = wt.action.CopyTo "ClipboardAndPrimarySelection", - } -} +{: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} -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, -} diff --git a/confgen.lua b/confgen.lua index 9fea300..9e948c6 100644 --- a/confgen.lua +++ b/confgen.lua @@ -33,3 +33,19 @@ end cg.opt.luaCompile = function(lua) return string.dump(loadstring(lua), true) 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