From 287aed455a1bfaec16ec12783743d084354fcf48 Mon Sep 17 00:00:00 2001 From: chawley Date: Sun, 18 Feb 2024 18:55:52 -0500 Subject: [PATCH] Added custom quotes to login Pull quotes from text file online, choose one and display it with optional `cowsay and `lolcat` at each login. --- .zshrc | 2 +- get-quote.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 get-quote.sh diff --git a/.zshrc b/.zshrc index 4526c5d..f65c637 100644 --- a/.zshrc +++ b/.zshrc @@ -12,7 +12,7 @@ source $ZSH/oh-my-zsh.sh [[ ! -f ~/.shell_functions ]] || source ~/.shell_functions [[ ! -f ~/.shell_aliases ]] || source ~/.shell_aliases -fortune -a | cowsay | lolcat +$HOME/dotfiles-zsh/get-quote.sh # Instant Prompt Preamble # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc. diff --git a/get-quote.sh b/get-quote.sh new file mode 100755 index 0000000..f490a8a --- /dev/null +++ b/get-quote.sh @@ -0,0 +1,42 @@ +#!/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