-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbattery.nu
More file actions
31 lines (27 loc) · 750 Bytes
/
battery.nu
File metadata and controls
31 lines (27 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/env nu
# battery.nu
# Get battery info
export def main [
--interface (-i): string = "BAT0" # Battery interface
--long (-l) # All fields
] {
let info = (get-info -i $interface)
if $long { $info } else { $info | select name charging capacity }
}
export def get-info [
--interface (-i): string = "BAT0" # Battery interface
] {
open $"/sys/class/power_supply/($interface)/uevent" |
from csv -n --separator '=' |
update column1 { str replace -a "POWER_SUPPLY_" "" | str snake-case } |
transpose -r |
into record |
each { str trim } |
insert charging { |value| $value.status == "Charging" }
}
export def level [] {
get-info | get capacity
}
export def notify [] {
notify-send $"Battery: (level)%"
}