.bashrc to show battery percentage at prompt
#1
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]\$ '
#2
Excellent!! My Pinebook 14 (with the old Mate image) had the battery directory in a slightly different place:

BATTERY=/sys/class/power_supply/battery


Possibly Related Threads…
Thread Author Replies Views Last Post
  Display battery charge value with LXDE and lxpanel wlad 1 8,357 12-04-2019, 03:36 AM
Last Post: pnts-se
  Improve the life of your Pinebook battery by setting charger's voltage limits wlad 0 4,509 06-11-2019, 02:27 PM
Last Post: wlad
  How can I reliably get battery status on pinebook tillea 5 15,645 06-11-2019, 10:10 AM
Last Post: wlad
  Battery Status in Bionic X-Istence 3 8,686 03-11-2019, 03:52 PM
Last Post: soupbowl
  Battery drained while turned off amentis 6 13,053 07-17-2018, 02:38 AM
Last Post: pfeerick
  Splash But No Login After Low Battery robbiemacg 3 8,279 05-17-2018, 09:30 AM
Last Post: robbiemacg
Information i3wm xenial-i3 introduction -- mate terminal & battery monitor MarkHaysHarris777 4 11,119 08-31-2017, 04:47 AM
Last Post: shirman

Forum Jump:


Users browsing this thread: 1 Guest(s)