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
8
1.1.md
8
1.1.md
|
@ -91,6 +91,14 @@ fetch --disable cpu gpu disk shell
|
||||||
the output of birthday.
|
the output of birthday.
|
||||||
- Added `--birthday_time` and `$birthday_time` to show/hide the time in the output.
|
- 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
|
### Image
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ printinfo () {
|
||||||
# info "Font" gtkfont
|
# info "Font" gtkfont
|
||||||
# info "Disk" disk
|
# info "Disk" disk
|
||||||
# info "Resolution" resolution
|
# info "Resolution" resolution
|
||||||
|
# info "Battery" battery
|
||||||
# info "Birthday" birthday
|
# info "Birthday" birthday
|
||||||
# info "Song" song
|
# info "Song" song
|
||||||
# info "Visual Style" visualstyle
|
# info "Visual Style" visualstyle
|
||||||
|
|
40
fetch
40
fetch
|
@ -56,6 +56,7 @@ printinfo () {
|
||||||
# info "Font" gtkfont
|
# info "Font" gtkfont
|
||||||
# info "Disk" disk
|
# info "Disk" disk
|
||||||
# info "Resolution" resolution
|
# info "Resolution" resolution
|
||||||
|
# info "Battery" battery
|
||||||
# info "Song" song
|
# info "Song" song
|
||||||
# info "Birthday" birthday
|
# info "Birthday" birthday
|
||||||
# info "Visual Style" visualstyle
|
# 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 {{{
|
# Birthday {{{
|
||||||
|
|
||||||
getbirthday () {
|
getbirthday () {
|
||||||
|
@ -1698,6 +1732,9 @@ getw3m_img_path () {
|
||||||
# Info {{{
|
# Info {{{
|
||||||
|
|
||||||
info () {
|
info () {
|
||||||
|
# $1 is the subtitle
|
||||||
|
subtitle="$1"
|
||||||
|
|
||||||
# Call the function and update variable
|
# Call the function and update variable
|
||||||
if [ -z "$2" ]; then
|
if [ -z "$2" ]; then
|
||||||
"get$1" 2>/dev/null
|
"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}"
|
string+="${colon_color}: ${info_color}${output}"
|
||||||
length=$((${#subtitle} + ${#output} + 2))
|
length=$((${#subtitle} + ${#output} + 2))
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# Print the string
|
||||||
printf "%b%s\n" "${padding}${string}${clear}"
|
printf "%b%s\n" "${padding}${string}${clear}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue