LoginSignup
31
32

More than 5 years have passed since last update.

コピー・ペーストをtmux、iTerm2、OS Xで共有する

Posted at

tmuxを使っているとコピー・ペーストがOS X上の他のアプリケーションと共有できない。

原因

OS Xはクリップボードを使うさいに、pbcopypbpasteというコマンドラインユーティリティを用いている。
しかしtmux上では上記ユーティリティが使用できないことがコピー・ペーストが共有できない理由のよう。

pbcopypbpasteをtmux上でも使えるようにするのが今回のゴール。

iTerm2

先にiTerm2の下記設定を無効にしておく。

Preferences > General > Applications in terminal may access clipboard

スクリーンショット 2016-07-29 8.46.29.png

tmux

pbcopypbpasteを使えるようにする。
まず下記をインストール。

$ brew install reattach-to-user-namespace

インストールしたら~/.tmux.confに下記を追記する。

~/.tmux.conf
# Mac OS X pasteboardを使用できるようにする
set-option -g default-command "reattach-to-user-namespace -l zsh"

# コピーモードでvimキーバインドを使う
setw -g mode-keys vi

# 'v' で選択を始める
bind-key -t vi-copy v begin-selection
bind-key -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"

# `Enter` でもcopy-pipeを使う
unbind -t vi-copy Enter
bind-key -t vi-copy Enter copy-pipe "reattach-to-user-namespace pbcopy"

# ']' でpbpasteを使う
bind ] run "reattach-to-user-namespace pbpaste | tmux load-buffer - && tmux paste-buffer"

最後にtmuxの設定を読み込む。

$ tmux source-file ~/.tmux.conf

参考

31
32
0

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
31
32