Real-time macOS system metrics (power, battery, CPU, temp, fan, memory, network) in your zsh RPROMPT
PowerLens โก
Real-time system metrics in your zsh right prompt โ power, battery, CPU, CPU temp, fan speed, memory, and network I/O, glanceable at a glance.
PowerLens is a lightweight Oh-My-Zsh plugin that embeds live system metrics into RPROMPT. A single background daemon collects all data every 2 seconds; the prompt reads a cached JSON file on each precmd โ adding less than 5ms to prompt render time regardless of how many terminal windows you have open.
Features
| | | |---|---| | 7 metrics | Power (W) ยท Battery % ยท CPU % ยท CPU temp ยฐC ยท Fan speed RPM ยท Memory % ยท Network โโ MB/s | | Two color modes | multi โ 4-level gradient per metric / alert โ neutral until threshold | | Two display modes | compact โ abbreviated values / full โ with units and decimals | | Per-metric toggles | Show or hide any metric independently | | Singleton daemon | N terminal windows โ 1 daemon process, never more | | Crash recovery | Stale data (>10s) auto-detected; daemon restarted silently | | SSH-aware | Daemon skipped in remote shells; shows -- gracefully | | macOS 12+ | Apple Silicon (arm64) and Intel (amd64), no sudo required |
Color Reference
Each metric is colored independently. Thresholds are fully configurable.
Installation
Oh-My-Zsh
git clone https://github.com/luyangkk/powerlens.git \
~/.oh-my-zsh/custom/plugins/powerlens
Add powerlens to your plugins list in ~/.zshrc:
plugins=(... powerlens)
Reload your shell:
source ~/.zshrc
Build from Source
If macOS blocks the pre-compiled binary (Gatekeeper), build it yourself โ requires Go 1.21+:
cd ~/.oh-my-zsh/custom/plugins/powerlens
make install
Or remove the quarantine flag from the pre-built binary:
xattr -d com.apple.quarantine bin/powerlens-fetch-arm64 # Apple Silicon
xattr -d com.apple.quarantine bin/powerlens-fetch-amd64 # Intel
Configuration
All options are set in ~/.zshrc before the plugins=(...) line.
Display
POWERLENS_MODE=compact # compact | full
POWERLENSCOLORMODE=multi # multi | alert
compact (default):
โก38W ๐87% โ34% ๐ก55ยฐ ๐1200 ๐ง 62% โ1.2Mโ3.8M
full:
โก 38.4W ๐ 87% โ 34.2% ๐ก 55.0ยฐC ๐ 1200RPM ๐ง 62.1% โ 1.2MB/s โ 3.8MB/s
Show / Hide Metrics
POWERLENSSHOWBATTERY=true # true | false
POWERLENSSHOWCPU=true
POWERLENSSHOWTEMP=true
POWERLENSSHOWFAN=true # hidden automatically on fanless Macs
POWERLENSSHOWMEM=true
POWERLENSSHOWNET=true
Network Interface
POWERLENSNETIFACE=default # default | wifi | ethernet
| Value | Behavior | |-------|----------| | default | Follows the default route โ whichever interface the OS is routing traffic through (WiFi, Ethernet, or VPN). Icon updates automatically when the active interface changes. | | wifi | Always monitors the Wi-Fi interface. Falls back to ๐ if Wi-Fi is inactive. | | ethernet | Always monitors the first wired Ethernet interface. Falls back to ๐ if none is connected. |
The interface type is shown as an icon prefix on the network display:
- ๐ถ Wi-Fi
- ๐ Ethernet
- ๐ Other / VPN
Refresh Interval
POWERLENS_REFRESH=2 # seconds between daemon polls
Color Thresholds โ multi Mode
Each metric has three thresholds that divide the four color levels (Idle โ Light โ Moderate โ Peak):
# Power (Watts)
POWERLENSTHRESHPOWER_IDLE=10
POWERLENSTHRESHPOWER_LIGHT=30
POWERLENSTHRESHPOWER_MODERATE=50
CPU (%)
POWERLENSTHRESHCPU_IDLE=30
POWERLENSTHRESHCPU_LIGHT=60
POWERLENSTHRESHCPU_MODERATE=85
Memory (%)
POWERLENSTHRESHMEM_IDLE=50
POWERLENSTHRESHMEM_LIGHT=70
POWERLENSTHRESHMEM_MODERATE=85
CPU Temperature (ยฐC)
POWERLENSTHRESHTEMP_IDLE=50
POWERLENSTHRESHTEMP_LIGHT=70
POWERLENSTHRESHTEMP_MODERATE=85
Fan Speed (RPM)
POWERLENSTHRESHFAN_IDLE=2000
POWERLENSTHRESHFAN_LIGHT=3500
POWERLENSTHRESHFAN_MODERATE=5000
Default values are tuned for Apple Silicon MacBooks. Adjust for your machine.
Alert Thresholds โ alert Mode
In alert mode all metrics render in neutral gray (#aaaaaa) until a single threshold is crossed, then switch to orange (#FF9500):
POWERLENSALERTPOWER=50 # W
POWERLENSALERTCPU=80 # %
POWERLENSALERTMEM=85 # %
POWERLENSALERTTEMP=80 # ยฐC
POWERLENSALERTFAN=4000 # RPM
How It Works
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Terminal 1 Terminal 2 Terminal 3 โ
โ (precmd) (precmd) (precmd) โ
โ โ โ โ โ
โ โโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโ โ
โ โ โ
โ read metrics.json โ
โ (only on mtime change) โ
โ โ โ
โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ powerlens-fetch (singleton daemon) โ โ
โ โ ยท IOKit โ power, battery โ โ
โ โ ยท IOKit/SMC โ CPU temp, fan speed โ โ
โ โ ยท gopsutil โ CPU, memory, network โ โ
โ โ ยท writes metrics.json every 2s โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- The daemon is started by the first shell and shared across all subsequent shells (PID file singleton).
- Each
precmdchecks the file modification time โ the JSON is re-parsed only when it actually changes. - The last shell to exit kills the daemon.
Behavior Reference
| Scenario | Display | |----------|---------| | Normal | Metrics with color | | Charging | ๐ replaced with ๐ | | Desktop Mac (no battery) | Battery element hidden | | Daemon crashed | โก --W ๐ --% โ --% ๐ง --% โ -- โ -- โ daemon auto-restarted | | SSH remote shell | Same degraded display, no daemon launched | | First network sample | โ0.0M โ0.0M (no previous snapshot to diff against) | | Fanless Mac (e.g. M1/M2 Air) | Fan metric hidden automatically |
Requirements
- macOS 12 (Monterey) or later
- Zsh 5.8+
- Oh-My-Zsh
Building
make arm64 # Apple Silicon
make amd64 # Intel
make universal # Universal binary (lipo)
make all # Both arm64 + amd64
make clean # Remove built binaries
Open Questions / Roadmap
- [ ] Historical mini-graph using Unicode Braille (
โฃโฃโฃโฃโฃโฃทโฃฟ) in expanded mode - [ ] powerlevel10k geometry integration
- [ ] Multiple battery support (MagSafe + Thunderbolt)
- [ ] CI notarization via GitHub Actions
Contributing
Contributions are welcome! Please read CONTRIBUTING.md before submitting a pull request.
License
MIT โ see LICENSE for details.