Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # In .bashrc to add the 'battery_status' to PS1
- # From a script written here :
- #http://www.basicallytech.com/blog/index.php?/archives/110-Colour-coded-battery-charge-level-and-status-in-your-bash-prompt.html, by Rob NEWCATER
- # Most of the work is his, I only did minor editing
- # Edited by J.DESROCHES to work on my laptop running "Linux version 3.14.2-1-ARCH (nobody@var-lib-archbuild-testing- # x86_64-tobias) (gcc version 4.9.0 (GCC) ) #1 SMP PREEMPT Sun Apr 27 11:28:44 CEST 2014" (output of cat /proc/version)
- ########################################################################################################################
- # By : J.D.
- # Battery status :
- battery_status()
- {
- BATTERY=/sys/class/power_supply/BAT1
- CHARGE=`cat $BATTERY/capacity`
- BATSTATE=`cat $BATTERY/status`
- # Colors for humans
- 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
- # prevent an error if the battery is not in the laptop (e.g. you have two and take out the primary)
- STATE=`cat $BATTERY/state`
- if [ "$STATE" == 'present: no' ]
- then
- echo -e "${RED}nobat"
- exit
- fi
- if [ "$CHARGE" -gt "15" ]
- then
- COLOUR="$YEL"
- fi
- if [ "$CHARGE" -gt "30" ]
- then
- COLOUR="$GRN"
- fi
- echo -e "${BATSTT}${COLOUR}${CHARGE}%${NON}"
- }
- # and here's my PS1 if people are looking for ideas :
- PS1='\[\e[1;34m\]{\d \t}\[\e[m\]\[\e[0;33m\]{\[\e[m\]$(battery_status)\[\e[0;33m\]}\[\e[m\] \[\e[0;32m\]\u\[\e[m\] @ \[\e[0;32m\]\h\[\e[m\] : \[\e[1;34m\]\W\[\e[m\] [\e[1;32m\]\$\[\e[m\]\n\[\e[1;37m\]'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement