Skip to content

Instantly share code, notes, and snippets.

@adde88
Created September 7, 2025 11:15
Show Gist options
  • Save adde88/67a26969a53e0d72955ef5bc6314c72f to your computer and use it in GitHub Desktop.
Save adde88/67a26969a53e0d72955ef5bc6314c72f to your computer and use it in GitHub Desktop.
A Zsh function to display live system information for a Raspberry Pi 3B+
# Start of this file that gets sourced from .zshrc
#
pinfo() {
# Color Codes for a beautiful output
C_DEFAULT="\e[0m"
C_BOLD="\e[1m"
C_RED="\e[31m"
C_GREEN="\e[32m"
C_YELLOW="\e[33m"
C_BLUE="\e[34m"
C_MAGENTA="\e[35m"
C_CYAN="\e[36m"
C_LIGHT_GRAY="\e[37m"
# Emojis for fun and clarity
E_TEMP="🌡️"
E_CLOCK="⚡"
E_RAM="💾"
E_VOLT="💡"
E_STORAGE="📦"
E_UPTIME="🕒"
E_NETWORK="🌐"
E_THROTTLE="⚠️"
E_PI="🍓"
# --- Data Collection ---
# CPU Temperature (in Celsius)
# Reads the raw value from the thermal zone file and divides by 1000.
cpu_temp_raw=$(cat /sys/class/thermal/thermal_zone0/temp)
cpu_temp_c=$(printf "%.1f" $(($cpu_temp_raw/1000)))
# GPU Temperature (in Celsius)
# Uses the vcgencmd utility, specific to Raspberry Pi firmware.
gpu_temp_c=$(vcgencmd measure_temp | egrep -o '[0-9]*\.[0-9]*')
# CPU Clock Speed (Current, Min, Max in MHz)
# Reads from the CPU frequency scaling driver files.
cpu_speed_cur=$(($(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)/1000))
cpu_speed_min=$(($(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq)/1000))
cpu_speed_max=$(($(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq)/1000))
# Core Voltage
# vcgencmd provides the core voltage for CPU/GPU.
core_volt=$(vcgencmd measure_volts core | cut -d "=" -f2)
# Memory Usage (RAM)
# Uses 'free' command and pipes to 'awk' for easy parsing.
ram_info=$(free -m | awk 'NR==2{printf "Used: %s MB (%.2f%%) / Total: %s MB", $3, $3*100/$2, $2 }')
# SD Card Storage Usage
# Uses 'df' (disk free) for the root partition.
disk_info=$(df -h / | awk 'NR==2{printf "Used: %s (%s) / Total: %s", $3, $5, $2}')
# System Uptime
# The 'uptime' command provides this directly.
sys_uptime=$(uptime -p)
# Network Information (IP Address)
# Gets the primary IP address.
ip_addr=$(hostname -I | cut -d' ' -f1)
# Throttling Status
# This is crucial for Pi health. It indicates under-voltage or overheating.
throttled_raw=$(vcgencmd get_throttled)
throttled_code=${throttled_raw#*=}
# Decode the throttling status code. A value of '0x0' is good.
if [[ "$throttled_code" != "0x0" ]]; then
throttled_status="${C_RED}${C_BOLD}YES! Check power/cooling.${C_DEFAULT} (Code: $throttled_code)"
else
throttled_status="${C_GREEN}No${C_DEFAULT}"
fi
# --- Output Display ---
# Get terminal width for dynamic line drawing
term_width=$(tput cols)
line=""
for ((i=1; i<=$term_width; i++)); do
line="${line}─"
done
# Header
printf "\n${C_BOLD}${C_MAGENTA}"
echo " .~~. .~~. $E_PI Raspberry Pi 3B+ Live System Info"
echo " '. \\ ' ' / .' "
printf "${C_DEFAULT}"
printf "${C_LIGHT_GRAY}%s${C_DEFAULT}\n" "$line"
# System Stats
printf " ${E_TEMP} ${C_BOLD}${C_YELLOW}%-18s${C_DEFAULT} CPU: ${C_CYAN}%s°C${C_DEFAULT} | GPU: ${C_CYAN}%s°C${C_DEFAULT}\n" "Temperature" "$cpu_temp_c" "$gpu_temp_c"
printf " ${E_CLOCK} ${C_BOLD}${C_YELLOW}%-18s${C_DEFAULT} Current: ${C_CYAN}%s MHz${C_DEFAULT} (Min: %s MHz, Max: %s MHz)\n" "CPU Clock" "$cpu_speed_cur" "$cpu_speed_min" "$cpu_speed_max"
printf " ${E_VOLT} ${C_BOLD}${C_YELLOW}%-18s${C_DEFAULT} ${C_CYAN}%s${C_DEFAULT}\n" "Core Voltage" "$core_volt"
printf " ${E_RAM} ${C_BOLD}${C_YELLOW}%-18s${C_DEFAULT} ${C_CYAN}%s${C_DEFAULT}\n" "Memory (RAM)" "$ram_info"
printf " ${E_STORAGE} ${C_BOLD}${C_YELLOW}%-18s${C_DEFAULT} ${C_CYAN}%s${C_DEFAULT}\n" "SD Card Storage" "$disk_info"
printf " ${E_UPTIME} ${C_BOLD}${C_YELLOW}%-18s${C_DEFAULT} ${C_CYAN}%s${C_DEFAULT}\n" "Uptime" "${sys_uptime/up /}"
printf " ${E_NETWORK} ${C_BOLD}${C_YELLOW}%-18s${C_DEFAULT} ${C_CYAN}%s${C_DEFAULT}\n" "IP Address" "$ip_addr"
printf " ${E_THROTTLE} ${C_BOLD}${C_YELLOW}%-18s${C_DEFAULT} ${throttled_status}\n" "Throttled"
# Footer
printf "${C_LIGHT_GRAY}%s${C_DEFAULT}\n\n" "$line"
}
# Rest of your file below should be as normal, if you have something already there
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment