Skip to main content
The hardware module provides cross-platform functions to query hardware information including CPU, GPU, memory, disk, and battery status.
Platform support varies by function. Most functions support Linux, macOS, and BSD variants. Functions return “unknown” when information is unavailable.

CPU information

Functions for querying CPU details.
Get the CPU model name.
cpu=$(hardware::cpu::name)
echo "CPU: $cpu"
# Intel Core i7-9750H
Automatically strips marketing terms like (TM), (R), “Processor”, “Dual-Core”, etc.Returns: CPU model name or “unknown”Platforms: Linux, macOS, FreeBSD, OpenBSD, NetBSD
Get the number of physical CPU cores.
cores=$(hardware::cpu::core_count::physical)
echo "$cores physical cores"
Returns: Number of physical coresPlatforms: Linux, macOS, FreeBSD, OpenBSD, NetBSD
Get the number of logical CPU cores (threads).
threads=$(hardware::cpu::core_count::logical)
echo "$threads logical cores"
Returns: Number of logical cores (including hyperthreading)Platforms: Linux, macOS, FreeBSD, OpenBSD, NetBSD
Alias for hardware::cpu::core_count::logical().
total=$(hardware::cpu::core_count::total)
Returns: Total thread count
Alias for hardware::cpu::core_count::logical().
threads=$(hardware::cpu::thread_count)
Returns: Thread count
Get the current CPU frequency in MHz.
freq=$(hardware::cpu::frequencyMHz)
echo "CPU running at ${freq}MHz"
Tries multiple sources: scaling_cur_freq, bios_limit, scaling_max_freq, cpuinfo_max_freq.Returns: CPU frequency in MHz or “unknown”Platforms: Linux, macOS, FreeBSD, OpenBSD, NetBSD
Get the CPU temperature in Celsius.
temp=$(hardware::cpu::temp)
echo "CPU temperature: ${temp}°C"
Returns: Temperature in Celsius with one decimal place, or “unknown”Platforms: Linux, FreeBSD, DragonFly, OpenBSD, NetBSD
macOS requires third-party tools like osx-cpu-temp.

GPU information

Functions for querying GPU details.
Get the GPU model name.
gpu=$(hardware::gpu)
echo "GPU: $gpu"
# NVIDIA GeForce RTX 3060
Tries multiple detection methods: nvidia-smi, lspci, glxinfo (Linux); system_profiler (macOS); pciconf (FreeBSD).Returns: GPU model name or “unknown”Platforms: Linux, macOS, FreeBSD, DragonFly
Get GPU VRAM in megabytes.
vram=$(hardware::gpu::vramMB)
echo "VRAM: ${vram}MB"
Returns: VRAM in MB or “unknown”Platforms: Linux (nvidia-smi, lspci), macOS

Memory (RAM) information

Functions for querying system memory.
Get total RAM in megabytes.
total=$(hardware::ram::totalSpaceMB)
echo "Total RAM: ${total}MB"
Returns: Total RAM in MBPlatforms: Linux, macOS, FreeBSD, OpenBSD, NetBSD
Get free RAM in megabytes.
free=$(hardware::ram::freeSpaceMB)
echo "Free RAM: ${free}MB"
Returns: Available RAM in MBPlatforms: Linux, macOS, FreeBSD, OpenBSD, NetBSD
Get used RAM in megabytes.
used=$(hardware::ram::usedSpaceMB)
echo "Used RAM: ${used}MB"
Returns: Used RAM in MBPlatforms: Linux, macOS, FreeBSD, OpenBSD, NetBSD

Disk information

Functions for querying disk space.
Get total disk space in gigabytes.
total=$(hardware::disk::totalSpaceGB)
echo "Total disk: ${total}GB"

# Check specific mount point
home_total=$(hardware::disk::totalSpaceGB "/home")
Parameters:
  • path - Path to check (default: /)
Returns: Total disk space in GB
Get free disk space in gigabytes.
free=$(hardware::disk::freeSpaceGB)
echo "Free disk: ${free}GB"
Parameters:
  • path - Path to check (default: /)
Returns: Free disk space in GB
Get used disk space in gigabytes.
used=$(hardware::disk::usedSpaceGB)
echo "Used disk: ${used}GB"
Parameters:
  • path - Path to check (default: /)
Returns: Used disk space in GB
Get disk usage percentage.
usage=$(hardware::disk::usagePercent)
echo "Disk usage: ${usage}%"

if (( usage > 90 )); then
    echo "Warning: Disk almost full!"
fi
Parameters:
  • path - Path to check (default: /)
Returns: Usage percentage (0-100)

Battery information

Functions for querying battery status (laptops).
Get battery charge percentage.
charge=$(hardware::battery::percent)
echo "Battery: ${charge}%"
Returns: Battery percentage (0-100) or “unknown”Platforms: Linux, macOS
Get battery status.
status=$(hardware::battery::status)
echo "Battery: $status"
# Charging, Discharging, Full, or Unknown
Returns: Battery status or “unknown”Platforms: Linux, macOS
Check if battery is currently charging.
hardware::battery::is_charging && echo "Plugged in"
Returns: Exit code 0 if chargingPlatforms: Linux, macOS

Usage example

source compiled.sh

echo "=== System Hardware Information ==="

# CPU
echo "CPU: $(hardware::cpu::name)"
echo "Cores: $(hardware::cpu::core_count::physical) physical, $(hardware::cpu::core_count::logical) logical"
echo "Frequency: $(hardware::cpu::frequencyMHz)MHz"
echo "Temperature: $(hardware::cpu::temp)°C"

# GPU
echo "GPU: $(hardware::gpu)"
echo "VRAM: $(hardware::gpu::vramMB)MB"

# Memory
total_ram=$(hardware::ram::totalSpaceMB)
used_ram=$(hardware::ram::usedSpaceMB)
free_ram=$(hardware::ram::freeSpaceMB)
echo "RAM: ${used_ram}MB used / ${total_ram}MB total (${free_ram}MB free)"

# Disk
total_disk=$(hardware::disk::totalSpaceGB)
used_disk=$(hardware::disk::usedSpaceGB)
usage=$(hardware::disk::usagePercent)
echo "Disk: ${used_disk}GB used / ${total_disk}GB total (${usage}% usage)"

# Battery (if available)
if battery=$(hardware::battery::percent); then
    status=$(hardware::battery::status)
    echo "Battery: ${battery}% ($status)"
fi

Build docs developers (and LLMs) love