magic 8 ball bash script
Date: June 22, 2013
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
Leave a Reply