Thursday, August 6, 2015

Enjoy logging in!

#!/usr/bin/env bash 

function color_bit() { 
local fgbg=0
local res="\e[00m" 
local color=$((${RANDOM}%257))
if [[ -z "${1}" ]] || [ "${1}" = " " ]; then 
 echo -en "${res}${1}${res}" 
else 
 (($((${RANDOM}%10))<9)) && fgbg=38 || fgbg=48 
 echo -en "\e[${fgbg};5;${color}m${1}${res}"
fi 
}
 
function colorize() { 
local BIT="" 
local res="\e[m" 
for (( i=0; i<${#1}; i++ )); do
  BIT="${1:$i:1}"
  [ "${BIT}" = "\n" ] && echo -en "\n${res}" || color_bit "${BIT}" 
done
 echo -en "\n"
} 

PALIN0=$(cat<< EOF 
                    A
                  A - B
                A - B - R
              A - B - R - A
            A - B - R - A - C
          A - B - R - A - C - A
        A - B - R - A - C - A - D
      A - B - R - A - C - A - D - A
    A - B - R - A - C - A - D - A - B
  A - B - R - A - C - A - D - A - B - R
A - B - R - A - C - A - D - A - B - R - A
  A - B - R - A - C - A - D - A - B - R
    A - B - R - A - C - A - D - A - B
      A - B - R - A - C - A - D - A
        A - B - R - A - C - A - D
          A - B - R - A - C - A
            A - B - R - A - C
              A - B - R - A
                A - B - R
                  A - B
                    A
EOF
) 
PALIN1=$(cat<< EOF 
S A T O R
A R E P O
T E N E T
O P E R A
R O T A S
EOF
) 
PALIN2="ΑΒΛΑΝΑΘΑΝΑΛΒΑ" 
PALINDRONES=("$PALIN0" "$PALIN1" "$PALIN2") 
PALIN_MAX=3
PALIN_CHOICE=$((${RANDOM}%${PALIN_MAX}))
colorize "${PALINDRONES[${PALIN_CHOICE}]}"
echo -en "\e[m" 
Just source the script above in your .bashrc file:
 e.g. echo ". /home/yourname/fav_scripts_dir/print_login_pal.bsh" >> ~/.bashrc