![]() |
|
.bashrc to show battery percentage at prompt - Printable Version +- PINE64 (https://forum.pine64.org) +-- Forum: Pinebook (https://forum.pine64.org/forumdisplay.php?fid=76) +--- Forum: Linux on Pinebook (https://forum.pine64.org/forumdisplay.php?fid=79) +--- Thread: .bashrc to show battery percentage at prompt (/showthread.php?tid=7227) |
.bashrc to show battery percentage at prompt - e-minguez - 03-05-2019 Code: #
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
alias ls='ls --color=auto'
battery_status(){
# From http://www.basicallytech.com/blog/archive/110/Colour-coded-battery-charge-level-and-status-in-your-bash-prompt
BATTERY=/sys/class/power_supply/axp20x-battery
BATSTATE=$(cat ${BATTERY}/status)
CHARGE=$(cat ${BATTERY}/capacity)
NON='\033[00m'
BLD='\033[01m'
RED='\033[01;31m'
GRN='\033[01;32m'
YEL='\033[01;33m'
COLOUR="$RED"
case "${BATSTATE}" in
'Charged')
BATSTT="$BLD=$NON"
;;
'Charging')
BATSTT="$BLD+$NON"
;;
'Discharging')
BATSTT="$BLD-$NON"
;;
esac
# prevent a charge of more than 100% displaying
if [ "$CHARGE" -gt "99" ]
then
CHARGE=100
fi
if [ "$CHARGE" -gt "15" ]
then
COLOUR="$YEL"
fi
if [ "$CHARGE" -gt "30" ]
then
COLOUR="$GRN"
fi
echo -e "${COLOUR}${CHARGE}%${NON} ${BATSTT}"
}
PS1='[$(battery_status)][\u@\h \W]\$ 'RE: .bashrc to show battery percentage at prompt - PatrickM - 03-05-2019 Excellent!! My Pinebook 14 (with the old Mate image) had the battery directory in a slightly different place: BATTERY=/sys/class/power_supply/battery |