0

This works (puts the date and time in the clipboard) in just iTerm:

printf "\e]1337;Copy=:$(date | base64)\a"; echo $(pbpaste)

This works in tmux running locally (using the DCS passthrough):

printf "\ePtmux;\e\e]1337;Copy=:$(date | base64)\a\e\\"; echo $(pbpaste)

This works in tmux running remotely:

printf "\ePtmux;\e\e]1337;Copy=:$(date | base64)\a\e\\"; echo $(ssh -p 2222 -qt localhost pbpaste)

My only problem is running tmux remotely under a local tmux:

printf "\ePtmux;\e\ePtmux;\e\e]1337;Copy=:$(date | base64)\a\e\\\e\\"; echo $(ssh -p 2222 -qt localhost pbpaste)

I think the problem is the inner \e\\ is being interpreted as the outer \e\\.

Is there some way to escape the inner \e\\ so it makes it the outer tmux properly?

1

You need to double every \e for each tmux, including the \e in the terminating \e\\, so:

printf "\ePtmux;\e\ePtmux;\e\e]1337;Copy=:$(date | base64)\a\e\e\\\e\\"

Alternatively if you configure tmux to use OSC 52 and then turn it on in iTerm2 ("Applications in terminal may access clipboard" from a quick search) it will pass through each tmux (creating a paste buffer in each) to the host clipboard. For tmux you will need something like:

set -as terminal-overrides ',tmux*:Ms=\\E]52;%p1%s;%p2%s\\007'
set -as terminal-overrides ',screen*:Ms=\\E]52;%p1%s;%p2%s\\007'
set -s set-clipboard on

Then you can do this in the innermost tmux:

printf "\033]52;$(date)\007"

Of course this will mean anything you copy in tmux will also go into the host clipboard which you may not want.

| improve this answer | |
  • Setting up OSC 52 works great, thanks. But I wanted to send other escape sequences as well (for growl notifications and other stuff). The printf is hanging, but that seems to be related to printf as perl -e 'print "\ePtmux;\e\ePtmux;\e\e\e\e]1337;Copy=:@{[date | base64]}\n\a\e\e\\\e\\"' is working. – Chas. Owens Dec 11 '19 at 19:20
  • Try piping both printf and perl to cat -v or od or something (eg printf "..."|cat -v) and compare what they are sending to tmux to see what printf is doing differently. – Nicholas Marriott Dec 11 '19 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.