You are not logged in.

#1 2012-12-27 16:44:23

kanikuleet
Member
Registered: 2012-12-22
Posts: 36

[solved] show battery status in PS1 not working correctly (script)

Hey,
I got this script to show the battery life of my laptop in my PS1:

#!/bin/bash
BATTERY=/sys/class/power_supply/BAT1

REM_CAP=`cat $BATTERY/energy_now`
FULL_CAP=`cat $BATTERY/energy_full`
BATSTATE=`cat $BATTERY/status`

CHARGE=`echo $(( $REM_CAP * 100 / $FULL_CAP ))`

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

if [ "$CHARGE" -gt "99" ]
then
	CHARGE=100
fi

if [ "$CHARGE" -gt "30" ]
then
	COLOUR="$GRN"
fi

if [ "$CHARGE" -gt "15" ]
then
	COLOUR="$YEL"
fi


echo -e "${COLOUR}${CHARGE}%${NON} ${BATSTT}"

I made it executable: chmod +x /home/kanikuleet/scripts/battery_status.sh
Put this in my .bashrc file: PS1="[ \$(/home/kanikuleet/scripts/battery_status.sh) ] \u@\h:\w \$ "
Built it: source ~/.bashrc

Now I get this errors:

/home/kanikuleet/scripts/battery_status.sh: Line 30: [: echo $(( $REM_CAP * 100 / $FULL_CAP )): integer expression expected
/home/kanikuleet/scripts/battery_status.sh: Line 35: [: echo $(( $REM_CAP * 100 / $FULL_CAP )): integer expression expected
/home/kanikuleet/scripts/battery_status.sh: Line 40: [: echo $(( $REM_CAP * 100 / $FULL_CAP )): integer expression expected

My bash promt currently looks like this:

[ echo $(( $REM_CAP * 100 / $FULL_CAP ))%  ] kanikuleet@arch: ~ $

I have acpi installed and BAT1 is my battery, I checked it.

Can anyone help??

Last edited by kanikuleet (2012-12-28 22:21:10)

Offline

#2 2012-12-27 17:43:54

illusionist
Member
From: localhost
Registered: 2012-04-03
Posts: 498

Re: [solved] show battery status in PS1 not working correctly (script)

I modified your script a little bit. Try this
http://pastebin.com/19hhf6su

EDIT: replace BAT0 with your battery.

Last edited by illusionist (2012-12-27 17:45:41)


  Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github

Offline

#3 2012-12-27 18:34:26

kanikuleet
Member
Registered: 2012-12-22
Posts: 36

Re: [solved] show battery status in PS1 not working correctly (script)

Works! Thank you smile

Offline

#4 2012-12-28 12:42:10

illusionist
Member
From: localhost
Registered: 2012-04-03
Posts: 498

Re: [solved] show battery status in PS1 not working correctly (script)

kanikuleet wrote:

Works! Thank you smile

In that case, please mark your thread as [solved] by editing the title of your post.


  Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github

Offline

Board footer

Powered by FluxBB