If you are using a laptop and Linux you probably thought about how to get for example the battery status or CPU temperature (since most laptops have cooling issues) on your prompt in the shell.
First I used gDesklets for Gnome but when you are working in your shell you do not want to have a look at your desktop all the time.
But if you could have it in the PS1 updating every time you enter a command it would pretty neat.
The PS1 is defined in your bashrc file which is located at ~/.bashrc. Just add an additional line at the end, mine looks like this:
PS1='[`~/.battery.prompt.sh`][`~/.temp.prompt.sh`]\[\033[1;32m\]\h\[\033[0m\]:\$
As you can see there are two scripts executed:
- ~/.battery.prompt.sh
- ~/.temp.prompt.sh
The .battery.prompt.sh script is from wiki.ubuntuusers.de/Bash/Prompt if you want to customize your bash prompt that's definitely the site you want to check out!
You can find the battery script there too but you might have to edit it to get it work. On my IBM T23 it worked out of the box but my new DELL Latitude D610 needs some adjustments, so my .battery.prompt.sh looks like this:
#!/bin/bash
BATTERY_DIR=/proc/acpi/battery/BAT0
AC_DIR=/proc/acpi/ac_adapter/AC
if grep -q 'last full capacity' ${BATTERY_DIR}/info ; then
FULL_BATTERY=$( awk '/last full capacity/ {print $4}' ${BATTERY_DIR}/in$
CURRENT_BATTERY=$( awk '/remaining capacity/ {print $3}' ${BATTERY_DIR}$
PERCENT=$(( ${CURRENT_BATTERY} * 100 / ${FULL_BATTERY} ))
if grep -q on-line ${AC_DIR}/state; then
echo "$PERCENT+"
else
echo "$PERCENT-"
fi
else
echo "---"
fi
If it does not work for you you may go to /proc/acpi and check out if there's a battery folder and what files are in there. For me it was BAT0 and not BAT1 like on ubuntuusers.de.
The .temp.prompt.sh is far more easy. Just have a look at the acpi folder and check out if you can find thermal information, than just read it with awk.
#!/bin/bash
TEMP_DIR=/proc/acpi/thermal_zone/THM
TEMP=$( awk '/temperature/ {print $2}' ${TEMP_DIR}/temperature )
echo "${TEMP}°C"
If everything is working you get an output like this:
[31+][46°C]Zuse3:~ $
I hope this helps to increase your effectiveness while working on your laptop.