LoginSignup
0
0

More than 5 years have passed since last update.

tmuxのstatusに自分のIPを表示しておく

Last updated at Posted at 2019-01-09

ぱっと自分のIPが確認できると良いよね

環境

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.2
BuildVersion:   18C54

tmux.confだけで完結させるver

.tmux.conf
set -g status-right '🌏#(touch -a /var/tmp/ipv4; command find /var/tmp -name ipv4 -and \( -mmin +5 -or -size 0 \) -exec curl -s -4 ifconfig.co -o {} \;; cat /var/tmp/ipv4) 🏠#(ipconfig getifaddr en0)'

グローバルIPはifconfig.coを利用して取ります.
tmuxのstatus line更新(自分の設定では5秒になっている)のたびにcurlするのは微妙だったので5分キャッシュするようにしました.

廃案:IPはcronで取っておく

crontab
*/5 * * * * curl -s -4 ifconfig.co > /var/tmp/ipv4
.tmux.conf
set -g status-right '🌏#(cat /var/tmp/ipv4) 🏠#(ipconfig getifaddr en0)'

cronとの合わせ技.こちらのほうがtmux.confは簡潔.
PC移行したときにcronの設定忘れててうまくいかないとかなんか悩んでしまったので没にした.

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