LoginSignup
14
13

More than 5 years have passed since last update.

zsh & tmuxで、sshした際にステータスラインに警告文的なのを表示したかった

Posted at

tmux 上のzshから、特定ホストにsshしている際に、tmuxのステータスラインに警告文を出したかった。
例えば本番サーバいじってる際は、その旨警告をしたい。

とりあえず.zshrcに以下の記述を追加して、ssh実行時と終了時にtmuxのウインドウ名フォーマットを変更してみる。
特定ホストログイン時のみ警告したい場合は、sshでgrepしている辺りを適宜書き換える。

preexec()
{
  echo "$1" | grep "ssh"
  if [ "$TMUX" -a "$?" -eq 0 ]
  then
    tmux set-window-option -a window-status-format "#[fg=red](Prod!)" > /dev/null
    tmux set-window-option -a window-status-current-format "#[fg=red](Prod!)" > /dev/null
  fi
}

precmd()
{
  history -1 | sed "s/^\s[0-9]*\s*//" | grep "ssh"
  if [ "$TMUX" -a "$?" -eq 0 ]
  then
    tmux set-window-option -u window-status-format > /dev/null
    tmux set-window-option -u window-status-current-format > /dev/null
  fi
}

上記の例で、ウインドウ1でssh実行時に、以下のようになる。

Screenshot_from_2013-07-17 23:58:45.png

しかしこのやり方だと、例えば同一ウインドウ内の複数ペイン内でsshしたい場合などに対応できないので、後でなんとかしたい。

また、最近powerlineを導入しているのだが、その様な凝ったデザインのステータスラインにしている場合はそれとの兼ね合いをどうするか悩みどころ。

Screenshot_from_2013-07-17 23:59:40.png

14
13
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
14
13