ENV: I am running tmux in putty, on a windows 7 laptop. I do ssh to linux systems while working.
I have to solve two glitches with tmux, before using it for all my needs.
With some trickery, it is possible to get the tmux buffer back through PuTTY and onto the client. I accomplished this using ANSI escape codes for the "AUX" port (serial printer).
Here is just one implementation of that method of transfer:
1) 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'
2) 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
}
3) On client-side (Microsoft Windows), create new printer:
PuTTY_Printer_File
"PuTTY Printer
"%USERPROFILE%\Documents\PuTTY_Printer_File
"4) In client-side PuTTY configuration:
PuTTY Printer
"t
" (referencing the .bashrc function above)At this point you can send the contents of the tmux buffer to your PuTTY client by highlighting some text in tmux's copy-mode, and pressing y
. The selected text will end in up %USERPROFILE%\Documents\PuTTY_Printer_File
back on the client. If you want to go a step further and emulate "pasting" out of this file, you can use a hotkey sequence to read the contents of the file and insert it. Here's an example that leverages AutoHotKey, but it is probably possible to achieve the same result in PowerShell if you prefer.
5) Client-side AutoHotKey macro:
;### Get contents of PuTTY ANSI printer device output and paste it
#v:: ;Winkey + v
FileRead, PuTTYPrinter, %USERPROFILE%\Documents\PuTTY_Printer_File
SendInput %PuTTYPrinter%
PuTTYPrinter = ; Free up memory
return
6) Complete usage procedure:
Ctrl + b
, [
)spacebar
y
WindowsKey + v
will paste the selectionSince pictures are worth 1,000 words, here's an overview of what's happening: https://media.licdn.com/mpr/mpr/AAEAAQAAAAAAAAfiAAAAJDYzM2RmMzYzLTk1NmQtNGQxMi1iN2YyLTQ4NGUxNjExMmVlOA.png