64

Running tmux 1.4 installed from ports on snow-leopard I am unable to use the built in OSX pbcopy command.

Outside of tmux:

> echo "abc" | pbcopy
> echo $(pbpaste) # or using ^v
abc

But inside of tmux:

> echo "123" | pbcopy
> echo $(pbpaste)
abc

I've scoured the man page but can't find any options that might relate to this behavior. I also can't understand why tmux would mess with shell redirection.

Anybody have any clues?

1
  • 1
    Note that this works using xclip on Linux. By the way, echo pbpaste should result in "pbpaste". Jan 10 '11 at 3:14
75

Using homebrew

brew install reattach-to-user-namespace --with-wrap-pbcopy-and-pbpaste

or Macports

sudo port install tmux-pasteboard

Prepend the following to the top of ~/.tmux.conf

set-option -g default-command "reattach-to-user-namespace -l zsh"

You might want to swap out the zsh for whichever shell you are using, for portability you should probably use $SHELL.

Taken from => robots.thoughtbot.com

10
  • 6
    use bash if you're on bash instead of zsh
    – three
    Oct 2 '12 at 6:48
  • my bash isn't initialized correctly (.bashrc, .bash_profile not sourced). How should this be done to do that?
    – Brad Parks
    Mar 9 '13 at 11:44
  • 1
    Must enable the option now brew install reattach-to-user-namespace --wrap-pbcopy-and-pbpaste
    – Ian Yang
    Aug 28 '13 at 14:14
  • 4
    A more robust option for tmux.conf is set-option -g default-command "reattach-to-user-namespace -l $SHELL" Apr 25 '14 at 18:27
  • 5
    option --wrap-pbcopy-and-pbpaste was deprecated using --with-wrap-pbcopy-and-pbpaste instead!
    – TaeL
    Aug 6 '16 at 9:57
11

When tmux detaches from the console (in order to support attach/detach), it does so in a way that doesn't allow it to communicate with the GUI any more.

Apple's patches to GNU screen use a private system call to detach in a different way. There is a patch in the Macports bug tracker that makes pbcopy/pbpaste work again. I also submitted it to the Homebrew repo, where it was briefly accepted, then reverted.

This is because when this patch is applied, it causes tmux to crash when re-attaching to a session.

See the pull request on github for the Homebrew project for more info.

1
  • This would make sense... except that if I run, say, open . in a tmux session, it opens a Finder window just fine, so "doesn't allow it to communicate with the GUI any more" doesn't seem quite accurate?
    – jamesdlin
    Jun 29 '18 at 0:57
6

I found a github project that wraps tmux so that pbpaste and pbcopy work and doesn't have the issues described that caused Homebrew to remove the patch. It's pretty easy to install, just a small bit of compilation and one line in your .tmux.conf

Homebrew had a patch, but as others mentioned, it was backed out because it caused issues with reattaching.

There was an issue filed against tmux, but it was closed because the tmux author doesn't have a Mac to test on. The README on the github tmux-MacOSX-pasteboard project has great details on why patching tmux is difficult in this case, and a bunch of other info surrounding the situation. It works on OSX 10.6 for me and reading through the code looks like it will work for 10.5 as well.

3

This issue is solved with the latest release ( 2.6 ) changelog https://raw.githubusercontent.com/tmux/tmux/2.6/CHANGES .

1

There is an open ticket here: http://sourceforge.net/tracker/index.php?func=detail&aid=2960136&group_id=200378&atid=973265

Date: 2010-02-28 11:20:57 UTC Sender: nicm

There is no reason you can't just pipe tmux showb to it, of course.

Date: 2010-02-28 11:20:05 UTC Sender: nicm

Not unless someone sends me some code to do it or some hardware with OS X on it.

I tried piping showb to pbcopy and it didn't work.

~: echo "12345"
12345
[use copy-mode to copy "12345"]
~: tmux showb
12345
~: tmux showb | pbcopy
~: pbpaste

1

I use tmux-MacOSX-pasteboard on both Snow Leopard and Lion and it patches pbcopy/pbpaste functionality for you in tmux. Easy to install, too.

1
  • 3
    tmux-MacOSX-pasteboard is now in macports as well with tmux-pasteboard name
    – anddam
    Mar 31 '12 at 13:04

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.