Created
December 27, 2024 18:22
-
-
Save sagar-gavhane/0baaf5c07b5686aa5da81769fd911d7b to your computer and use it in GitHub Desktop.
cowsay .zshrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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