[Bash] Remaining Battery Power as Prompt
Hi,
as seen at my pal Philipp, I also wanted to see the current battery power in the bash prompt. So here is a script which works fine on my X60s.
#!/bin/bash
REMAIN=`grep "remaining capacity" /proc/acpi/battery/BAT0/state | sed 's/remaining capacity:\(.*\)mWh/\1/'`
FULL=`grep "last full capacity" /proc/acpi/battery/BAT0/info | sed 's/last full capacity:\(.*\)mWh/\1/'`
echo $[ $REMAIN * 100 / $FULL ]`</blockquote>
Just save it for example in your home directory as bat.sh
and make it executable with chmod +x bat.sh
. Then edit the .bashrc
file in your home dir and add the following line at the end:
PS1='[`~/bat.sh`%] \W> '
The \W is some preference from me to see only the directory I’m currently in and not the whole path.
Bye Sven