fix(nvim): add workaround for lack of OSC 7

We are working around the problem
of neovim not outputting OSC 7
properly. The issue link is as
follows https://github.com/neovim/neovim/issues/2252
chezmoi
sgoudham 2 years ago
parent d8ed2ef2c2
commit 011dee305e
Signed by: hammy
GPG Key ID: 44E818FD5457EEA4

@ -1,11 +1,17 @@
local wk = require("which-key") local wk = require("which-key")
-- what a workaround (screw you @nekowinston :sob:)
-- https://github.com/wez/wezterm/discussions/2426
-- https://github.com/neovim/neovim/issues/2252
wk.register({ wk.register({
["0"] = { "0^", "" } ["<A-N>"] = { "<cmd>lua io.popen('wezterm cli split-pane --right --cwd .')<cr>", "All my homies hate OSC 7" },
}) ["<A-M>"] = { "<cmd>lua io.popen('wezterm cli split-pane --bottom --cwd .')<cr>", "All my homies hate OSC 7" },
}, { mode = { "n", "i", "v", "t" } })
-- normal binds -- normal binds
wk.register({ wk.register({
["0"] = { "0^", "Start of Line" },
["<CR>"] = { "o<ESC>", "New Line Without Insert" },
["<C-s>"] = { "<cmd>write<cr>", "Save" }, ["<C-s>"] = { "<cmd>write<cr>", "Save" },
["<C-d>"] = { "<C-d>zz", "Half page down" }, ["<C-d>"] = { "<C-d>zz", "Half page down" },
["<C-u>"] = { "<C-u>zz", "Half page up" }, ["<C-u>"] = { "<C-u>zz", "Half page up" },

@ -1,210 +1,251 @@
local wezterm = require 'wezterm'; local wezterm = require("wezterm")
local act = wezterm.action local act = wezterm.action
local wsl_domains = wezterm.default_wsl_domains() local wsl_domains = wezterm.default_wsl_domains()
-- WSL related -- WSL related
for _, dom in ipairs(wsl_domains) do for _, dom in ipairs(wsl_domains) do
dom.default_cwd = "~" dom.default_cwd = "~"
end end
local function get_os() local function get_os()
local target = wezterm.target_triple local target = wezterm.target_triple
if string.find(target, "linux") then if string.find(target, "linux") then
return "linux" return "linux"
elseif string.find(target, "darwin") then elseif string.find(target, "darwin") then
return "macos" return "macos"
else else
return "windows" return "windows"
end end
end end
if get_os() == "windows" then if get_os() == "windows" then
default_prog = { 'wsl.exe', '~', '-d', 'Ubuntu-20.04' } default_prog = { "wsl.exe", "~", "-d", "Ubuntu-20.04" }
default_domain = 'WSL:Ubuntu-20.04' default_domain = "WSL:Ubuntu-20.04"
end end
-- Superscript/Subscript -- Superscript/Subscript
local function numberStyle(number, script) local function numberStyle(number, script)
local scripts = { local scripts = {
superscript = { superscript = {
"", "",
"¹", "¹",
"²", "²",
"³", "³",
"", "",
"", "",
"", "",
"", "",
"", "",
"", "",
}, },
subscript = { subscript = {
"", "",
"", "",
"", "",
"", "",
"", "",
"", "",
"", "",
"", "",
"", "",
"", "",
}, },
} }
local numbers = scripts[script] local numbers = scripts[script]
local number_string = tostring(number) local number_string = tostring(number)
local result = "" local result = ""
for i = 1, #number_string do for i = 1, #number_string do
local char = number_string:sub(i, i) local char = number_string:sub(i, i)
local num = tonumber(char) local num = tonumber(char)
if num then if num then
result = result .. numbers[num + 1] result = result .. numbers[num + 1]
else else
result = result .. char result = result .. char
end
end end
end return result
return result
end end
-- Custom Tab Bar -- Custom Tab Bar
wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_width) wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_width)
local RIGHT_DIVIDER = utf8.char(0xe0bc) local RIGHT_DIVIDER = utf8.char(0xe0bc)
local colours = config.resolved_palette.tab_bar local colours = config.resolved_palette.tab_bar
local active_tab_index = 0 local active_tab_index = 0
for _, t in ipairs(tabs) do for _, t in ipairs(tabs) do
if t.is_active == true then if t.is_active == true then
active_tab_index = t.tab_index active_tab_index = t.tab_index
end
end end
end
local active_bg = colours.active_tab.bg_color
local active_bg = colours.active_tab.bg_color local active_fg = colours.active_tab.fg_color
local active_fg = colours.active_tab.fg_color local inactive_bg = colours.inactive_tab.bg_color
local inactive_bg = colours.inactive_tab.bg_color local inactive_fg = colours.inactive_tab.fg_color
local inactive_fg = colours.inactive_tab.fg_color local new_tab_bg = colours.new_tab.bg_color
local new_tab_bg = colours.new_tab.bg_color
local s_bg, s_fg, e_bg, e_fg
local s_bg, s_fg, e_bg, e_fg
-- the last tab
-- the last tab if tab.tab_index == #tabs - 1 then
if tab.tab_index == #tabs - 1 then if tab.is_active then
if tab.is_active then s_bg = active_bg
s_bg = active_bg s_fg = active_fg
s_fg = active_fg e_bg = new_tab_bg
e_bg = new_tab_bg e_fg = active_bg
e_fg = active_bg else
s_bg = inactive_bg
s_fg = inactive_fg
e_bg = new_tab_bg
e_fg = inactive_bg
end
elseif tab.tab_index == active_tab_index - 1 then
s_bg = inactive_bg
s_fg = inactive_fg
e_bg = active_bg
e_fg = inactive_bg
elseif tab.is_active then
s_bg = active_bg
s_fg = active_fg
e_bg = inactive_bg
e_fg = active_bg
else else
s_bg = inactive_bg s_bg = inactive_bg
s_fg = inactive_fg s_fg = inactive_fg
e_bg = new_tab_bg e_bg = inactive_bg
e_fg = inactive_bg e_fg = inactive_bg
end end
elseif tab.tab_index == active_tab_index - 1 then
s_bg = inactive_bg local muxpanes = wezterm.mux.get_tab(tab.tab_id):panes()
s_fg = inactive_fg local count = #muxpanes == 1 and "" or #muxpanes
e_bg = active_bg
e_fg = inactive_bg return {
elseif tab.is_active then { Background = { Color = s_bg } },
s_bg = active_bg { Foreground = { Color = s_fg } },
s_fg = active_fg {
e_bg = inactive_bg Text = " "
e_fg = active_bg .. tab.tab_index + 1
else .. ": "
s_bg = inactive_bg .. tab.active_pane.title
s_fg = inactive_fg .. numberStyle(count, "superscript")
e_bg = inactive_bg .. " ",
e_fg = inactive_bg },
end { Background = { Color = e_bg } },
{ Foreground = { Color = e_fg } },
local muxpanes = wezterm.mux.get_tab(tab.tab_id):panes() { Text = RIGHT_DIVIDER },
local count = #muxpanes == 1 and "" or #muxpanes }
return {
{ Background = { Color = s_bg } },
{ Foreground = { Color = s_fg } },
{ Text = " " .. tab.tab_index + 1 .. ": " .. tab.active_pane.title .. numberStyle(count, "superscript") .. " " },
{ Background = { Color = e_bg } },
{ Foreground = { Color = e_fg } },
{ Text = RIGHT_DIVIDER },
}
end) end)
return { return {
color_scheme = "Catppuccin Mocha", color_scheme = "Catppuccin Mocha",
font = wezterm.font_with_fallback { "VictorMono Nerd Font" }, font = wezterm.font_with_fallback({ "VictorMono Nerd Font" }),
font_size = 14, font_size = 14,
background = { { background = {
source = { File = "/home/hammy/Pictures/astronaut.png", }, {
hsb = { brightness = 0.15, hue = 1.0, saturation = 0.1, }, source = { File = "Pictures/astronaut.png" },
} }, hsb = { brightness = 0.15, hue = 1.0, saturation = 0.1 },
},
default_domain = default_domain, },
wsl_domains = wsl_domains,
default_prog = default_prog, default_domain = default_domain,
wsl_domains = wsl_domains,
window_padding = { top = 0, bottom = 0, left = 0, right = 0 }, default_prog = default_prog,
adjust_window_size_when_changing_font_size = false,
window_decorations = "RESIZE", window_padding = { top = 0, bottom = 0, left = 0, right = 0 },
window_close_confirmation = 'NeverPrompt', adjust_window_size_when_changing_font_size = false,
window_decorations = "RESIZE",
use_fancy_tab_bar = false, window_close_confirmation = "NeverPrompt",
tab_bar_at_bottom = true,
hide_tab_bar_if_only_one_tab = true, use_fancy_tab_bar = false,
tab_max_width = 32, tab_bar_at_bottom = true,
hide_tab_bar_if_only_one_tab = true,
exit_behavior = "CloseOnCleanExit", tab_max_width = 32,
clean_exit_codes = { 130 }, scrollback_lines = 1000000,
audible_bell = "Disabled",
disable_default_key_bindings = false, exit_behavior = "CloseOnCleanExit",
clean_exit_codes = { 130 },
keys = { audible_bell = "Disabled",
-- Fullscreen disable_default_key_bindings = false,
{ key = 'F11', action = wezterm.action.ToggleFullScreen, },
-- Zoom keys = {
{ key = 'z', mods = 'ALT|SHIFT', action = wezterm.action.TogglePaneZoomState, }, -- Fullscreen
-- Copy / Paste { key = "F11", action = wezterm.action.ToggleFullScreen },
{ key = 'C', mods = 'CTRL', action = wezterm.action.Copy }, -- Zoom
{ key = 'V', mods = 'CTRL', action = act.PasteFrom 'Clipboard' }, { key = "z", mods = "ALT|SHIFT", action = wezterm.action.TogglePaneZoomState },
-- Copy / Paste
-- Open Pane { key = "C", mods = "CTRL", action = wezterm.action.Copy },
{ key = "n", mods = "ALT|SHIFT", action = act({ SplitHorizontal = { domain = "CurrentPaneDomain" } }), }, { key = "V", mods = "CTRL", action = act.PasteFrom("Clipboard") },
{ key = "m", mods = "ALT|SHIFT", action = act({ SplitVertical = { domain = "CurrentPaneDomain" } }), },
-- Navigating Panes -- Open Pane
{ key = 'h', mods = 'ALT|SHIFT', action = act.ActivatePaneDirection 'Left', }, -- https://github.com/wez/wezterm/discussions/2426
{ key = 'l', mods = 'ALT|SHIFT', action = act.ActivatePaneDirection 'Right', }, -- https://github.com/neovim/neovim/issues/2252
{ key = 'k', mods = 'ALT|SHIFT', action = act.ActivatePaneDirection 'Up', }, {
{ key = 'j', mods = 'ALT|SHIFT', action = act.ActivatePaneDirection 'Down', }, key = "n",
-- Close Pane mods = "ALT|SHIFT",
{ key = 'c', mods = 'ALT|SHIFT', action = wezterm.action.CloseCurrentPane { confirm = false }, }, action = wezterm.action_callback(function(window, pane)
-- Swap Panes if pane:get_title() == "nvim" then
{ key = 'i', mods = 'ALT|SHIFT', action = act.PaneSelect { alphabet = 'asdfghjkl;', mode = 'Activate' } }, window:perform_action(act.SendKey({ key = "n", mods = "ALT|SHIFT" }), pane)
{ key = 's', mods = 'ALT|SHIFT', action = act.PaneSelect { alphabet = 'asdfghjkl;', mode = 'SwapWithActive' } }, else
-- Resize Panes window:perform_action(act.SplitPane({ direction = "Right", size = { Percent = 50 } }), pane)
{ key = "LeftArrow", mods = "ALT|SHIFT", action = act({ AdjustPaneSize = { "Left", 5 } }) }, end
{ key = "DownArrow", mods = "ALT|SHIFT", action = act({ AdjustPaneSize = { "Down", 5 } }) }, end),
{ key = "UpArrow", mods = "ALT|SHIFT", action = act({ AdjustPaneSize = { "Up", 5 } }) }, },
{ key = "RightArrow", mods = "ALT|SHIFT", action = act({ AdjustPaneSize = { "Right", 5 } }) }, {
key = "m",
-- New Tab mods = "ALT|SHIFT",
{ key = "n", mods = "CTRL|SHIFT", action = act({ SpawnTab = "CurrentPaneDomain" }) }, action = wezterm.action_callback(function(window, pane)
-- Swap Tabs if pane:get_title() == "nvim" then
{ key = 'h', mods = 'CTRL|SHIFT', action = act.ActivateTabRelative(-1) }, window:perform_action(act.SendKey({ key = "m", mods = "ALT|SHIFT" }), pane)
{ key = 'l', mods = 'CTRL|SHIFT', action = act.ActivateTabRelative(1) }, else
window:perform_action(act.SplitPane({ direction = "Down", size = { Percent = 50 } }), pane)
-- Open Links end
{ end),
key = "o",
mods = "ALT|SHIFT",
action = wezterm.action.QuickSelectArgs({
label = "open url",
patterns = {
"https?://\\S+",
}, },
action = wezterm.action_callback(function(window, pane)
local url = window:get_selection_text_for_pane(pane) -- Navigating Panes
wezterm.open_with(url) { key = "h", mods = "ALT|SHIFT", action = act.ActivatePaneDirection("Left") },
end), { key = "l", mods = "ALT|SHIFT", action = act.ActivatePaneDirection("Right") },
}), { key = "k", mods = "ALT|SHIFT", action = act.ActivatePaneDirection("Up") },
{ key = "j", mods = "ALT|SHIFT", action = act.ActivatePaneDirection("Down") },
-- Close Pane
{ key = "c", mods = "ALT|SHIFT", action = wezterm.action.CloseCurrentPane({ confirm = false }) },
-- Swap Panes
{ key = "i", mods = "ALT|SHIFT", action = act.PaneSelect({ alphabet = "asdfghjkl;", mode = "Activate" }) },
{
key = "s",
mods = "ALT|SHIFT",
action = act.PaneSelect({ alphabet = "asdfghjkl;", mode = "SwapWithActive" }),
},
-- Resize Panes
{ key = "LeftArrow", mods = "ALT|SHIFT", action = act({ AdjustPaneSize = { "Left", 5 } }) },
{ key = "DownArrow", mods = "ALT|SHIFT", action = act({ AdjustPaneSize = { "Down", 5 } }) },
{ key = "UpArrow", mods = "ALT|SHIFT", action = act({ AdjustPaneSize = { "Up", 5 } }) },
{ key = "RightArrow", mods = "ALT|SHIFT", action = act({ AdjustPaneSize = { "Right", 5 } }) },
-- New Tab
{ key = "n", mods = "CTRL|SHIFT", action = act({ SpawnTab = "CurrentPaneDomain" }) },
-- Swap Tabs
{ key = "h", mods = "CTRL|SHIFT", action = act.ActivateTabRelative(-1) },
{ key = "l", mods = "CTRL|SHIFT", action = act.ActivateTabRelative(1) },
-- Open Links
{
key = "o",
mods = "ALT|SHIFT",
action = wezterm.action.QuickSelectArgs({
label = "open url",
patterns = {
"https?://\\S+",
},
action = wezterm.action_callback(function(window, pane)
local url = window:get_selection_text_for_pane(pane)
wezterm.open_with(url)
end),
}),
},
-- ScrollBack To Prompt
{ key = "UpArrow", mods = "CTRL|SHIFT", action = act.ScrollToPrompt(-1) },
{ key = "DownArrow", mods = "CTRL|SHIFT", action = act.ScrollToPrompt(1) },
}, },
}
} }

Loading…
Cancel
Save