LoginSignup
12
12

More than 5 years have passed since last update.

SSH 越しに tmux を開いたときステータスの色を変える

Posted at

SSH で接続した先で tmux を起動したらステータスの色を変えるようにしてみた。

.tmux.conf

# cat <<__DATA__ >/dev/null

# (無関係の設定項目は省略……)

# __DATA__
#
# function set_color {
#     if [ -z "$SSH_CONNECTION" ]; then
#         tmux set -t: status-bg                colour64
#         tmux set -t: pane-active-border-fg    colour64
#         tmux set -t: pane-border-fg           colour238
#         tmux set -t: window-status-current-bg colour106
#     else
#         tmux set -t: status-bg                colour30
#         tmux set -t: pane-active-border-fg    colour30
#         tmux set -t: pane-border-fg           colour238
#         tmux set -t: window-status-current-bg colour37
#     fi
# }
#
# function on_login {
#     # NOTE:
#     # Redirecting output of tmux to somewhere,
#     # such as "tmux ls > /dev/null", will never return on some system!
#     # You can use "| true" instead of "> /dev/null" to discard output.
#     set_color | true
# }
#
# $1

.zshrc

if [[ -n "$TMUX" ]]; then
         cut -c3- ~/.tmux.conf | sh -s on_login
fi

.tmux.conf にシェルスクリプトを埋め込んで実行する技を使っている。 .zshrc にベタ書きしてもいいのだが、 tmux に関する設定は .tmux.conf にまとめておきたいのでこうした。

ローカルの tmux のステータスは緑に、リモートの tmux のステータスは水色になる

12
12
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
12
12