2
0
mirror of https://github.com/webgefrickel/dotfiles synced 2024-11-09 13:10:27 +00:00
steffen-dotfiles/.wezterm.lua

231 lines
7.3 KiB
Lua
Raw Normal View History

local wezterm = require('wezterm')
local act = wezterm.action
local config = wezterm.config_builder()
2024-02-14 09:35:12 +00:00
local mux = wezterm.mux
-- helper functions
local function get_current_working_dir(tab)
local current_dir = tab.active_pane.current_working_dir
local HOME_DIR = string.format('file://%s', os.getenv('HOME'))
2024-05-28 15:29:27 +00:00
return current_dir == HOME_DIR and '~' or string.gsub(tostring(current_dir), '(.*[/\\])(.*)', '%2')
end
2023-09-30 15:37:21 +00:00
local function isVim(pane)
return pane:get_foreground_process_name():find('n?vim') ~= nil
end
local function conditionalActivatePane(window, pane, pane_direction, vim_direction)
2023-09-30 15:37:21 +00:00
if isVim(pane) then
window:perform_action(act.SendKey({ key = vim_direction, mods = 'CTRL' }), pane)
else
window:perform_action(act.ActivatePaneDirection(pane_direction), pane)
end
end
2023-10-04 18:15:19 +00:00
-- open new development session with splits and commands
-- this expects the default src / public-dist structure to work
local function newDevelopmentSession(path_and_title)
local sites_dir = wezterm.home_dir .. '/Sites/'
2023-10-04 18:32:00 +00:00
local dev_tab, dev_pane, dev_window = mux.spawn_window({
cwd = sites_dir .. path_and_title,
2023-10-04 18:15:19 +00:00
workspace = path_and_title,
2023-10-04 18:32:00 +00:00
})
2023-10-04 18:15:19 +00:00
local src_tab, src_pane, dev_window = dev_window:spawn_tab({
2023-10-04 18:32:00 +00:00
cwd = sites_dir .. path_and_title,
2023-10-04 18:15:19 +00:00
})
2024-02-03 16:37:35 +00:00
local git_tab, git_pane, dev_window = dev_window:spawn_tab({
cwd = sites_dir .. path_and_title,
})
2024-07-05 14:03:15 +00:00
local devcli_pane = dev_pane:split({
2023-10-04 18:15:19 +00:00
workspace = path_and_title,
direction = 'Right',
2024-02-03 16:37:35 +00:00
cwd = sites_dir .. path_and_title,
2023-10-04 18:15:19 +00:00
})
2024-07-05 14:03:15 +00:00
dev_tab:set_title('zsh')
dev_pane:send_text('v package.json\n')
devcli_pane:send_text('g pl && g l\n')
2023-10-04 18:15:19 +00:00
src_tab:set_title('src')
2024-02-03 16:37:35 +00:00
git_tab:set_title('git')
git_pane:send_text('lg\n')
2023-10-04 18:15:19 +00:00
2024-07-05 14:03:15 +00:00
dev_tab:activate()
2023-10-04 18:15:19 +00:00
mux.set_active_workspace(path_and_title)
end
-- base config
2024-07-11 10:09:38 +00:00
config.color_scheme = 'Gruvbox Material (Gogh)'
config.line_height = 1.15
config.font_size = 14.0
2024-02-14 09:35:12 +00:00
config.font = wezterm.font({
family = 'MonaspiceAr Nerd Font',
harfbuzz_features = { 'calt', 'liga', 'dlig', 'ss01', 'ss02', 'ss03', 'ss04', 'ss05', 'ss06', 'ss07', 'ss08' },
})
2023-09-30 15:37:21 +00:00
config.default_prog = { '/opt/homebrew/bin/zsh' }
config.initial_cols = 120
config.initial_rows = 32
2023-10-02 10:07:26 +00:00
config.inactive_pane_hsb = { saturation = 0.5, brightness = 0.9 }
config.leader = { key = 'a', mods = 'CTRL', timeout_milliseconds = 1000 }
config.scrollback_lines = 5000
2023-10-02 10:07:26 +00:00
config.send_composed_key_when_left_alt_is_pressed = true
config.show_new_tab_button_in_tab_bar = false
config.tab_bar_at_bottom = true
config.use_dead_keys = false
config.use_fancy_tab_bar = false
config.window_decorations = 'RESIZE'
-- key mappings
config.keys = {
2023-10-10 18:31:00 +00:00
{ key = '\\', mods = 'LEADER', action = act.SplitHorizontal },
{ key = '-', mods = 'LEADER', action = act.SplitVertical },
{ key = ']', mods = 'LEADER', action = act.ActivateCopyMode },
{ key = 'g', mods = 'LEADER', action = act.ShowLauncherArgs { flags = 'FUZZY|WORKSPACES' } },
-- Navigator.nvim keys
{ key = 'h', mods = 'CTRL', action = act.EmitEvent('ActivatePaneDirection-left') },
{ key = 'j', mods = 'CTRL', action = act.EmitEvent('ActivatePaneDirection-down') },
{ key = 'k', mods = 'CTRL', action = act.EmitEvent('ActivatePaneDirection-up') },
{ key = 'l', mods = 'CTRL', action = act.EmitEvent('ActivatePaneDirection-right') },
-- leader-key mappings
{
key = ',',
mods = 'LEADER',
action = act.PromptInputLine {
description = 'Enter new name for tab',
action = wezterm.action_callback(function(window, pane, line)
if line then
window:active_tab():set_title(line)
end
end),
},
},
{
key = 'c',
mods = 'LEADER',
action = act.PromptInputLine {
description = 'Enter name for new workspace',
action = wezterm.action_callback(function(window, pane, line)
if line then
window:perform_action(
act.SwitchToWorkspace {
name = line,
},
pane
)
end
end),
},
},
2023-10-04 18:15:19 +00:00
{
key = 'd',
mods = 'LEADER',
action = act.PromptInputLine {
description = 'Enter name for new workspace',
action = wezterm.action_callback(function(window, pane, line)
if line then
newDevelopmentSession(line:gsub('%s+', ''))
end
end),
},
},
{
key = '$',
mods = 'LEADER',
action = act.PromptInputLine {
description = 'Rename current workspace',
action = wezterm.action_callback(function(window, pane, line)
if line then
2024-02-14 09:35:12 +00:00
mux.rename_workspace(mux.get_active_workspace(), line)
end
end),
},
},
}
-- Navigator.nvim events
wezterm.on('ActivatePaneDirection-right', function(window, pane)
conditionalActivatePane(window, pane, 'Right', 'l')
end)
wezterm.on('ActivatePaneDirection-left', function(window, pane)
conditionalActivatePane(window, pane, 'Left', 'h')
end)
wezterm.on('ActivatePaneDirection-up', function(window, pane)
conditionalActivatePane(window, pane, 'Up', 'k')
end)
wezterm.on('ActivatePaneDirection-down', function(window, pane)
conditionalActivatePane(window, pane, 'Down', 'j')
end)
-- set tab-title to current dir if not set explicitly
wezterm.on('format-tab-title', function(tab)
local cwd = get_current_working_dir(tab)
local title = tab.tab_title
local num = tab.tab_index + 1
if title and #title > 0 then
return string.format(' %s %s ', num, title)
end
return string.format(' %s %s ', num, cwd)
end)
2024-04-10 09:44:43 +00:00
-- Vim ZenMode fontsize-sync
wezterm.on('user-var-changed', function(window, pane, name, value)
local overrides = window:get_config_overrides() or {}
if name == "ZEN_MODE" then
local incremental = value:find("+")
local number_value = tonumber(value)
if incremental ~= nil then
while (number_value > 0) do
window:perform_action(wezterm.action.IncreaseFontSize, pane)
number_value = number_value - 1
end
overrides.enable_tab_bar = false
elseif number_value < 0 then
window:perform_action(wezterm.action.ResetFontSize, pane)
overrides.font_size = nil
overrides.enable_tab_bar = true
else
overrides.font_size = number_value
overrides.enable_tab_bar = false
end
end
window:set_config_overrides(overrides)
end)
-- show workspace on the left side of tabbar
wezterm.on('update-status', function(window)
local workspace = mux.get_active_workspace()
window:set_left_status(string.format(' %s ', workspace))
end)
2024-02-14 09:35:12 +00:00
-- always maximise and start default session with mutt, notes and dotfiles
wezterm.on('gui-startup', function()
2023-10-04 18:15:19 +00:00
local home_dir = wezterm.home_dir
local tab, pane, window = mux.spawn_window({ cwd = home_dir })
local todo_tab, todo_pane, window = window:spawn_tab({ cwd = home_dir .. '/Notes' })
local dot_tab, dot_pane, window = window:spawn_tab({ cwd = home_dir .. '/Dotfiles' })
local git_pane = dot_pane:split({ direction = 'Right', cwd = home_dir .. '/Dotfiles' })
2024-07-05 14:03:15 +00:00
2023-10-04 18:15:19 +00:00
tab:set_title('mail')
pane:send_text('O && m\n')
dot_tab:set_title('dotfiles')
dot_pane:send_text('v nvim/init.lua\n')
todo_tab:set_title('todo')
2024-02-14 13:02:31 +00:00
todo_pane:send_text('v index.md\n')
2023-10-04 18:15:19 +00:00
git_pane:send_text('gs\n')
2023-10-04 18:32:00 +00:00
tab:activate()
2023-10-04 18:15:19 +00:00
-- initialize some sessions for MRU projects and folders
newDevelopmentSession('ag/core')
newDevelopmentSession('ag/web')
2023-10-04 18:32:00 +00:00
newDevelopmentSession('ag/sp')
newDevelopmentSession('pax/frontend')
newDevelopmentSession('wwz/frontend')
2023-10-04 18:15:19 +00:00
mux.set_active_workspace('default')
window:gui_window():maximize()
end)
return config