Author Topic: [Bash]Colors not taking effect  (Read 774 times)

0 Members and 2 Guests are viewing this topic.

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
[Bash]Colors not taking effect
« on: January 30, 2014, 09:03:21 am »
Code: [Select]
#!/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.
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: [Bash]Colors not taking effect
« Reply #1 on: January 30, 2014, 12:42:08 pm »
https://wiki.archlinux.org/index.php/Color_Bash_Prompt
Not sure but I dont think bash accepts HEX color codes.
« Last Edit: January 30, 2014, 12:42:40 pm by proxx »
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: [Bash]Colors not taking effect
« Reply #2 on: January 30, 2014, 01:51:31 pm »
I am just going to leave you with my battery script:

Code: (Bash) [Select]
#! /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:

Code: (bash) [Select]
#!/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:

« Last Edit: January 30, 2014, 02:06:53 pm by Deque »

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: [Bash]Colors not taking effect
« Reply #3 on: January 30, 2014, 07:29:48 pm »
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:



Despite the fact that bash scripts can only use a few kinds of colors.
« Last Edit: January 30, 2014, 10:40:29 pm by lucid »
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python