luyangkk
powerlens
Goโœจ New

Real-time macOS system metrics (power, battery, CPU, temp, fan, memory, network) in your zsh RPROMPT

Last updated Jul 5, 2026
58
Stars
3
Forks
0
Issues
0
Stars/day
Attention Score
49
Language breakdown
No language data available.
โ–ธ Files click to expand
README

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.

License: MIT Platform: macOS 12+ Shell: zsh CI

PowerLens Demo

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

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 precmd checks 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.

๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท luyangkk/powerlens ยท Updated daily from GitHub