irongit
dotfiles/wezterm/wezterm.lua
125 lines4.4 KBLua
1local wezterm = require("wezterm")
2local utils = require("utils")
3local act = wezterm.action
4local config = wezterm.config_builder()
5local resurrect = wezterm.plugin.require("https://github.com/MLFlexer/resurrect.wezterm")
6local tabline = wezterm.plugin.require("https://github.com/michaelbrusegard/tabline.wez")
7local workspace_switcher = wezterm.plugin.require("https://github.com/MLFlexer/smart_workspace_switcher.wezterm")
8
9-- set up tabline
10tabline.setup()
11tabline.apply_to_config(config)
12
13-- set up resurrect
14wezterm.on("gui-startup", resurrect.state_manager.resurrect_on_gui_startup)
15resurrect.state_manager.periodic_save()
16
17-- window config
18config.enable_wayland = false
19config.font_size = 8
20config.window_decorations = "RESIZE"
21config.window_background_opacity = 0.85
22config.enable_scroll_bar = true
23config.colors = {
24 scrollbar_thumb = "orange",
25}
26config.color_scheme = "Tokyo Night Storm"
27
28-- keymap
29config.keys = {
30 -- Vim like pane movement
31 { key = "h", mods = "ALT", action = act.ActivatePaneDirection("Left") },
32 { key = "j", mods = "ALT", action = act.ActivatePaneDirection("Down") },
33 { key = "k", mods = "ALT", action = act.ActivatePaneDirection("Up") },
34 { key = "l", mods = "ALT", action = act.ActivatePaneDirection("Right") },
35
36 -- Vim like resize events
37 { key = "h", mods = "SHIFT|ALT", action = act.AdjustPaneSize({ "Left", 3 }) },
38 { key = "j", mods = "SHIFT|ALT", action = act.AdjustPaneSize({ "Down", 3 }) },
39 { key = "k", mods = "SHIFT|ALT", action = act.AdjustPaneSize({ "Up", 3 }) },
40 { key = "l", mods = "SHIFT|ALT", action = act.AdjustPaneSize({ "Right", 3 }) },
41
42 -- Vim like create panes
43 { key = "h", mods = "CTRL|SHIFT", action = act.SplitPane({ direction = "Left" }) },
44 { key = "j", mods = "CTRL|SHIFT", action = act.SplitPane({ direction = "Down" }) },
45 { key = "k", mods = "CTRL|SHIFT", action = act.SplitPane({ direction = "Up" }) },
46 { key = "l", mods = "CTRL|SHIFT", action = act.SplitPane({ direction = "Right" }) },
47
48 -- New tab in current pane's cwd
49 { key = "t", mods = "SHIFT|ALT", action = act.SpawnTab("CurrentPaneDomain") },
50
51 -- Close current pane
52 { key = "q", mods = "ALT", action = act.CloseCurrentPane({ confirm = true }) },
53
54 -- open lazygit
55 {
56 key = "g",
57 mods = "CTRL|SHIFT",
58 action = wezterm.action_callback(function(win, pane)
59 win:perform_action(act.SplitPane({ direction = "Right", command = { args = { "lazygit" } } }), pane)
60 win:perform_action(act.TogglePaneZoomState, pane)
61 end),
62 },
63
64 -- workspace switcher
65 {
66 key = "p",
67 mods = "ALT",
68 action = workspace_switcher.switch_to_prev_workspace(),
69 },
70
71 -- resurrect bindings
72 {
73 key = "w",
74 mods = "ALT",
75 action = wezterm.action_callback(function(win, pane)
76 resurrect.state_manager.save_state(resurrect.workspace_state.get_workspace_state())
77 end),
78 },
79 {
80 key = "W",
81 mods = "ALT",
82 action = resurrect.window_state.save_window_action(),
83 },
84 {
85 key = "T",
86 mods = "ALT",
87 action = resurrect.tab_state.save_tab_action(),
88 },
89 {
90 key = "s",
91 mods = "ALT",
92 action = wezterm.action_callback(function(win, pane)
93 resurrect.state_manager.save_state(resurrect.workspace_state.get_workspace_state())
94 resurrect.window_state.save_window_action()
95 end),
96 },
97 {
98 key = "r",
99 mods = "ALT",
100 action = wezterm.action_callback(function(win, pane)
101 resurrect.fuzzy_loader.fuzzy_load(win, pane, function(id, label)
102 local type = string.match(id, "^([^/]+)") -- match before '/'
103 id = string.match(id, "([^/]+)$") -- match after '/'
104 id = string.match(id, "(.+)%..+$") -- remove file extention
105 local opts = {
106 relative = true,
107 restore_text = true,
108 on_pane_restore = resurrect.tab_state.default_on_pane_restore,
109 }
110 if type == "workspace" then
111 local state = resurrect.state_manager.load_state(id, "workspace")
112 resurrect.workspace_state.restore_workspace(state, opts)
113 elseif type == "window" then
114 local state = resurrect.state_manager.load_state(id, "window")
115 resurrect.window_state.restore_window(pane:window(), state, opts)
116 elseif type == "tab" then
117 local state = resurrect.state_manager.load_state(id, "tab")
118 resurrect.tab_state.restore_tab(pane:tab(), state, opts)
119 end
120 end)
121 end),
122 },
123}
124
125return config