EvilZone
Programming and Scripting => Scripting Languages => : lucid January 30, 2014, 09:03:21 AM
-
#!/bin/bash
healthy='#859900'
low='#ff0000'
discharge='#dc322f'
capacity=`cat /sys/class/power_supply/BAT0/capacity`
if (($capacity <= 25));
then
capacityColour=$low
else
capacityColour=$healthy
fi
status=`cat /sys/class/power_supply/BAT0/status`
if [[ "$status" = "Discharging" ]]
then
statusColour=$discharge
status="▼"
else
statusColour=$healthy
status="▲"
fi
echo "<span>$capacity%</span> <span>$status</span>"
Not exactly sure why, but the colors are supposed to affect the arrows, and they do not.
-
https://wiki.archlinux.org/index.php/Color_Bash_Prompt (https://wiki.archlinux.org/index.php/Color_Bash_Prompt)
Not sure but I dont think bash accepts HEX color codes.
-
I am just going to leave you with my battery script:
#! /bin/bash
BATTERY_DIR=/sys/class/power_supply/BAT0
ACAD_DIR=/sys/class/power_supply/AC
BARS=$( awk '{print int( 5*($0/100) + 0.5) }' ${BATTERY_DIR}/capacity)
if [ $(cat ${ACAD_DIR}/online) -eq 1 ]; then
echo -ne "~"
fi
if [ $BARS -gt 3 ]; then
echo -ne "\[\033[1;32m\]" #green color
elif [ $BARS -gt 2 ]; then
echo -ne "\[\033[1;33m\]" #yellow color
else
echo -ne "\[\033[1;31m\]" #red color
fi
for (( c=1; c<=${BARS}; c++ ))
do
echo -ne "|"
done
for (( c=${BARS} + 1; c<=5; c++ ))
do
echo -ne " "
done
Edit: I also have found a color script somewhere in the net that I use to choose the right color values. It is pretty useful. This is not my code:
#!/bin/bash
#
# This file echoes a bunch of color codes to the
# terminal to demonstrate what's available. Each
# line is the color code of one forground color,
# out of 17 (default + 16 escapes), followed by a
# test use of that color on all nine background
# colors (default + 8 escapes).
#
T='gYw' # The test text
echo -e "\n 40m 41m 42m 43m\
44m 45m 46m 47m";
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
' 36m' '1;36m' ' 37m' '1;37m';
do FG=${FGs// /}
echo -en " $FGs \033[$FG $T "
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m";
done
echo;
done
echo
The result looks like this:
(http://s14.directupload.net/images/140130/c2hmwcei.png)
-
https://wiki.archlinux.org/index.php/Color_Bash_Prompt (https://wiki.archlinux.org/index.php/Color_Bash_Prompt)
Not sure but I dont think bash accepts HEX color codes.
I didn't think so either normally, but I thought that using variables might change it somehow. Thinking about it now that I'm less tired I'm really not sure why.
@ Deque- Thanks a bunch for that, will try it out. Yeah I see tons of people showing off that color script thing on all sorts of Awesome wm config threads. Here, nom on this..
EDIT: I wonder how people get that script to look like this:
(http://cyb3rpunk.files.wordpress.com/2010/01/enero.png)
Despite the fact that bash scripts can only use a few kinds of colors.