9
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

tmux設定をmacとlinuxで共存させる

Posted at

ubuntuの開発環境を整えるにあたり、.tmux.confをmacからコピーしてきたがmacでしか動かない設定がベタ打ちになっており、そもそも起動しなかったのでmac, linuxで共存できるように設定を更新した。

tmux起動して [exited] 62;9;c とか言い始めたらまず間違いなくこれ

reattach-to-user-namespace これを呼び出してるから


解決策

.tmux.confif-shellで制御構文が書けるのでmac, linuxでそれぞれの設定を書く。

mac

tmux.conf
if-shell "uname | grep -q Darwin"

linux

厳密にはxselでclipboardが利用できるかどうか調べて実行する。

tmux.conf
if-shell 'type xsel'

最終的にこうなった

tmux.conf
# クリップボード共有を有効にする
# for mac
if-shell "uname | grep -q Darwin" \
  'set-option -g default-command "reattach-to-user-namespace -l zsh"'
if-shell "uname | grep -q Darwin" \
  'bind-key -T copy-mode-vi y send -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"'

# for Linux
# tmuxのbufferとxのclipboardを連携させる
if-shell 'type xsel' \
  "bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xsel -ib'"
if-shell 'type xsel' \
  "bind-key -T copy-mode-vi Y send-keys -X copy-pipe 'xsel -ib'"
if-shell 'type xsel' \
  "bind ] run-shell \
    'xsel -ob | xargs -0 -I{} tmux set-buffer -- {} && tmux paste-buffer'"
9
3
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
9
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?