If you come from bash you might have to change your $PATH.
export PATH=HOME/bin:/usr/local/bin:PATH
export ZSH="$HOME/.oh-my-zsh"
ghibli_time_sparkle() {
local hour=(hour -ge 6 && hour -ge 12 && hour -ge 17 && $hour -lt 21 ]]; then
echo "✨" # Evening (magic hour like in image)
else
echo "🌙" # Night
fi
}
Assistant
Looking at your zsh configuration, I can see you're already using curl and jq in your display_fun_fact() function! Here's how to access JSON fields from an API endpoint:
display_fun_fact() {
# Check if curl and jq are installed
if ! command -v curl &> /dev/null; then
echo "SPARKLEGOLD✨Note:′curl′isnotinstalled.Cannotfetchfunfacts.{RESET}"
return
fi
if ! command -v jq &> /dev/null; then
echo "SPARKLEG{RESET}"
# Fallback (less reliable, but might work if jq isn't there)
local fact_raw=(curl−s"https(echo "fact_raw" | grep -oP '"text":\s*"\K[^"]+' | head -n 1) # Extract text using grep
else
local fact=(curl -s "https://uselessfacts.jsph.pl/api/v2/facts/random?language=en" | jq -r '.text')
fi
if [[ -n "$fact" ]]; then
echo "${SPARKLE_GOLD}✨ Fun Fact: ${fact}${RESET}"
else
echo "${SPARKLE_GOLD}✨ Could not fetch a fun fact at the moment. Check your internet connection or API status.${RESET}"
fi
}
Call the function to display a fun fact on startup
get_api_data() {
local url=$1
local field=$2
# Check if curl succeeds
response=$(curl -s -f "$url" 2>/dev/null)
if [[ $? -ne 0 ]]; then
echo "Error: Failed to fetch data" >&2
return 1
fi
# Check if jq can parse the field
value=$(echo "$response" | jq -r "$field" 2>/dev/null)
if [[ $? -ne 0 || "$value" == "null" ]]; then
echo "Error: Field not found or invalid JSON" >&2
return 1
fi
echo "$value"
}
The key tool here is jq - it's a powerful JSON processor that makes working with JSON in the shell much easier. Your config already shows you know how to use it!