2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

powerlineを使わずにtmuxのstatus-lineにIMEとか曲名とかを表示する遊び

Last updated at Posted at 2017-04-24

タイトルに書いたものとかを取得/表示します.tmux-powerlineとかは使いません.
tmuxで扱えるように回りくどい書き方しているものもあります.
(音量はosascript -e (get volume settings)'s output volumeで取れたりとか)

#実験環境

Mac
iTerm2
tmux

#シェルで値を取得してみる

今回は

  • IME
  • 音量
  • WiFiの信号強度
  • WiFiのSSID
  • バッテリー残量
  • iTunesで再生されてるトラック名
    を取りました.

##IME

/usr/libexec/PlistBuddy -c "Print AppleSelectedInputSources" ~/Library/Preferences/com.apple.HIToolbox.plist|grep -Eo 'Japanese|Roman'

見やすくするとこんな感じ

if /usr/libexec/PlistBuddy -c 'Print AppleSelectedInputSources' ~/Library/Preferences/com.apple.HIToolbox.plist|grep -Eo 'Japanese'>/dev/null; then echo 'あ'; else echo 'A'; fi

##音量

osascript -e 'get Volume settings'|tr ':,' '\n'|head -n 2|tail -n 1

##Wi-Fi信号強度(RSSI値)

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I|grep 'agrCtlRSSI:'|cut -d ' ' -f7

##Wi-FiのESSID

en0部分は使用環境に合わせて変更してください

networksetup -getairportnetwork en0|tr ': ' '\n'|tail -n 1

##バッテリー残量

ioreg -l|grep CurrentCapacity|tr '= ' '\n'|tail -n 1

…だとmAhの値が出てきちゃうので,以下のコマンドでパーセント表示させます.(追記)

pmset -g batt|tr '\t;' '\n'|tail -n 3|head -n 1

##再生中の曲名

osascript -e 'tell application "iTunes"' -e 'the name of current track' -e 'end tell'

#status-lineに表示してみる

見栄えのためにemojify使ってます.

set -g status-right "#(if pmset -g batt|grep 'AC'>/dev/null; then emojify :electric_plug:; else emojify :battery:; fi):#(pmset -g batt|tr '\t;' '\n'|tail -n 3|head -n 1) #(if osascript -e 'get volume settings'|grep false>/dev/null; then emojify :sound:; else emojify :mute:; fi):#(osascript -e 'get Volume settings'|tr ':,' '\n'|head -n 2|tail -n 1) #(emojify :musical_note:):#(osascript -e 'tell application "iTunes"' -e 'the name of current track' -e 'end tell') #(emojify :signal_strength:):#(networksetup -getairportnetwork en1|tr ': ' '\n'|tail -n 1)(#(if [ `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I|grep 'agrCtlRSSI:'|cut -d ' ' -f7` -gt -60 ]; then echo 強; elif [ `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I|grep 'agrCtlRSSI:'|cut -d ' ' -f7` -gt -80 ]; then echo 中; else echo 弱; fi)) #(if /usr/libexec/PlistBuddy -c 'Print AppleSelectedInputSources' ~/Library/Preferences/com.apple.HIToolbox.plist|grep -Eo 'Japanese'>/dev/null; then echo 'あ'; else echo 'A'; fi) %m/%d(%a)%H:%M"

長いなぁ

#参考

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?