Skip to content

Commit

Permalink
wezterm: add scrollback editing with vim, and disable clickable hyper…
Browse files Browse the repository at this point in the history
…links
  • Loading branch information
damncabbage committed Aug 29, 2023
1 parent b9c06f8 commit 8ca796d
Showing 1 changed file with 65 additions and 2 deletions.
67 changes: 65 additions & 2 deletions .config/wezterm/wezterm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,40 @@ local codelia = function(overrides)
return wezterm.font(font)
end

---------- Misc Helpers ----------
local scrollback_lines = 10000
wezterm.on("trigger-vim-with-scrollback", function(window, pane)
-- Retrieve the current viewport's text.
-- Pass an optional number of lines (eg: 2000) to retrieve
-- that number of lines starting from the bottom of the viewport
local scrollback = pane:get_logical_lines_as_text(scrollback_lines);

-- Create a temporary file to pass to vim
local name = os.tmpname();
local f = io.open(name, "w+");
f:write(scrollback);
f:flush();
f:close();

-- Open a new window running vim and tell it to open the file
window:perform_action(
wezterm.action{
SpawnCommandInNewWindow={args={"vim", name}}
},
pane
)

-- wait "enough" time for vim to read the file before we remove it.
-- The window creation and process spawn are asynchronous
-- wrt. running this script and are not awaitable, so we just pick
-- a number.
wezterm.sleep_ms(1000);
os.remove(name);
end)


---------- Config ----------
return {
local config = {
font_rules = {
{
italic = true,
Expand Down Expand Up @@ -141,7 +172,7 @@ return {
{ key = '>', mods = 'SUPER|ALT|SHIFT', action = act.AdjustPaneSize { 'Right', 3 } },
{ key = '<', mods = 'SUPER|ALT|SHIFT', action = act.AdjustPaneSize { 'Left', 3 } },

-- Misc
-- Scrollback
{
key = 'k',
mods = 'SUPER',
Expand All @@ -150,6 +181,35 @@ return {
act.SendKey { key = 'l', mods = 'CTRL' },
},
},
{
key = 'e',
mods = 'SUPER',
action=wezterm.action{EmitEvent="trigger-vim-with-scrollback"},
},
},

mouse_bindings = {
-- Change the default click behavior so that it only selects
-- text and doesn't open hyperlinks
{
event={Up={streak=1, button="Left"}},
mods="NONE",
action=act.CompleteSelection("PrimarySelection"),
},

-- and make Super-Click open hyperlinks
{
event={Up={streak=1, button="Left"}},
mods="SUPER",
action=act.OpenLinkAtMouseCursor,
},

-- Disable the 'Down' event of SUPER-Click to avoid weird program behaviors
{
event = { Down = { streak = 1, button = 'Left' } },
mods = 'SUPER',
action = act.Nop,
}
},

---------- Misc ----------
Expand All @@ -160,5 +220,8 @@ return {
target = 'BackgroundColor',
},

scrollback_lines = scrollback_lines,

check_for_updates_interval_seconds = 604800,
}
return config

0 comments on commit 8ca796d

Please sign in to comment.