Files
dotfiles-zsh/get-quote.sh
chawley 287aed455a Added custom quotes to login
Pull quotes from text file online, choose one and display it with
optional `cowsay and `lolcat` at each login.
2024-02-18 18:55:52 -05:00

43 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
#===============================================================================
#
# FILE:
# USAGE:
# DESCRIPTION:
# REQUIREMENTS:
# NOTES:
# AUTHOR: C Hawley
# CREATED:
#
#===============================================================================
# URL of the text file
TEXT_FILE_URL="https://files.planethawleywood.com/quotes.txt"
# Download the text file using curl and store it in a temporary file
temp_file=$(mktemp)
curl -s "$TEXT_FILE_URL" > "$temp_file"
# Count the number of lines in the file
num_lines=$(wc -l < "$temp_file")
# Generate a random line number
random_line=$(( (RANDOM % num_lines) + 1))
# Display the random line
quote=$(sed -n "${random_line}p" "$temp_file")
# cowsay and lolcat if available
if [[ $(command -v cowsay) ]]; then
if [[ $(command -v lolcat) ]]; then
cowsay -f tux "${quote}" | lolcat
else
cowsay -f tux "${quote}"
fi
else
echo "${quote}"
fi
# remove temp file
rm $temp_file