flocon/home/base/programs/wezterm.nix

107 lines
3.5 KiB
Nix
Raw Normal View History

{ pkgs, ... }:
# Workaround for libdecor not being fully implemented yet when using wayland - https://github.com/wez/wezterm/issues/1969#issuecomment-1597817011
let
wrappedWezterm = pkgs.symlinkJoin {
name = "wezterm";
paths = [ pkgs.wezterm ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/wezterm \
--set WAYLAND_DISPLAY "wayland-1" \
--set GTK_THEME "adwaita"
'';
};
in
{
programs.wezterm = {
enable = true;
package = wrappedWezterm;
extraConfig = ''
local w = require('wezterm')
-- if you are *NOT* lazy-loading smart-splits.nvim (recommended)
local function is_vim(pane)
-- this is set by the plugin, and unset on ExitPre in Neovim
return pane:get_user_vars().IS_NVIM == 'true'
end
-- if you *ARE* lazy-loading smart-splits.nvim (not recommended)
-- you have to use this instead, but note that this will not work
-- in all cases (e.g. over an SSH connection). Also note that
-- `pane:get_foreground_process_name()` can have high and highly variable
-- latency, so the other implementation of `is_vim()` will be more
-- performant as well.
local function is_vim(pane)
-- This gsub is equivalent to POSIX basename(3)
-- Given "/foo/bar" returns "bar"
-- Given "c:\\foo\\bar" returns "bar"
local process_name = string.gsub(pane:get_foreground_process_name(), '(.*[/\\])(.*)', '%2')
return process_name == 'nvim' or process_name == 'vim'
end
local direction_keys = {
h = 'Left',
j = 'Down',
k = 'Up',
l = 'Right',
}
local function split_nav(resize_or_move, key)
return {
key = key,
mods = resize_or_move == 'resize' and 'META' or 'CTRL',
action = w.action_callback(function(win, pane)
if is_vim(pane) then
-- pass the keys through to vim/nvim
win:perform_action({
SendKey = { key = key, mods = resize_or_move == 'resize' and 'META' or 'CTRL' },
}, pane)
else
if resize_or_move == 'resize' then
win:perform_action({ AdjustPaneSize = { direction_keys[key], 3 } }, pane)
else
win:perform_action({ ActivatePaneDirection = direction_keys[key] }, pane)
end
end
end),
}
end
return {
front_end = "WebGpu",
enable_wayland = true,
hide_tab_bar_if_only_one_tab = true,
show_new_tab_button_in_tab_bar = false,
harfbuzz_features = { "ss01", "ss03" },
leader = { key = " ", mods = "CTRL", timeout_milliseconds = 1000 },
keys = {
{
mods = "LEADER",
key = "-",
action = wezterm.action.SplitVertical { domain = "CurrentPaneDomain" }
},
{
mods = "LEADER",
key = "=",
action = wezterm.action.SplitHorizontal { domain = "CurrentPaneDomain" }
},
-- move between split panes
split_nav('move', 'h'),
split_nav('move', 'j'),
split_nav('move', 'k'),
split_nav('move', 'l'),
-- resize panes
split_nav('resize', 'h'),
split_nav('resize', 'j'),
split_nav('resize', 'k'),
split_nav('resize', 'l'),
},
}
'';
};
}