View previous topic :: View next topic |
Author |
Message |
Anior Guru
Joined: 17 Apr 2003 Posts: 317 Location: European Union (Stockholm / Sweden)
|
Posted: Wed Nov 05, 2003 9:45 pm Post subject: Displaying your laptops battery state in the bash prompt. |
|
|
Since I've been a frequent leecher in this forum for quite a while now I thought that it where time to try to write something of my own.
The thing I forget most frequently is pluggin in my laptops AC adapter when I arrive at school.
It's fairly new so the battery will keep it alive til just before I'm comming back from lunch.
So I decided to display my current battery charge in the bash prompt.
Resulting in something like this:
Code: | [10:21:00][Wed Nov 05][niklas@gentootop][Battery: 96%]
[~] >
|
I started out by writing the small script that will display your battery charge
I recomend saving this one to /usr/bin/battery for easy access.
Code: | #!/bin/bash
if [ -e /proc/acpi/battery/BAT0/ ]
then
path="/proc/acpi/battery/BAT0"
elif [ -e /proc/acpi/battery/BAT1/ ]
then
path="/proc/acpi/battery/BAT1"
else
echo "No batteri found. Make sure that you have acpi support in your kernel"
echo "and that the computer actually is a laptop :)"
exit 1
fi
full=`cat $path/info|grep 'last full capacity'|awk -F: '{print $2}'|awk -Fm '{print $1}'`
current=`cat $path/state|grep 'remaining capacity'|awk -F: '{print $2}'|awk -Fm '{print $1}'`
state=$(( current * 100 / $full))
echo "Battery: $state%" |
Of course you have to chmod +x /usr/bin/battery (or whatever you saved it to).
Now open up your ~/.bashrc if you just want to set it for the current user or /etc/profile for a global prompt.
Look for a line that starts with "export PS1="
Replace that one with:
Code: | PS1="\[\033[1;34m\][\[\033[1;37m\]\T\[\033[1;34m\]]\[\033[1;34m\][\[\033[1;37m\]\d\[\033[1;34m\]][\[\033[1;37m\]\u\[\033[1;34m\]@\[\033[1;37m\]\H\[\033[1;34m\]][\033[1;37m\`/usr/bin/battery\`\033[1;34m]\n[\[\033[1;37m\]\w\[\033[1;34m\]] > \[\033[1;0m\]" |
Then edit the prompt to less/more bulk as you see fit.
The prompt where created by AnarchE here on the forum. I found it quite nice so I use it on all three of my gentoo machines. Hope that he doesn't mind that I include it here aswell.
A nice thread about prompt editing can be found here.
Last edited by Anior on Wed Nov 05, 2003 10:39 pm; edited 1 time in total |
|
Back to top |
|
|
Qball Apprentice
Joined: 25 Nov 2002 Posts: 196
|
Posted: Wed Nov 05, 2003 10:16 pm Post subject: |
|
|
I like this .. gonna use it on my laptop aswell.
I wrote a while back a small C app to check on battery/cpu temp on my laptop. (overkill I know, but its darn usefull)
you can find that here: http://qballcow.nl/test/index.php?s=37
sample output:
Code: | -----------------21:19:46-----------------
The processor temp: 43 Degrees.
Battery is discharging
|####################| 100% Left.
Remaining: 03:27 (with current load)
------------------------------------------ |
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|