POWER-SUPPLY(1)

πŸ“¦ version 0.1.0, in alpine 3.24

πŸ’– POWER-SUPPLY(1) πŸ’–

okay so bestie, welcome to power-supply(1) β€” the little script that spills all the tea about your power supply devices πŸ”‹βœ¨ she reads straight out of /sys and tells you everything, no cap.


🌸 NAME 🌸

power-supply β€” query properties of power supply devices πŸ’…


✨ SYNOPSIS ✨

power-supply
power-supply [-r] -d <dev> [prop-options] [-d <dev> [prop-options]]...
[-- <cmd...>]
power-supply (-V | -h)

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the vibe check πŸ‘‡

If you run power-supply with no arguments at all, it prints a list of AC Adapters and Batteries in the format <dev-type>:<dev-idx> <dev-name>. iconic.

  • dev-type is adapter (AC Adapter) or battery,
  • dev-idx is a 0-based ordinal number of the device type,
  • dev-name is the name of the device (directory) in /sys/class/power_supply.

Then, power-supply invoked with -d and the property option(s) without an argument, prints value(s) of the specified property/ies 🫢.

And power-supply invoked with -d and the property option(s) with a value argument (conditions), tests if all the specified properties satisfy the specified condition πŸ‘€ β€” like a vibe check but for your battery.

so if cmd is given:

  • if conditions are satisfied: cmd is executed πŸƒβ€β™€οΈ
  • else: exits with status 0

else (when cmd is not given):

  • if conditions are satisfied: exits with status 0
  • else exits with status 1 😭

Also, heads up: property values are converted to lowercase and spaces replaced with hyphens (-), unless --raw is specified. little glow-up, you know how it is πŸ’…


πŸŽ€ OPTIONS πŸŽ€

  • -d <dev>[:<idx>], --dev <dev>[:<idx>] β€” Either dev-name of the device under /sys/class/power_supply or dev-type of the device, optionally followed by a colon and dev-idx β€” a 0-based ordinal number (this is the one you want when multiple devices of the same type exist, iykyk).

The dev-type is one of:

  • adapter, ac, or a for an AC Adapter (Mains),
  • battery, bat or b for a Battery.
  • -r, --raw β€” Output (or compare) property values as-is, no lowercasing, no space-to-- swap. raw and unfiltered, main character energy πŸ”₯
  • --all β€” Print all properties of the device in the format: <prop> <value>. it's giving full transparency πŸ’–
  • --<prop> β€” Print value of the device property prop (hyphens will be replaced with underscores).
  • --<prop> [!]<value> | <start>-<end> β€” Specify condition on the property prop β€” it can be a value (<prop> = <value>), a value prefixed with ! (<prop> != <value>) or an inclusive integer range (<prop> -ge <start> && <prop> -le <end>) πŸ‘‘
  • -V, --version β€” Print script name & version and exit.
  • -h, --help β€” Show the help message and exit.

πŸ”Œ AC Adapter options

  • -s [[!]<value>], --status [[!]<value>] β€” Alias for --online. Valid values are: offline, online (or 0, 1 if --raw). πŸ’‘

πŸ“ Battery options

  • -s [[!]<value>] β€” Alias for --status. Valid values are: unknown, charging, discharging, not-charging, full.
  • -c [[!]<value> | <start>-<end>] β€” Alias for --capacity. Valid value is integer between 0 and 100.
  • -C [[!]<value>] β€” Alias for --capacity-level. Valid values are: unknown, critical, low, normal, high, full.

πŸ’€ EXIT CODES πŸ’€

  • 0 β€” Clean exit, no error has encountered. slay ✨
  • 1 β€” The conditions were not satisfied (see DESCRIPTION for more information). πŸ™ˆ
  • 100 β€” Invalid usage.
  • 101 β€” The device was not found or has unsupported type.
  • 102 β€” The device does not provide the requested property or failed to read it.
If cmd is given and the conditions are met, power-supply exits with the exit status of the cmd. fr fr, she hands the mic over 🎀

🧚 FILES 🧚

  • /sys/class/power_supply/* β€” The directory where the devices and properties are read from. that's the source of truth bestie πŸ“

🌈 EXAMPLES 🌈

List all AC Adapters and Batteries found in /sys/class/power_supply

$ power-supply
adapter:0 AC
battery:0 CMB1
battery:1 hidpp_battery_38

Print all properties of Battery 0

$ power-supply -d battery:0 --all
alarm 0
capacity 30
capacity_level normal
cycle_count 19
energy_full 56570000
energy_full_design 57020000
energy_now 17080000
manufacturer smp
model_name 5b10w139
...

Print the current capacity of Battery 0

$ power-supply -d bat --capacity
95

Exit with status 0 if AC Adapter 0 is online, 1 if it's offline

$ power-supply -d adapter -s online

Run command doas zzz -H if AC Adapter 0 is offline and Battery 0 has capacity below 11 %

$ power-supply -d ac -s offline -d bat -c 0-10 -- doas zzz -H

like, the range 0-10 is inclusive so 10 counts too, okurrr πŸ’œ


πŸ‘‘ AUTHORS πŸ‘‘

Jakub Jirutka


🎀 REPORTING BUGS 🎀

Report bugs to the project's issue tracker at https://github.com/jirutka/acpi-utils/issues. don't be shy, she wants to hear from you 🫢


and that's the whole page bestie πŸ’– β€” written up and dated 2021-10-19, packed into the POWER-SUPPLY(1) page, from the acpi-utils fam. go forth and query those power supplies 😭✨🌷

πŸ“¦ where this page comes from