diff options
| author | Jérémy <PixiBixi@users.noreply.github.com> | 2025-08-16 21:28:32 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-16 21:28:32 +0200 |
| commit | 7504f22a0ce649ab577a6232f2a673ea98d773a6 (patch) | |
| tree | eb575613efa434cffa064aa200f13cd4ea392607 /plugins | |
| parent | 92a03105acd514fe81fb3a1f581ff0daeb11cead (diff) | |
| download | zsh-7504f22a0ce649ab577a6232f2a673ea98d773a6.tar.gz zsh-7504f22a0ce649ab577a6232f2a673ea98d773a6.tar.bz2 zsh-7504f22a0ce649ab577a6232f2a673ea98d773a6.zip | |
feat(battery): add wattage for macOS (#13258)
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/battery/README.md | 6 | ||||
| -rw-r--r-- | plugins/battery/battery.plugin.zsh | 10 |
2 files changed, 15 insertions, 1 deletions
diff --git a/plugins/battery/README.md b/plugins/battery/README.md index 73fcb693e..07e4e0b16 100644 --- a/plugins/battery/README.md +++ b/plugins/battery/README.md @@ -19,6 +19,12 @@ For example: BATTERY_CHARGING="⚡️" ``` +You can see the power of your charger using the following setting (MacOS only) + +```zsh +BATTERY_SHOW_WATTS=true +``` + ## Requirements - On Linux, you must have the `acpi` or `acpitool` commands installed on your operating system. diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index 7977e4d04..c7618f6b3 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -17,8 +17,13 @@ # Modified to add support for OpenBSD # ########################################### +: ${BATTERY_SHOW_WATTS:=false} + if [[ "$OSTYPE" = darwin* ]]; then + function get_charger_power() { + echo "$(ioreg -rc AppleSmartBattery | grep -o '"Watts"=[0-9]\+' | head -1 | grep -o '[0-9]\+')W " + } function battery_is_charging() { ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ Yes' } @@ -58,7 +63,10 @@ if [[ "$OSTYPE" = darwin* ]]; then fi echo "%{$fg[$color]%}[${battery_pct}%%]%{$reset_color%}" else - echo "${BATTERY_CHARGING-⚡️}" + if [[ "${BATTERY_SHOW_WATTS}" = "true" ]] ; then + watts=$(get_charger_power) + fi + echo "${watts}${BATTERY_CHARGING-⚡️}" fi } |
