Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Battery live icon #106

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 2 additions & 0 deletions battery.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ battery_interpolation=(
"\#{battery_icon_status}"
"\#{battery_percentage}"
"\#{battery_remain}"
"\#{battery_icon_live}"
)

battery_commands=(
Expand All @@ -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() {
Expand Down
128 changes: 128 additions & 0 deletions scripts/battery_icon_live.sh
Original file line number Diff line number Diff line change
@@ -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