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

sho2010
3 min readMar 20, 2019

--

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

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

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

解決策

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

mac

if-shell "uname | grep -q Darwin"

linux

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

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'"

参考

https://askubuntu.com/questions/442766/tmux-exited-on-startup

--

--