LoginSignup
34
18

More than 5 years have passed since last update.

macOS Sierra の tmux 上で pbcopy と pbpaste が動くようにする

Last updated at Posted at 2017-01-06

tmux 2.6 で問題が解消されたので、この記事の対応は不要となりました。


Mac には、ターミナル上でクリップボードへのコピーとペーストを行う pbcopypbpaste というコマンドがありますが、 Sierra にアップグレードしたら tmux 上でこれらのコマンドが効かなくなってしまいました。

環境

  • macOS Sierra

    $ sw_vers
    ProductName:    Mac OS X
    ProductVersion: 10.12.2
    BuildVersion:   16C68
    
  • tmux 2.3

    $ tmux -V
    tmux 2.3
    

既に同様の声が多く上がっており、暫定的な対応策として reattach-to-user-namespace というラッパーが作られていたのでこれを入れます。

reattach-to-user-namespace で pbcopypbpaste を動くようにする

1. reattach-to-user-namespace をインストールする

Homebrew を使っていればこれでインストールできます。

$ brew install reattach-to-user-namespace

2. .tmux.conf に設定を追加する

自分の .tmux.conf に設定を追加します。

$ echo 'set -g default-command "reattach-to-user-namespace -l ${SHELL}"' >> /path/to/your/.tmux.conf

3. tmux を再起動する

$ tmux kill-server

これで pbcopypbpaste が使えるようになりました。

reattach-to-user-namespace を作った経緯

reattach-to-user-namespace の README に Quick Summary として作成の経緯が書いてありました。

  • tmux で Mac OS X の pbpaste と pbcopy が動かなくなった。 screen も同様の影響を受けている。
  • ドキュメントになっていないプライベート API 関数でこの問題を解決できる。
  • その関数は安定していない (現に 10.6 で引数が追加されている) ので、 tmux にパッチを当てるより小さなラッパーを使った方がいいと思い reattach-to-user-namespace を作った。

ということでこの方法はあくまで応急措置であり、当該のプライベート API がパブリックになるなどすれば tmux 本体で対応されるかもしれませんね。

参考

Problems copying text on Mac OS Sierra · Issue #543 · tmux/tmux

34
18
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
18