From b9779d4df45ec7a9a9e37cb5c61b9766473f511b Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Sun, 26 May 2024 22:24:57 +0200 Subject: [PATCH] Fresh take on using wezterm without tmux for remote dev --- .config/fish/conf.d/aliases.fish | 3 +- .config/wezterm/wezterm.lua | 324 +++++++++++------- .../wezterm-dev-secondary.desktop | 10 + .local/share/applications/wezterm-dev.desktop | 10 + .../wezterm-dln-dev-secondary.desktop | 10 - .../applications/wezterm-dln-dev.desktop | 10 - .ssh/config | 1 + bin/wezterm-edit-helper | 50 +++ 8 files changed, 280 insertions(+), 138 deletions(-) create mode 100644 .local/share/applications/wezterm-dev-secondary.desktop create mode 100644 .local/share/applications/wezterm-dev.desktop delete mode 100644 .local/share/applications/wezterm-dln-dev-secondary.desktop delete mode 100644 .local/share/applications/wezterm-dln-dev.desktop create mode 100755 bin/wezterm-edit-helper diff --git a/.config/fish/conf.d/aliases.fish b/.config/fish/conf.d/aliases.fish index 3349f69..d2d3ddb 100644 --- a/.config/fish/conf.d/aliases.fish +++ b/.config/fish/conf.d/aliases.fish @@ -1,5 +1,4 @@ -alias e='tmux-edit-helper' -alias eh='tmux-edit-history' +alias e='wezterm-edit-helper' alias dotgit='git --work-tree $HOME --git-dir $HOME/.dot_git' alias git='git-branchless wrap --' alias l='bat --wrap=never --pager="less -S"' diff --git a/.config/wezterm/wezterm.lua b/.config/wezterm/wezterm.lua index 3a53a9d..1c76512 100644 --- a/.config/wezterm/wezterm.lua +++ b/.config/wezterm/wezterm.lua @@ -2,10 +2,89 @@ local wezterm = require("wezterm") local mux = wezterm.mux local act = wezterm.action -local dev_host = "dln-dev" -local spawn_dev_nvim = { "ssh", dev_host, "nvim", "--listen", os.getenv("XDG_RUNTIME_DIR") .. "/nvim-persistent.sock" } +local config = {} -wezterm.add_to_config_reload_watch_list(os.getenv("HOME") .. "/.config/shelman-theme/current/wezterm") +-- ------------------------------------------------------------------------------------ +-- Workspace behavior + +-- local nvim_args = { "nvim", "--listen", "$XDG_RUNTIME_DIR" .. "/nvim-persistent.sock" } +local nvim_args = { "nvim", "--listen", os.getenv("XDG_RUNTIME_DIR") .. "/nvim-persistent.sock" } + +config.exec_domains = { + wezterm.exec_domain("dev", function(cmd) + local wrapped = { "/usr/bin/ssh", "-t", "dev" } + for _, arg in ipairs(cmd.args or { os.getenv("SHELL") }) do + table.insert(wrapped, arg) + end + cmd.args = wrapped + return cmd + end), +} + +local function activate_nvim(window, pane) + wezterm.log_info("nvim") + for _, t in ipairs(window:mux_window():tabs_with_info()) do + for _, p in ipairs(t.tab:panes()) do + if p:get_title() == "nvim" or t.tab:get_title() == "nvim" then + window:perform_action( + act.Multiple({ + act.ActivateTab(t.index), + act.MoveTab(0), + }), + pane + ) + return + end + end + end + + local nvim_tab, nvim_pane, _ = window:mux_window():spawn_tab({ args = nvim_args }) + window:perform_action(act.MoveTab(0), nvim_pane) + nvim_tab:set_title("nvim") +end + +local function activate_tab(title, index) + return function(window, pane) + wezterm.log_info(title) + for _, t in ipairs(window:mux_window():tabs_with_info()) do + if t.tab:get_title() == title then + window:perform_action( + act.Multiple({ + act.ActivateTab(t.index), + act.MoveTab(index), + }), + pane + ) + return + end + end + local tab, _, _ = window:mux_window():spawn_tab({ + cwd = "~", + }) + tab:set_title(title) + window:perform_action(act.MoveTab(index), pane) + end +end + +wezterm.on("activate-nvim", activate_nvim) +wezterm.on("tab-2", activate_tab("t2", 1)) +wezterm.on("tab-3", activate_tab("t3", 2)) +wezterm.on("tab-4", activate_tab("t4", 3)) +wezterm.on("tab-5", activate_tab("t5", 4)) +wezterm.on("tab-6", activate_tab("t6", 5)) +wezterm.on("tab-7", activate_tab("t7", 6)) +wezterm.on("tab-8", activate_tab("t8", 7)) +wezterm.on("tab-9", activate_tab("t9", 8)) +wezterm.on("tab-10", activate_tab("t10", 9)) + +wezterm.on("user-var-changed", function(window, pane, name, _) + if name == "nvim_activate" then + activate_nvim(window, pane) + end +end) + +-- ------------------------------------------------------------------------------------ +-- Appearance local function scheme_for_appearance(appearance) if appearance:find("Dark") then @@ -24,124 +103,137 @@ local function font_for_appearance(appearance) else return wezterm.font({ family = "IosevkaShelman Nerd Font", - -- weight = "Regular", --weight = "Regular", }) end end +config.color_scheme = scheme_for_appearance(wezterm.gui.get_appearance()) -return { - color_scheme = scheme_for_appearance(wezterm.gui.get_appearance()), - font = font_for_appearance(wezterm.gui.get_appearance()), - - font_rules = { - { - italic = true, - intensity = "Bold", - reverse = false, - font = wezterm.font("IosevkaShelman Nerd Font", { weight = "ExtraLight", italic = true }), - -- font = wezterm.font("Iosevka Term Curly Slab", { weight = "Thin", italic = true }), - - -- font = wezterm.font({ -- Normal text - -- -- family = "Monaspace Radon", - -- family = "Monaspace Argon", - -- harfbuzz_features = { - -- "calt", - -- "liga", - -- "dlig", - -- "ss01", - -- "ss02", - -- "ss03", - -- "ss04", - -- "ss05", - -- "ss06", - -- "ss07", - -- "ss08", - -- }, - -- weight = "Regular", - -- -- weight = "ExtraLight", - -- stretch = "Normal", - -- style = "Normal", - -- }), - }, - - { - italic = true, - intensity = "Normal", - reverse = false, - font = wezterm.font("IosevkaShelman Nerd Font", { weight = "Light", italic = true }), - }, +-- ------------------------------------------------------------------------------------ +-- Fonts +config.font = font_for_appearance(wezterm.gui.get_appearance()) +config.font_rules = { + { + italic = true, + intensity = "Bold", + reverse = false, + font = wezterm.font("IosevkaShelman Nerd Font", { weight = "ExtraLight", italic = true }), + -- font = wezterm.font("Iosevka Term Curly Slab", { weight = "Thin", italic = true }), }, - -- front_end = "WebGpu", - -- webgpu_power_preference = "HighPerformance", - front_end = "OpenGL", - warn_about_missing_glyphs = false, - bold_brightens_ansi_colors = false, - -- allow_square_glyphs_to_overflow_width = "Never", - font_size = 16, - command_palette_font_size = 13.5, - line_height = 1.0, - initial_cols = 132, - initial_rows = 45, - use_resize_increments = true, - adjust_window_size_when_changing_font_size = false, - window_decorations = "RESIZE", - window_padding = { - left = 6, - right = 6, - top = 0, - bottom = 0, - }, - unicode_version = 14, - default_cursor_style = "SteadyBlock", - cursor_thickness = "6px", - cursor_blink_rate = 700, - hide_mouse_cursor_when_typing = false, - underline_position = -9, - underline_thickness = 1, - enable_wayland = true, - enable_tab_bar = false, - tab_bar_at_bottom = true, - use_fancy_tab_bar = false, - show_tab_index_in_tab_bar = true, - enable_scroll_bar = false, - scrollback_lines = 5000, - alternate_buffer_wheel_scroll_speed = 1, - check_for_updates = false, - status_update_interval = 100, - audible_bell = "Disabled", - term = "wezterm", - disable_default_key_bindings = true, - keys = { - { key = "c", mods = "ALT|SHIFT", action = act.CopyTo("ClipboardAndPrimarySelection") }, - { key = "v", mods = "ALT|SHIFT", action = act.PasteFrom("Clipboard") }, - { key = "0", mods = "CTRL", action = "ResetFontSize" }, - { key = "-", mods = "CTRL", action = "DecreaseFontSize" }, - { key = "=", mods = "CTRL", action = "IncreaseFontSize" }, - { key = "Enter", mods = "ALT", action = "ToggleFullScreen" }, - { key = "UpArrow", mods = "SHIFT", action = act.ScrollByLine(-1) }, - { key = "DownArrow", mods = "SHIFT", action = act.ScrollByLine(1) }, - { key = "PageUp", mods = "SHIFT", action = act.ScrollByPage(-0.5) }, - { key = "PageDown", mods = "SHIFT", action = act.ScrollByPage(0.5) }, - }, - mouse_bindings = { - { - event = { Down = { streak = 1, button = { WheelUp = 1 } } }, - mods = "SHIFT", - action = act.ScrollByLine(-1), - }, - { - event = { Down = { streak = 1, button = { WheelDown = 1 } } }, - mods = "SHIFT", - action = act.ScrollByLine(1), - }, - { - event = { Down = { streak = 1, button = { WheelUp = 1 } } }, - action = act.ScrollByPage(-0.25), - }, - { - event = { Down = { streak = 1, button = { WheelDown = 1 } } }, - action = act.ScrollByPage(0.25), - }, + + { + italic = true, + intensity = "Normal", + reverse = false, + font = wezterm.font("IosevkaShelman Nerd Font", { weight = "Light", italic = true }), }, } +-- config.dpi = 192 +config.font_size = 15 +config.line_height = 1.0 +config.warn_about_missing_glyphs = false +config.bold_brightens_ansi_colors = false +config.unicode_version = 14 + +-- Config +config.enable_wayland = true +config.front_end = "WebGpu" +config.webgpu_power_preference = "HighPerformance" +config.term = "wezterm" +config.check_for_updates = false + +-- UI +config.command_palette_font_size = 13.5 +config.initial_cols = 132 +config.initial_rows = 45 +config.status_update_interval = 100 +config.audible_bell = "Disabled" +config.use_resize_increments = true +config.adjust_window_size_when_changing_font_size = false +config.window_decorations = "RESIZE" +config.window_frame = { + border_left_width = "4px", + border_right_width = "4px", + border_bottom_height = "4px", + border_top_height = "4px", + border_left_color = "#000000", + border_right_color = "#000000", + border_bottom_color = "#000000", + border_top_color = "#000000", +} +config.window_padding = { + left = 0, + right = 0, + top = 0, + bottom = 0, +} + +-- Tabs +config.enable_tab_bar = false +config.tab_bar_at_bottom = true +config.use_fancy_tab_bar = false +config.show_tab_index_in_tab_bar = true + +-- Cursor +config.default_cursor_style = "SteadyBlock" +config.cursor_thickness = "6px" +config.cursor_blink_rate = 700 +config.hide_mouse_cursor_when_typing = false +config.underline_position = -9 +config.underline_thickness = 1 + +-- Scrolling +config.enable_scroll_bar = false +config.scrollback_lines = 5000 +config.alternate_buffer_wheel_scroll_speed = 1 + +-- Keys +config.disable_default_key_bindings = true +config.keys = { + { key = "c", mods = "ALT|SHIFT", action = act.CopyTo("ClipboardAndPrimarySelection") }, + { key = "v", mods = "ALT|SHIFT", action = act.PasteFrom("Clipboard") }, + { key = "0", mods = "CTRL", action = "ResetFontSize" }, + { key = "-", mods = "CTRL", action = "DecreaseFontSize" }, + { key = "=", mods = "CTRL", action = "IncreaseFontSize" }, + { key = "UpArrow", mods = "SHIFT", action = act.ScrollByLine(-1) }, + { key = "DownArrow", mods = "SHIFT", action = act.ScrollByLine(1) }, + { key = "PageUp", mods = "SHIFT", action = act.ScrollByPage(-0.5) }, + { key = "PageDown", mods = "SHIFT", action = act.ScrollByPage(0.5) }, + { key = "r", mods = "ALT", action = act.ReloadConfiguration }, + { key = "o", mods = "ALT", action = act.ActivateCommandPalette }, + { key = "Backspace", mods = "ALT", action = act.SwitchWorkspaceRelative(1) }, + { key = "1", mods = "ALT", action = act.EmitEvent("activate-nvim") }, + { key = "2", mods = "ALT", action = act.EmitEvent("tab-2") }, + { key = "3", mods = "ALT", action = act.EmitEvent("tab-3") }, + { key = "4", mods = "ALT", action = act.EmitEvent("tab-4") }, + { key = "5", mods = "ALT", action = act.EmitEvent("tab-5") }, + { key = "6", mods = "ALT", action = act.EmitEvent("tab-6") }, + { key = "7", mods = "ALT", action = act.EmitEvent("tab-7") }, + { key = "8", mods = "ALT", action = act.EmitEvent("tab-8") }, + { key = "9", mods = "ALT", action = act.EmitEvent("tab-9") }, + { key = "0", mods = "ALT", action = act.EmitEvent("tab-10") }, +} + +-- Mouse +config.mouse_bindings = { + { + event = { Down = { streak = 1, button = { WheelUp = 1 } } }, + mods = "SHIFT", + action = act.ScrollByLine(-1), + }, + { + event = { Down = { streak = 1, button = { WheelDown = 1 } } }, + mods = "SHIFT", + action = act.ScrollByLine(1), + }, + { + event = { Down = { streak = 1, button = { WheelUp = 1 } } }, + action = act.ScrollByPage(-0.25), + }, + { + event = { Down = { streak = 1, button = { WheelDown = 1 } } }, + action = act.ScrollByPage(0.25), + }, +} + +return config diff --git a/.local/share/applications/wezterm-dev-secondary.desktop b/.local/share/applications/wezterm-dev-secondary.desktop new file mode 100644 index 0000000..9c1905b --- /dev/null +++ b/.local/share/applications/wezterm-dev-secondary.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=wezterm-dev-secondary +GenericName=wezterm-dev-secondary +StartupWMClass=org.wezfurlong.wezterm-dev-secondary +Type=Application +TryExec=/usr/bin/wezterm +Icon=org.wezfurlong.wezterm +Terminal=false +Categories=System;TerminalEmulator; +Exec=/usr/bin/wezterm --config 'default_prog={"/usr/bin/fish"}' start --class=org.wezfurlong.wezterm-dev-secondary --domain=dev diff --git a/.local/share/applications/wezterm-dev.desktop b/.local/share/applications/wezterm-dev.desktop new file mode 100644 index 0000000..9cff6ce --- /dev/null +++ b/.local/share/applications/wezterm-dev.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=wezterm-dev +GenericName=wezterm-dev +StartupWMClass=org.wezfurlong.wezterm-dev +Type=Application +TryExec=/usr/bin/wezterm +Icon=org.wezfurlong.wezterm +Terminal=false +Categories=System;TerminalEmulator; +Exec=/usr/bin/wezterm --config 'default_prog={"/usr/bin/fish"}' start --class=org.wezfurlong.wezterm-dev --domain=dev diff --git a/.local/share/applications/wezterm-dln-dev-secondary.desktop b/.local/share/applications/wezterm-dln-dev-secondary.desktop deleted file mode 100644 index 862fa5a..0000000 --- a/.local/share/applications/wezterm-dln-dev-secondary.desktop +++ /dev/null @@ -1,10 +0,0 @@ -[Desktop Entry] -Name=wezterm-dln-dev-secondary -GenericName=wezterm-dln-dev-secondary -StartupWMClass=org.wezfurlong.wezterm-secondary -Type=Application -TryExec=/usr/bin/wezterm -Icon=org.wezfurlong.wezterm -Terminal=false -Categories=System;TerminalEmulator; -Exec=/usr/bin/wezterm --config 'default_prog={"ssh", "-tq", "dln-dev", "--", "tmux", "-u", "new", "-As1", "-t0"}' start --class=org.wezfurlong.wezterm-secondary diff --git a/.local/share/applications/wezterm-dln-dev.desktop b/.local/share/applications/wezterm-dln-dev.desktop deleted file mode 100644 index 277cb3a..0000000 --- a/.local/share/applications/wezterm-dln-dev.desktop +++ /dev/null @@ -1,10 +0,0 @@ -[Desktop Entry] -Name=wezterm-dln-dev -GenericName=wezterm-dln-dev -StartupWMClass=org.wezfurlong.wezterm -Type=Application -TryExec=/usr/bin/wezterm -Icon=org.wezfurlong.wezterm -Terminal=false -Categories=System;TerminalEmulator; -Exec=/usr/bin/wezterm --config 'default_prog={"ssh", "-tq", "dln-dev", "--", "tmux", "-u", "new", "-As0", "-t0"}' start --class=wezterm-dln-dev diff --git a/.ssh/config b/.ssh/config index be346ee..8914ace 100644 --- a/.ssh/config +++ b/.ssh/config @@ -12,6 +12,7 @@ Include ~/.ssh/private_config Host 10.1.100.16 Host dln-dev +Host dev Hostname 10.1.100.16 #Hostname aarn.shelman.io #Port 2022 diff --git a/bin/wezterm-edit-helper b/bin/wezterm-edit-helper new file mode 100755 index 0000000..c0a9421 --- /dev/null +++ b/bin/wezterm-edit-helper @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +set -fe -o pipefail + +eval "$(direnv export bash 2>/dev/null)" + +PATH="$HOME/bin:$PATH" + +if [ -n "$1" ]; then + _file=$(readlink -f "$@") +else + FZF=${FZF:-"fzf-tmux -p 90%,50% -y 0 --layout=reverse"} + _root=$(git rev-parse --show-toplevel 2>/dev/null || jj workspace root 2>/dev/null || pwd) + _store=$(echo "$_root" | sha1sum | cut -d ' ' -f 1) + _file=$( ( (fre --store_name "$_store" --sorted | xargs -n 100 ls -d 2>/dev/null || true) && fd --type f --hidden --follow --exclude .git --exclude .jj --ignore-file "${_root}/.gitignore" . "$_root") | cat -n | sort -k2 -k1n | uniq -f1 | sort -nk1,1 | cut -f2- | sed -e "s#^${_root}/##" | $FZF --no-sort) + _file="${_root}/${_file}" + fre --store_name "$_store" --add "$_file" +fi + +fre --store_name "edit-history" --add "$_file" + +_nvim_socket="$XDG_RUNTIME_DIR/nvim-persistent.sock" + +nvim --server "$_nvim_socket" --remote "$_file" + +function _nvim_setenv() { + nvim --server "$_nvim_socket" --remote-expr "execute(\"let \$${1} = \\\"${2}\\\"\")" 2>&1 >/dev/null +} + +_nvim_setenv AR "$AR" +_nvim_setenv AS "$AS" +_nvim_setenv BUILD_COMMAND "$BUILD_COMMAND" +_nvim_setenv CC "$CC" +_nvim_setenv CXX "$CXX" +_nvim_setenv GOFLAGS "$GOFLAGS" +_nvim_setenv GOPACKAGESDRIVER "$GOPACKAGESDRIVER" +_nvim_setenv LC_ALL "$LC_ALL" +_nvim_setenv LD "$LD" +_nvim_setenv NM "$NM" +_nvim_setenv NM "$NM" +_nvim_setenv OBJCOPY "$OBJCOPY" +_nvim_setenv OBJDUMP "$OBJDUMP" +_nvim_setenv PATH "$PATH" +_nvim_setenv RANLIB "$RANLIB" +_nvim_setenv READELF "$READELF" +_nvim_setenv RUST_SRC_PATH "$RUST_SRC_PATH" +_nvim_setenv SIZE "$SIZE" +_nvim_setenv STRIP "$STRIP" + +# Wezterm: switch tab to nvim +printf "\033]1337;SetUserVar=%s=%s\007" nvim_activate $(date +%s | base64)