diff --git a/bin/battery_indicator.sh b/bin/battery_indicator.sh new file mode 100755 index 0000000..8c7fbc9 --- /dev/null +++ b/bin/battery_indicator.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# modified from http://ficate.com/blog/2012/10/15/battery-life-in-the-land-of-tmux/ + +HEART='♥ ' + +if [[ `uname` == 'Linux' ]]; then + current_charge=$(cat /proc/acpi/battery/BAT1/state | grep 'remaining capacity' | awk '{print $3}') + total_charge=$(cat /proc/acpi/battery/BAT1/info | grep 'last full capacity' | awk '{print $4}') +else + battery_info=`ioreg -rc AppleSmartBattery` + current_charge=$(echo $battery_info | grep -o '"CurrentCapacity" = [0-9]\+' | awk '{print $3}') + total_charge=$(echo $battery_info | grep -o '"MaxCapacity" = [0-9]\+' | awk '{print $3}') +fi + +charged_slots=$(echo "((($current_charge/$total_charge)*10)/3)+1" | bc -l | cut -d '.' -f 1) +if [[ $charged_slots -gt 3 ]]; then + charged_slots=3 +fi + +echo -n '#[fg=red]' +for i in `seq 1 $charged_slots`; do echo -n "$HEART"; done + +if [[ $charged_slots -lt 3 ]]; then + echo -n '#[fg=white]' + for i in `seq 1 $(echo "3-$charged_slots" | bc)`; do echo -n "$HEART"; done +fi diff --git a/tmux/tmux.conf.symlink b/tmux/tmux.conf.symlink index 9d5fbf2..4731b1f 100644 --- a/tmux/tmux.conf.symlink +++ b/tmux/tmux.conf.symlink @@ -1,6 +1,7 @@ set -g default-command "reattach-to-user-namespace -l zsh" # tmux display things in 256 colors set -g default-terminal "screen-256color" +set -g status-utf8 on set -g history-limit 20000 @@ -147,6 +148,7 @@ tm_date='#[fg=colour245] %R %d %b' tm_host='#[fg=colour198,bg=colour232,bold]#h' tm_session_name='#[fg=colour198,bg=colour232,bold] ❤ #S' tm_mail='#[fg=colour196,bold]✉ #(~/.dotfiles/applescripts/mail.scpt -ug)' +tm_battery='#(~/.dotfiles/bin/battery_indicator.sh)' set -g status-left-length 32 set -g status-right-length 150 @@ -157,5 +159,5 @@ set -g window-status-format "#[fg=colour239,bg=colour232] #I #W " # set -g window-status-current-format "#[fg=colour232,bg=colour26]#[fg=colour16,bg=colour26,noreverse,bold] #I #W #[fg=colour26,bg=colour232,nobold]" set -g window-status-current-format "#[fg=colour232,bg=colour26]#[fg=colour16,bg=colour26,noreverse,bold] #I #W #[fg=colour26,bg=colour232,nobold]" set -g status-left $tm_session_name -set -g status-right $tm_itunes_track' '$tm_rdio_track' '$tm_date' '$tm_host +set -g status-right $tm_battery' '$tm_itunes_track' '$tm_rdio_track' '$tm_date' '$tm_host