wezterm icon indicating copy to clipboard operation
wezterm copied to clipboard

Paste not working when `wezterm connect unix_domain` from local WSL2

Open Ma-Jian1 opened this issue 1 year ago • 6 comments

What Operating System(s) are you seeing this problem on?

Windows

Which Wayland compositor or X11 Window manager(s) are you using?

I'm also use wslg on wsl2, seem it's using wayland( don't known how to check)

WezTerm version

20230408-112425-69ae8472

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

No, and I'll explain why below

Describe the bug

I used WSL2 on Windows 11, so I put wezterm config on /mnt/c/Users/xxx/.config/wezterm for windows gui and /home/dev/.config/wezterm for wsl2. and config the default_domain to WSL, so I can launch WSL shell directly.

  if wezterm.target_triple == "x86_64-pc-windows-msvc" then
    config.default_domain = "WSL:Ubuntu"
  end

Because wezterm ssh SSHMUX:xxx seems not support ProxyCommand, I have added unix_domains from ~/.ssh/config in my wezterm config file

  local unix_domains = {}
  for name, _ in pairs(wezterm.enumerate_ssh_hosts()) do
    table.insert(unix_domains, {
      name = name,
      -- should install wezterm binary in system path(eg. /usr/bin/wezterm)
      proxy_command = { "ssh", "-T", "-A", name, "wezterm", "cli", "proxy" },
    })
  end
  config.unix_domains = unix_domains

and then wezterm connect xxx from windows gui (Term 1) succeed. and a new gui from wls2 was created(Term2) which running the remote shell. Right mouse click or "LEADER-v" to paste from clipboard (which is workable on local) not workable on Term2. I can confirm that copy is workable. (I can copy from "Term 2", and paste to other place include Term 1. but I can't paster to Term 2)

my mouse and key config, it's same on local (include windows and wsl) and remote

local wezterm = require("wezterm")
local act = wezterm.action
local M = {}

function M.setup(config)
  config.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"),
    },
    -- select to copy(not wezterm copy mode), and paste if don't select anything
    {
      event = { Down = { streak = 1, button = "Right" } },
      mods = "NONE",
      action = wezterm.action_callback(function(window, pane)
        local has_selection = window:get_selection_text_for_pane(pane) ~= ""
        if has_selection then
          window:perform_action(act.CopyTo("ClipboardAndPrimarySelection"), pane)
          window:perform_action(act.ClearSelection, pane)
        else
          window:perform_action(act.PasteFrom("Clipboard"), pane)
        end
      end),
    },
    -- CTRL-Click open hyperlinks
    {
      event = { Up = { streak = 1, button = "Left" } },
      mods = "CTRL",
      action = act.OpenLinkAtMouseCursor,
    },
    -- Disable the 'Down' event of CTRL-Click to avoid weird program behaviors
    -- https://wezfurlong.org/wezterm/config/mouse.html?highlight=Ctrl-click#gotcha-on-binding-an-up-event-only
    {
      event = { Down = { streak = 1, button = "Left" } },
      mods = "CTRL",
      action = act.Nop,
    },
    -- Grap the semantic zone when triple click
    {
      event = { Down = { streak = 3, button = "Left" } },
      mode = "NONE",
      action = act.SelectTextAtMouseCursor("SemanticZone"),
    },
  }
end

return M
local wezterm = require("wezterm")
local act = wezterm.action
local M = {}

function M.setup(config)
  config.disable_default_key_bindings = true
  config.use_dead_keys = false -- Allow using ^ with single key press.
  config.leader = { key = "a", mods = "CTRL" }
  config.keys = {
    -- Send "CTRL-A" to the terminal when pressing CTRL-A, CTRL-A
    { key = "a", mods = "LEADER|CTRL", action = act.SendString("\x01") },
    -- workspace
    { key = "l", mods = "SHIFT|ALT", action = act.ShowLauncherArgs({ flags = "FUZZY|WORKSPACES" }) },
    { key = "n", mods = "SHIFT|ALT", action = act.SwitchWorkspaceRelative(1) },
    { key = "p", mods = "SHIFT|ALT", action = act.SwitchWorkspaceRelative(-1) },
    -- window
    { key = "l", mods = "SHIFT|CTRL", action = act.ShowLauncher },
    { key = "Enter", mods = "SHIFT|CTRL", action = act.ToggleFullScreen },
    { key = "p", mods = "SHIFT|CTRL", action = act.ActivateCommandPalette },
    { key = "d", mods = "SHIFT|CTRL", action = act.ShowDebugOverlay },
    { key = "+", mods = "SHIFT|CTRL", action = act.IncreaseFontSize },
    { key = "-", mods = "SHIFT|CTRL", action = act.DecreaseFontSize },
    { key = "=", mods = "CTRL", action = act.ResetFontSize },
    -- tab
    { key = "t", mods = "LEADER", action = act.SpawnTab("CurrentPaneDomain") },
    { key = "q", mods = "LEADER", action = act.CloseCurrentTab({ confirm = true }) },
    { key = "1", mods = "LEADER", action = act.ActivateTab(0) },
    { key = "2", mods = "LEADER", action = act.ActivateTab(1) },
    { key = "3", mods = "LEADER", action = act.ActivateTab(2) },
    { key = "4", mods = "LEADER", action = act.ActivateTab(3) },
    { key = "5", mods = "LEADER", action = act.ActivateTab(4) },
    { key = "6", mods = "LEADER", action = act.ActivateTab(5) },
    { key = "7", mods = "LEADER", action = act.ActivateTab(6) },
    { key = "8", mods = "LEADER", action = act.ActivateTab(7) },
    { key = "9", mods = "LEADER", action = act.ActivateTab(-1) },
    -- pane
    { key = "x", mods = "LEADER", action = act.CloseCurrentPane({ confirm = true }) },
    { key = "z", mods = "LEADER", action = act.TogglePaneZoomState },
    { key = "-", mods = "LEADER", action = act.SplitVertical({ domain = "CurrentPaneDomain" }) },
    { key = "\\", mods = "LEADER", action = act.SplitHorizontal({ domain = "CurrentPaneDomain" }) },
    { key = "f", mods = "LEADER", action = act.Search("CurrentSelectionOrEmptyString") },
    { key = "v", mods = "LEADER", action = act.PasteFrom("Clipboard") },
    { key = "V", mods = "LEADER|SHIFT", action = act.PasteFrom("PrimarySelection") },
    -- KeyTable
    { key = "c", mods = "LEADER", action = act.ActivateCopyMode },
    { key = "phys:Space", mods = "LEADER", action = act.QuickSelect },
    -- LEADER-'r': resize-pane mode until we cancel that mode.
    {
      key = "r",
      mods = "LEADER",
      action = act.ActivateKeyTable({
        name = "resize_pane",
        one_shot = false,
      }),
    },
    -- LEADER-'w': activate-pane mode until we press some other key or until timeout (1000ms)
    {
      key = "w",
      mods = "LEADER",
      action = act.ActivateKeyTable({
        name = "activate_pane",
        timeout_milliseconds = 1000,
      }),
    },
  }
  config.key_tables = {
    -- Defines the keys that are active in our resize-pane mode.
    -- Since we're likely to want to make multiple adjustments,
    -- we made the activation one_shot=false. We therefore need
    -- to define a key assignment for getting out of this mode.
    -- 'resize_pane' here corresponds to the name="resize_pane" in
    -- the key assignments above.
    resize_pane = {
      { key = "LeftArrow", action = act.AdjustPaneSize({ "Left", 1 }) },
      { key = "h", action = act.AdjustPaneSize({ "Left", 1 }) },

      { key = "RightArrow", action = act.AdjustPaneSize({ "Right", 1 }) },
      { key = "l", action = act.AdjustPaneSize({ "Right", 1 }) },

      { key = "UpArrow", action = act.AdjustPaneSize({ "Up", 1 }) },
      { key = "k", action = act.AdjustPaneSize({ "Up", 1 }) },

      { key = "DownArrow", action = act.AdjustPaneSize({ "Down", 1 }) },
      { key = "j", action = act.AdjustPaneSize({ "Down", 1 }) },

      -- Cancel the mode by pressing escape
      { key = "Escape", action = "PopKeyTable" },
    },

    -- Defines the keys that are active in our activate-pane mode.
    -- 'activate_pane' here corresponds to the name="activate_pane" in
    -- the key assignments above.
    activate_pane = {
      { key = "LeftArrow", action = act.ActivatePaneDirection("Left") },
      { key = "h", action = act.ActivatePaneDirection("Left") },

      { key = "RightArrow", action = act.ActivatePaneDirection("Right") },
      { key = "l", action = act.ActivatePaneDirection("Right") },

      { key = "UpArrow", action = act.ActivatePaneDirection("Up") },
      { key = "k", action = act.ActivatePaneDirection("Up") },

      { key = "DownArrow", action = act.ActivatePaneDirection("Down") },
      { key = "j", action = act.ActivatePaneDirection("Down") },
    },
  }
end

return M

To Reproduce

No response

Configuration

https://github.com/ensonmj/dotfiles/tree/master/wezterm/.config/wezterm

Expected Behavior

copy and paste should work like local

Logs

No response

Anything else?

No response

Ma-Jian1 avatar Jul 12 '23 03:07 Ma-Jian1