Linux: Added 'battery' which prints the usage percentage of each battery in your system

This commit is contained in:
Dylan 2016-02-02 01:56:33 +11:00
parent c70b163d6c
commit 645a6a9ddb
3 changed files with 48 additions and 1 deletions

8
1.1.md
View file

@ -91,6 +91,14 @@ fetch --disable cpu gpu disk shell
the output of birthday.
- Added `--birthday_time` and `$birthday_time` to show/hide the time in the output.
**Battery**
- Added `battery` which prints the battery usage percentage for each battery<br \>
in your system.
- **NOTE:** This currently only works on Linux, support for other platforms is being<br \>
worked on.
### Image

View file

@ -36,6 +36,7 @@ printinfo () {
# info "Font" gtkfont
# info "Disk" disk
# info "Resolution" resolution
# info "Battery" battery
# info "Birthday" birthday
# info "Song" song
# info "Visual Style" visualstyle

40
fetch
View file

@ -56,6 +56,7 @@ printinfo () {
# info "Font" gtkfont
# info "Disk" disk
# info "Resolution" resolution
# info "Battery" battery
# info "Song" song
# info "Birthday" birthday
# info "Visual Style" visualstyle
@ -1182,6 +1183,39 @@ getdisk () {
# }}}
# Battery Usage {{{
getbattery () {
case "$os" in
"Linux")
if [ -d "/sys/class/power_supply/BAT0" ]; then
batteries=($(cat /sys/class/power_supply/BAT*/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
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"
fi
;;
esac
}
# }}}
# Birthday {{{
getbirthday () {
@ -1698,6 +1732,9 @@ getw3m_img_path () {
# Info {{{
info () {
# $1 is the subtitle
subtitle="$1"
# Call the function and update variable
if [ -z "$2" ]; then
"get$1" 2>/dev/null
@ -1727,12 +1764,13 @@ info () {
;;
*)
string="${bold}${subtitle_color}${1}${clear}"
string="${bold}${subtitle_color}${subtitle}${clear}"
string+="${colon_color}: ${info_color}${output}"
length=$((${#subtitle} + ${#output} + 2))
;;
esac
# Print the string
printf "%b%s\n" "${padding}${string}${clear}"
}