From f15deb7557c1fcedd02a78fbf22bcd908320807d Mon Sep 17 00:00:00 2001 From: Francois Scala Date: Tue, 20 Sep 2016 12:46:39 +0200 Subject: [PATCH 1/2] update themes/agnoster.zsh-theme : added battery status to the prompt --- themes/agnoster.zsh-theme | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme index da1f9b6e6..528f49bda 100644 --- a/themes/agnoster.zsh-theme +++ b/themes/agnoster.zsh-theme @@ -190,10 +190,54 @@ prompt_status() { [[ -n "$symbols" ]] && prompt_segment black default "$symbols" } +# Battery status +prompt_battery() { + if $(ls -d /sys/class/power_supply/BAT* &> /dev/null) + then + + local PLUG_CHAR + () { + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + PLUG_CHAR='🔌' + } + + local LEVEL1 LEVEL2 LEVEL3 LEVEL4 + LEVEL1=95 + LEVEL2=50 + LEVEL3=15 + LEVEL4=5 + + if [ $(< /sys/class/power_supply/AC0/online) -ne '0' ] + then + prompt_segment blue grey "${PLUG_CHAR} " + fi + + for BAT in $(basename $(dirname /sys/class/power_supply/*/capacity)) + do + cap=$(< /sys/class/power_supply/$BAT/capacity) + power=$(< /sys/class/power_supply/$BAT/power_now ) + let power=power/1000000 + + local bg fg + if [ $cap -gt $LEVEL1 ]; then bg="blue"; fg="grey" + elif [ $cap -gt $LEVEL2 ]; then bg="green"; fg="black" + elif [ $cap -gt $LEVEL3 ]; then bg="yellow"; fg="black" + elif [ $cap -gt $LEVEL4 ]; then bg="red"; fg="yellow" + else bg="magenta"; fg="yellow" + fi + + prompt_segment ${bg} ${fg} "[${BAT} "${cap}"/"${sign}${power}"W]" + + done + + fi +} + ## Main prompt build_prompt() { RETVAL=$? prompt_status + prompt_battery prompt_virtualenv prompt_context prompt_dir From 04948b94f9e3f25a8e9daf45f26ba0534e63eff4 Mon Sep 17 00:00:00 2001 From: Francois Scala Date: Tue, 20 Sep 2016 12:52:06 +0200 Subject: [PATCH 2/2] update themes/agnoster.zsh-theme : display power usage only when not charging --- themes/agnoster.zsh-theme | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme index 528f49bda..1cc3663d2 100644 --- a/themes/agnoster.zsh-theme +++ b/themes/agnoster.zsh-theme @@ -201,14 +201,14 @@ prompt_battery() { PLUG_CHAR='🔌' } - local LEVEL1 LEVEL2 LEVEL3 LEVEL4 + local LEVEL1 LEVEL2 LEVEL3 LEVEL4 online LEVEL1=95 LEVEL2=50 LEVEL3=15 LEVEL4=5 - if [ $(< /sys/class/power_supply/AC0/online) -ne '0' ] - then + online=$(< /sys/class/power_supply/AC0/online) + if [ ${online} -ne 0 ]; then prompt_segment blue grey "${PLUG_CHAR} " fi @@ -226,7 +226,11 @@ prompt_battery() { else bg="magenta"; fg="yellow" fi - prompt_segment ${bg} ${fg} "[${BAT} "${cap}"/"${sign}${power}"W]" + if [ ${online} -ne 0 ]; then + prompt_segment ${bg} ${fg} "[${BAT} "${cap}"W]" + else + prompt_segment ${bg} ${fg} "[${BAT} "${cap}"/"${sign}${power}"W]" + fi done