LoginSignup
44
37

More than 5 years have passed since last update.

.tmux.confをtmux 2.2に対応させる

Posted at

現行で使っているのはtmux 1.8。これを2.2にあげてtmuxが動くように.tmux.confを修正する。

.tmux.conf

修正前
https://github.com/msmsny/dotfiles/blob/bcde707fe5e4269baebffce97c8e1989e9bcee97/.tmux.conf

2.2にあげてtmuxを起動

問題が出てくるので解決していく

問題点1

エラーメッセージが出る

/home/msmsny/.tmux.conf:3: unknown option: utf8

changelogには

* UTF8 detection how happens automatically if the client supports it, hence
  the:

  mouse-utf8
  utf8

  options has been removed.

とあるのでutf8の設定は削除する。

.tmux.conf
# 削除
setw -g utf8 on

問題点2

new-windowで起動するシェルが設定を何も読んでいないデフォルトのシェルになってしまう

自分の場合は~/.bash_profileを読み込めばzshの起動+諸々設定ロード済みの状態になるので、default-commandで設定を追加した。

.tmux.conf
set -g default-command "source ~/.bash_profile"

問題点3

プロンプトのスタイル設定が効いていない

これは1.8から1.9への変更で

* The various foo-{fg,bg,attr} commands have been deprecated and replaced
  with equivalent foo-style option instead.  Currently this is still
  backwards-compatible, but will be removed over time.

とあるので置き換える。

.tmux.conf
# 旧
set -g status-bg black
set -g status-fg ${GREEN}
setw -g window-status-bg black
setw -g window-status-fg ${GREEN}
setw -g window-status-attr bold
setw -g window-status-current-bg black
setw -g window-status-current-fg ${GREEN}
setw -g window-status-current-attr underscore
set -g pane-active-border-fg ${GREEN}

# 新
set -g status-style "bg=black,fg=${GREEN}"
setw -g window-status-style "bg=black,fg=${GREEN},bold"
setw -g window-status-current-style "bg=black,fg=${GREEN},underscore"
set -g pane-active-border-style "fg=${GREEN}"

問題点4

ssh先のhostnameが取得できない

「sshしているpaneを選択した状態でnew-windowすると自動的にsshした状態にする」というバインドの設定をしていて

.tmux.conf
bind C-t new-window "~/git/scripts/tmux/postWindow.sh new 2> /dev/null || exec $SHELL"

new-windowの前のhostnameをスクリプトで取得し、sshしている。
postWindow.shが呼ぶgetLastPaneHostname.shで取得)

getLastPaneHostname.sh
SIP=$(tmux display -p "#S:#I:#P")
PTY=$(tmux info |
  egrep flags=\|bytes |
  awk '/windows/ { s = $2 }
       /references/ { i = $1 }
       /bytes/ { print s i $1 $2 } ' |
  grep "$SIP" |
  cut -d: -f4)
PTS=${PTY#/dev/}
echo -n `ps -U $USER -o pid,tty,command -ww | awk '$2 == "'$PTS'" && match($0, /ssh\ .+$/) {print substr($0, RSTART + 4, RLENGTH)}'`

しかしtmux infoで取得できる情報が変わってしまったようでttyの値を特定できなくなってしまった。(=hostnameが取得できない)
そこで取得の方法を変えて

  • #{pane_pid}で選択していたPIDを取得
  • pgrepでhostnameを取り出す

としてひとまず取得できるようにした。

getLastPaneHostname.sh
PANE_PID="`tmux display -p '#{pane_pid}'`"
echo -n "`pgrep -flP $PANE_PID | awk '{print $3}' `"
44
37
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
44
37