Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agnoster theme : batteries status in the prompt #5425

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions themes/agnoster.zsh-theme
Expand Up @@ -190,10 +190,58 @@ 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 online
LEVEL1=95
LEVEL2=50
LEVEL3=15
LEVEL4=5

online=$(< /sys/class/power_supply/AC0/online)
if [ ${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

if [ ${online} -ne 0 ]; then
prompt_segment ${bg} ${fg} "[${BAT} "${cap}"W]"
else
prompt_segment ${bg} ${fg} "[${BAT} "${cap}"/"${sign}${power}"W]"
fi

done

fi
}

## Main prompt
build_prompt() {
RETVAL=$?
prompt_status
prompt_battery
prompt_virtualenv
prompt_context
prompt_dir
Expand Down