diff --git a/README.md b/README.md index 5bf4775..5c08892 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,8 @@ set -g status-right '#{battery_status_bg} Batt: #{battery_icon} #{battery_percen - `#{battery_icon_charge}` - will display a battery charge icon - `#{battery_icon_status}` - will display a battery status icon - `#{battery_percentage}` - will show battery percentage - - `#{battery_remain}` - will show remaining time of battery charge\* + - `#{battery_remain}` - will show remaining time of battery charge + - `#{battery_icon_live}` - will show the a charging battery icon or a normal one depending if the device is charging \* These format strings can be further customized via options as described below. diff --git a/battery.tmux b/battery.tmux index 0c666b8..a264c6f 100755 --- a/battery.tmux +++ b/battery.tmux @@ -17,6 +17,7 @@ battery_interpolation=( "\#{battery_icon_status}" "\#{battery_percentage}" "\#{battery_remain}" + "\#{battery_icon_live}" ) battery_commands=( @@ -32,6 +33,7 @@ battery_commands=( "#($CURRENT_DIR/scripts/battery_icon_status.sh)" "#($CURRENT_DIR/scripts/battery_percentage.sh)" "#($CURRENT_DIR/scripts/battery_remain.sh)" + "#($CURRENT_DIR/scripts/battery_icon_live.sh)" ) set_tmux_option() { diff --git a/scripts/battery_icon_live.sh b/scripts/battery_icon_live.sh new file mode 100644 index 0000000..afa1b03 --- /dev/null +++ b/scripts/battery_icon_live.sh @@ -0,0 +1,128 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/helpers.sh" + +# icons charging  ,  ,  ,  ,  , ,  +# 100, 90, 80, 60, 40, 30, 20 % + +# icons normal  , , , , , , , ,  +# 100, 90, 80, 70, 60, 50, 40, 20, 10 % + +# unfortunately there's a mismatch there are no more available charging icons, there are two that are duplicated in the variables +# this requires a patched font (nerdfont) + +# script global variables +icon_live_charge_tier8='' +icon_live_charge_tier7='' +icon_live_charge_tier6='' +icon_live_charge_tier5='' +icon_live_charge_tier4='' +icon_live_charge_tier3='' +icon_live_charge_tier2='' +icon_live_charge_tier1='' + +# script default variables +icon_live_charge_tier8_default='' +icon_live_charge_tier7_default='' +icon_live_charge_tier6_default='' +icon_live_charge_tier5_default='' +icon_live_charge_tier4_default='' +icon_live_charge_tier3_default='' +icon_live_charge_tier2_default='' +icon_live_charge_tier1_default='' + +icon_live_charge_tier8_charging='' +icon_live_charge_tier7_charging='' +icon_live_charge_tier6_charging='' +icon_live_charge_tier5_charging='' +icon_live_charge_tier4_charging='' +icon_live_charge_tier3_charging='' +icon_live_charge_tier2_charging='' +icon_live_charge_tier1_charging='' + + + +# icons are set as script global variables +get_icon_charge_settings() { + icon_live_charge_tier8=$(get_tmux_option "@batt_icon_live_charge_tier8" "$icon_live_charge_tier8_default") + icon_live_charge_tier7=$(get_tmux_option "@batt_icon_live_charge_tier7" "$icon_live_charge_tier7_default") + icon_live_charge_tier6=$(get_tmux_option "@batt_icon_live_charge_tier6" "$icon_live_charge_tier6_default") + icon_live_charge_tier5=$(get_tmux_option "@batt_icon_live_charge_tier5" "$icon_live_charge_tier5_default") + icon_live_charge_tier4=$(get_tmux_option "@batt_icon_live_charge_tier4" "$icon_live_charge_tier4_default") + icon_live_charge_tier3=$(get_tmux_option "@batt_icon_live_charge_tier3" "$icon_live_charge_tier3_default") + icon_live_charge_tier2=$(get_tmux_option "@batt_icon_live_charge_tier2" "$icon_live_charge_tier2_default") + icon_live_charge_tier1=$(get_tmux_option "@batt_icon_live_charge_tier1" "$icon_live_charge_tier1_default") +} + + +print_icon_charge_plus_status() { + percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//') + status=$(battery_status | awk '{print $1;}') + + if [ $status == 'charging' ]; then + + if [ $percentage -ge 95 -o "$percentage" == "" ]; then + # if percentage is empty, assume it's a desktop + printf "$icon_live_charge_tier8_charging" + + elif [ $percentage -ge 80 ]; then + printf "$icon_live_charge_tier7_charging" + + elif [ $percentage -ge 65 ]; then + printf "$icon_live_charge_tier6_charging" + + elif [ $percentage -ge 50 ]; then + printf "$icon_live_charge_tier5_charging" + + elif [ $percentage -ge 35 ]; then + printf "$icon_live_charge_tier4_charging" + + elif [ $percentage -ge 20 ]; then + printf "$icon_live_charge_tier3_charging" + + elif [ $percentage -gt 5 ]; then + printf "$icon_live_charge_tier2_charging" + + else + printf "$icon_live_charge_tier1_charging" + fi + + else + + if [ $percentage -ge 95 -o "$percentage" == "" ]; then + # if percentage is empty, assume it's a desktop + printf "$icon_live_charge_tier8" + + elif [ $percentage -ge 80 ]; then + printf "$icon_live_charge_tier7" + + elif [ $percentage -ge 65 ]; then + printf "$icon_live_charge_tier6" + + elif [ $percentage -ge 50 ]; then + printf "$icon_live_charge_tier5" + + elif [ $percentage -ge 35 ]; then + printf "$icon_live_charge_tier4" + + elif [ $percentage -ge 20 ]; then + printf "$icon_live_charge_tier3" + + elif [ $percentage -gt 5 ]; then + printf "$icon_live_charge_tier2" + + else + printf "$icon_live_charge_tier1" + fi + fi +} + + +main() { + get_icon_charge_settings + print_icon_charge_plus_status +} + +main