Linux: Added 'battery' which prints the usage percentage of each battery in your system
This commit is contained in:
parent
c70b163d6c
commit
645a6a9ddb
3 changed files with 48 additions and 1 deletions
40
fetch
40
fetch
|
@ -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}"
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue