# Print information about the battery on this device export def main [] { let device_directory = '/sys/class/power_supply/BAT0' if ( not ($device_directory | path exists) ) { print --stderr $"Could not find ($device_directory). Does this device have a battery? Maybe under another path?" return } let energy_full = (open ([$device_directory energy_full] | path join) | into int) let energy_now = (open ([$device_directory energy_now] | path join) | into int) let current_energy = $energy_now / $energy_full let current_energy_percent = $current_energy * 100 | into int let icon = battery_icon $current_energy_percent print $"($icon) ($current_energy_percent)%" } def battery_icon [ percent: int ] { let index = ( ($percent | math ceil) / 10 | math floor | into int) let icons = [ '󰁺 ' '󰁻 ' '󰁼 ' '󰁽 ' '󰁾 ' '󰁿 ' '󰂀 ' '󰂁' '󰂂 ' '󰁹 ' ] return ($icons | get $index) }