Added 'battery_num' which allows you to choose which battery to display by number.
This commit is contained in:
parent
645a6a9ddb
commit
bb48caec70
3 changed files with 29 additions and 4 deletions
3
1.1.md
3
1.1.md
|
@ -96,6 +96,9 @@ the output of birthday.
|
|||
- Added `battery` which prints the battery usage percentage for each battery<br \>
|
||||
in your system.
|
||||
|
||||
- Added `battery_num` which allows you to choose which battery to display, <br \>
|
||||
it also takes the value `all` which will print all batteries line by line.
|
||||
|
||||
- **NOTE:** This currently only works on Linux, support for other platforms is being<br \>
|
||||
worked on.
|
||||
|
||||
|
|
|
@ -115,6 +115,14 @@ gtk2="on"
|
|||
gtk3="on"
|
||||
|
||||
|
||||
# Battery
|
||||
|
||||
# Which battery to display.
|
||||
# By default we display all batteries.
|
||||
# --battery_num all, 0, 1, 2, etc
|
||||
battery_num="all"
|
||||
|
||||
|
||||
# Birthday
|
||||
|
||||
# Whether to show a long pretty output
|
||||
|
|
22
fetch
22
fetch
|
@ -135,6 +135,14 @@ gtk2="on"
|
|||
gtk3="on"
|
||||
|
||||
|
||||
# Battery
|
||||
|
||||
# Which battery to display.
|
||||
# By default we display all batteries.
|
||||
# --battery_num all, 0, 1, 2, etc
|
||||
battery_num="all"
|
||||
|
||||
|
||||
# Birthday
|
||||
|
||||
# Whether to show a long pretty output
|
||||
|
@ -1189,26 +1197,32 @@ getbattery () {
|
|||
case "$os" in
|
||||
"Linux")
|
||||
if [ -d "/sys/class/power_supply/BAT0" ]; then
|
||||
batteries=($(cat /sys/class/power_supply/BAT*/capacity))
|
||||
# Set the index to the battery number.
|
||||
case "$battery_num" in
|
||||
"all") battery_num="*" index=0 ;;
|
||||
*) index="$battery_num" ;;
|
||||
esac
|
||||
|
||||
# Create an array of battery usage from each battery.
|
||||
batteries=($(cat /sys/class/power_supply/BAT${battery_num}/capacity))
|
||||
|
||||
# Get the subtitle and reassign it so it doesn't change.
|
||||
title="$subtitle"
|
||||
|
||||
# If there's only a single battery,
|
||||
# don't number the subtitle.
|
||||
if [ "${#batteries[@]}" == 1 ]; then
|
||||
if [ "${#batteries[@]}" == 1 ] && [ "$battery_num" == 0 ]; then
|
||||
prin "${title}: ${batteries[0]}%"
|
||||
return
|
||||
fi
|
||||
|
||||
# Print each battery on a seperate line.
|
||||
index=0
|
||||
for bat in ${batteries[@]}; do
|
||||
prin "${title}${index}: ${bat}%"
|
||||
index=$((index + 1))
|
||||
done
|
||||
else
|
||||
battery="Unknown"
|
||||
battery="None"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
|
Loading…
Reference in a new issue