mirror of
				https://github.com/ohmyzsh/ohmyzsh.git
				synced 2025-11-04 13:21:19 +08:00 
			
		
		
		
	feat(battery): add wattage for macOS (#13258)
This commit is contained in:
		
							parent
							
								
									92a03105ac
								
							
						
					
					
						commit
						7504f22a0c
					
				@ -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.
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user