2013
06.22
06.22
so i got bored a couple of days ago and decided to write a magic 8 ball script. i know, they have been done a million times before, but it was 10 minutes and i wanted to see how centered in the terminal i could get it.
you can get it here.
here are the goods:
#!/bin/bash
[ -z $(which tput 2>/dev/null) ] && { printf "%s\n" "tput not found"; exit 1; }
GRN=$(tput setaf 2)
YLW=$(tput setaf 3)
RED=$(tput setaf 1)
CLR=$(tput sgr0)
ANSWERS=(
"`printf "${GRN}●${CLR} It is certain"`"
"`printf "${GRN}●${CLR} It is decidedly so"`"
"`printf "${GRN}●${CLR} Without a doubt"`"
"`printf "${GRN}●${CLR} Yes definitely"`"
"`printf "${GRN}●${CLR} You may rely on it"`"
"`printf "${GRN}●${CLR} As I see it yes"`"
"`printf "${GRN}●${CLR} Most likely"`"
"`printf "${GRN}●${CLR} Outlook good"`"
"`printf "${GRN}●${CLR} Yes"`"
"`printf "${GRN}●${CLR} Signs point to yes"`"
"`printf "${YLW}●${CLR} Reply hazy try again"`"
"`printf "${YLW}●${CLR} Ask again later"`"
"`printf "${YLW}●${CLR} Better not tell you now"`"
"`printf "${YLW}●${CLR} Cannot predict now"`"
"`printf "${YLW}●${CLR} Concentrate and ask again"`"
"`printf "${RED}●${CLR} Dont count on it"`"
"`printf "${RED}●${CLR} My reply is no"`"
"`printf "${RED}●${CLR} My sources say no"`"
"`printf "${RED}●${CLR} Outlook not so good"`"
"`printf "${RED}●${CLR} Very doubtful"`"
)
MOD=${#ANSWERS[*]}
INDEX=$(($RANDOM%$MOD))
W_CNT=$((${#ANSWERS[$INDEX]}-9))
printf $(tput clear)
tput cup $(($(tput lines)/2)) $((($(tput cols)/2)-($W_CNT/2)))
printf "${ANSWERS[$INDEX]}"
tput cup $(tput lines) 0
The following two tabs change content below.
charlie root
VP of keeping it real / HNIC at pissedoffadmins.com
I bring the cold coffee.
Latest posts by charlie root (see all)
- ssh master just for the ports - March 29, 2018
- Do recruiters dream of electric replies ? - March 16, 2018
- So my linux install is broken….. what to try first - January 29, 2018
No Comment.
Add Your Comment