Skip to content

Instantly share code, notes, and snippets.

@sagar-gavhane
Created December 27, 2024 18:22
Show Gist options
  • Save sagar-gavhane/0baaf5c07b5686aa5da81769fd911d7b to your computer and use it in GitHub Desktop.
Save sagar-gavhane/0baaf5c07b5686aa5da81769fd911d7b to your computer and use it in GitHub Desktop.
cowsay .zshrc
# Function to get a random quote from a file (same as before)
get_random_quote() {
local quote_file="$HOME/.quotes.txt"
if [[ ! -f "$quote_file" ]]; then
echo "Error: Quotes file '$quote_file' not found." >&2
return 1
fi
local num_lines=$(wc -l < "$quote_file")
local random_line=$((RANDOM % num_lines + 1))
sed -n "${random_line}p" "$quote_file"
}
# Function to display a cow with a random quote (same as before)
cow_with_quote() {
local quote=$(get_random_quote)
if [[ $? -eq 0 ]]; then
cowsay "$quote"
else
echo "Could not retrieve a quote." >&2
fi
}
# Run the cow with quote function on every new iTerm2 session/tab
if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
cow_with_quote
fi
#Optional: Alias for manual use
alias coway="cow_with_quote"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment