#!/bin/bash
#### Declaring colour codes
RESTORE='\033[0m'
RED='\033[00;31m'
LRED='\033[01;31m'
GREEN='\033[00;32m'
LGREEN='\033[01;32m'
YELLOW='\033[00;33m'
LYELLOW='\033[01;33m'
#echo `acpitool | grep -i 'Battery' | awk '{print $5}' | cut -b1-3`
bat_perc=`acpitool | grep -i 'Battery' | awk '{print $5}' | cut -b1-3`
#echo $bat_perc
statusCharge=`acpitool | grep -i 'adapter' | awk '{print $4}'`
#echo $statusCharge
chargeStat=`acpitool | grep -i 'Battery' | awk '{print $4}' | cut -b1`
if [ $statusCharge == 'online' ]
then
echo -e "${LGREEN}$bat_perc$chargeStat"
elif [[ $statusCharge == 'off-line' && $bat_perc > 80 ]]
then
echo -e "${GREEN}$bat_perc$chargeStat"
elif [[ $statusCharge == 'off-line' && $bat_perc > 50 && $bat_perc < 79 ]]
then
echo -e "${LYELLOW}$bat_perc$chargeStat"
elif [[ $statusCharge == 'off-line' && $bat_perc > 30 && $bat_perc < 49 ]]
then
echo -e "${RED}$bat_perc$chargeStat"
elif [[ $statusCharge == 'off-line' && $bat_perc < 3 && $bat_perc < 29 ]]
then
echo -e "${LRED}$bat_perc$chargeStat"
fi

Open a text editor and save this under /opt/ or any other directory you want. Add executable permission to this script. You should have acpitool installed for this to work.
Finally edit your PS1 variable in your .bashrc which will be in your home directory accordingly. Mine is as follows,
PS1='\[\e[01;35m\]\t\[\e[m\]@`/usr/local/bin/bat`\[\e[01;34m\]\w\[\e[m\]\n--> '
#### Declaring colour codes
RESTORE='\033[0m'
RED='\033[00;31m'
LRED='\033[01;31m'
GREEN='\033[00;32m'
LGREEN='\033[01;32m'
YELLOW='\033[00;33m'
LYELLOW='\033[01;33m'
#echo `acpitool | grep -i 'Battery' | awk '{print $5}' | cut -b1-3`
bat_perc=`acpitool | grep -i 'Battery' | awk '{print $5}' | cut -b1-3`
#echo $bat_perc
statusCharge=`acpitool | grep -i 'adapter' | awk '{print $4}'`
#echo $statusCharge
chargeStat=`acpitool | grep -i 'Battery' | awk '{print $4}' | cut -b1`
if [ $statusCharge == 'online' ]
then
echo -e "${LGREEN}$bat_perc$chargeStat"
elif [[ $statusCharge == 'off-line' && $bat_perc > 80 ]]
then
echo -e "${GREEN}$bat_perc$chargeStat"
elif [[ $statusCharge == 'off-line' && $bat_perc > 50 && $bat_perc < 79 ]]
then
echo -e "${LYELLOW}$bat_perc$chargeStat"
elif [[ $statusCharge == 'off-line' && $bat_perc > 30 && $bat_perc < 49 ]]
then
echo -e "${RED}$bat_perc$chargeStat"
elif [[ $statusCharge == 'off-line' && $bat_perc < 3 && $bat_perc < 29 ]]
then
echo -e "${LRED}$bat_perc$chargeStat"
fi

Open a text editor and save this under /opt/ or any other directory you want. Add executable permission to this script. You should have acpitool installed for this to work.
Finally edit your PS1 variable in your .bashrc which will be in your home directory accordingly. Mine is as follows,
PS1='\[\e[01;35m\]\t\[\e[m\]@`/usr/local/bin/bat`\[\e[01;34m\]\w\[\e[m\]\n--> '
Comments
Post a Comment