Skip to content

Instantly share code, notes, and snippets.

@abdul-jabbar01
Last active August 27, 2019 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdul-jabbar01/65d95b03cbef596a7151d8a008e77f97 to your computer and use it in GitHub Desktop.
Save abdul-jabbar01/65d95b03cbef596a7151d8a008e77f97 to your computer and use it in GitHub Desktop.
This script will show you a very nicely format and unique daily quote on your shell screen
#!/bin/bash
# This script will show you a very nicely format unique quote of the day on your shell screen.
# Sample Screenshot => https://ibb.co/mGRQnNp
#Steps to setup
#1) Save this script file in your machine
#2) Set permissions of file by chmod +x daily-quote-shell.sh
#3) Open file ~/.bash_profile
#4) paste the path of this file as . i.e. /home/daily-quote-shell.sh
# Set Path where this shell script has been saved
QUOTE_FILE=~/Desktop/scripts/motivator
#Set Your Name
NAME="Abdul"
#It will create temporary file to save the quote
QUOTE_FILE="$QUOTE_FILE/quote.txt"
COLUMNS=$(tput cols)
#Fetch the quote from API
function fetchQuote {
quote=$(curl -s http://quotes.rest/qod.json?category=inspire | jq -r '.contents.quotes[0].quote')
author=$(curl -s http://quotes.rest/qod.json?category=inspire | jq -r '.contents.quotes[0].author')
echo "Fetching"
echo $quote > $1
echo $author >> $1
}
#Display text at center of screen
displayTextCenter() {
termwidth="$(tput cols)"
padding="$(printf '%0.1s' ={1..500})"
printf '%*.*s %s %*.*s\n\n' 0 "$(((termwidth-2-${#1})/2))" "$padding" "$1" 0 "$(((termwidth-1-${#1})/2))" "$padding"
}
#Check if quote file is not present
if [ ! -f $QUOTE_FILE ]
then
#Fetch the quote
fetchQuote $QUOTE_FILE
else
today=$(date "+%m/%d/%y")
quoteUpdated=$(stat -f %Sm -t %D $QUOTE_FILE)
#Check if quote fetched id older than today
if [ "$today" != "$quoteUpdated" ];
then
fetchQuote $QUOTE_FILE
fi
fi
quote=$(cat $QUOTE_FILE | head -1)
author=$(cat $QUOTE_FILE | tail -1)
#Display welcome message
displayTextCenter "Welcome back $NAME"
#Display quote
tput setaf 2; echo -e "$quote" | fmt -c -w $COLUMNS ; tput sgr0
tput setaf 1; echo -e "$author\n" | fmt -c -w $COLUMNS; tput sgr0
seq -f "=" -s '' $COLUMNS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment