Useful for copying text from vertically split panes in tmux, when normal "shift + clickdrag" copying spans across the vertical separator, or there are too many rows to fit into the pane. Video explanation of what this does and how it works @ https://www.youtube.com/watch?v=kEIpE2XpDdY
-
In server-side tmux.conf, add:
# Send the tmux copy buffer to a file. The file is read for ANSI printing by "t" alias in .bashrc bind -t vi-copy y copy-pipe 'cat > ~/.tmux-buffer'
-
In server-side .bashrc, add:
t() { # Configure a PuTTY profile to send "t" as the "Remote command". This function will automatically reattach to an existing tmux session if one exists, or start a new one. This function also repeatedly sends our homemade tmux clipboard back to the PuTTY client in the form of an ANSI printer escape sequence. The contents of the homemade clipboard are populated by `bind -t vi-copy y copy-pipe 'cat > ~/.tmux-buffer'` in tmux.conf. It is expected that the PuTTY client will be configured to print to a "Microsoft XPS Document Writer" which saves the printer output to a file. The file is subsequently read by an AutoHotkey macro, and the contents are made available for paste. [[ "$TERM" == "xterm" ]] || return 0 # This prevents recursive runs, in case t() is called after tmux is started. { while :; do tput mc5; cat ~/.tmux-buffer; tput mc4; sleep 5; done } & tmux attach || tmux }
-
On client-side (Microsoft Windows), create new printer:
-
Add a Printer
-
Create a new port > Local Port
-
Enter a port name > "PuTTY_Printer_File"
-
Driver > Microsoft XPS Document Writer
-
Printer name > "PuTTY Printer"
-
Optional: Print a test page and make sure it shows up in contents of file @ "%USERPROFILE%\Documents\PuTTY_Printer_File"
-
In client-side PuTTY configuration:
-
Set Terminal > "Printer to send ANSI printer output to:" to newly created printer named "PuTTY Printer"
-
Set Connection > SSH > "Remote command:" to "t" (referencing the .bashrc function above)
-
In client-side AutoHotkey configuration, create a macro to read contents from %USERPROFILE%\Documents\PuTTY_Printer_File and output it to your clipboard:
;### Get contents of PuTTY ANSI printer device output and paste it #v:: ;Winkey + v FileRead, Clipboard, %USERPROFILE%\Documents\PuTTY_Printer_File return
-
Usage:
-
Connect to host with PuTTY and get dropped into tmux by t() function.
-
When ready to select text for copy, use tmux hotkey for copy-mode ( Ctrl + b, [ )
-
Move cursor with arrow keys
-
Begin selection with spacebar
-
End selection and copy it with "y"
-
Back on client-side running PuTTY, WindowsKey + v will paste the selection
Great workaround. Thoroughly explained. I will report back once I have it up and running.