.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)][\[email protected]\h \W]\$ '
  Reply


Messages In This Thread
.bashrc to show battery percentage at prompt - by e-minguez - 03-05-2019, 05:45 AM

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

Forum Jump:


Users browsing this thread: 1 Guest(s)