diff --git a/1.1.md b/1.1.md index daee1991..6da39756 100644 --- a/1.1.md +++ b/1.1.md @@ -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
+in your system. + +- **NOTE:** This currently only works on Linux, support for other platforms is being
+worked on. + ### Image diff --git a/config/config b/config/config index bc51295f..553b5504 100644 --- a/config/config +++ b/config/config @@ -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 diff --git a/fetch b/fetch index 211dd3ae..0b3fbe2b 100755 --- a/fetch +++ b/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}" }