From d9db12c4a5fc1a50664e46f77fc4588d4d9866fc Mon Sep 17 00:00:00 2001 From: Emma Thorpe Date: Mon, 24 Aug 2026 13:26:21 +0100 Subject: [PATCH] fix(tmux): stop clip.exe mangling non-ASCII in the WSL clipboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tmux-yank autodetects WSL and pipes the selection to clip.exe, which decodes its stdin as the console OEM codepage rather than UTF-8. Copying an em dash out of a pane put "ΓÇö" on the Windows clipboard; the same applies to every non-ASCII character. Override the copy command to route through tmux's own buffer. With set-clipboard on, that emits OSC 52 and the terminal receives UTF-8 directly, with no Windows-side helper in the path. Windows Terminal honours OSC 52; verified against the running client. Guarded on /proc/version so only WSL is affected. iTerm2 does not accept OSC 52 by default, so the Darwin hosts keep pbcopy. Set in the plugin's extraConfig rather than the shared block because yank.tmux bakes the copy command into its key bindings at load time, and home-manager emits plugin extraConfig before the run-shell. --- home/shell.nix | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/home/shell.nix b/home/shell.nix index 9fab8b0..4435b92 100644 --- a/home/shell.nix +++ b/home/shell.nix @@ -287,7 +287,22 @@ in plugins = with pkgs.tmuxPlugins; [ sensible vim-tmux-navigator # Ctrl-h/j/k/l across vim splits and tmux panes - yank + { + # On WSL, tmux-yank pipes the selection to clip.exe, which decodes its + # stdin as the OEM codepage instead of UTF-8 -- an em dash reaches the + # Windows clipboard as three characters. Route through tmux's own + # buffer instead: with set-clipboard on, tmux emits OSC 52 and the + # terminal takes the text as UTF-8. Windows Terminal honours OSC 52; + # iTerm2 does not by default, hence the runtime guard rather than + # overriding pbcopy/xsel on every host. yank.tmux bakes the command + # into its key bindings when it loads, so this must be set first, which + # is what plugin extraConfig gives us. + plugin = yank; + extraConfig = '' + if-shell 'grep -qi microsoft /proc/version 2>/dev/null' \ + "set -g @override_copy_command 'tmux load-buffer -w -'" + ''; + } extrakto # prefix+Tab: fzf-grab paths/URLs/text from the pane into the prompt { # Catppuccin Mocha statusline (v2 API: flavour + window options must be