about summary refs log tree commit diff
path: root/modules/workstation/windowing/sway/status_command.in
blob: 19b87b8e0777e1f0747b7dd82a24060a4da091a1 (plain) (blame)
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
32
33
34
35
36
37
38
39
#! @execline@/bin/execlineb

loopwhilex

elglob -0 bats /sys/class/power_supply/BAT*

# We need to capture the whole status line, and then echo it all at
# once, to work around https://github.com/swaywm/sway/issues/3857.
backtick -i -n line {
  foreground {
    forx bat { $bats }
    importas -i -u bat bat

    foreground {
      backtick -i -n status { cat ${bat}/status }
      importas -i -u status status

      ifelse { test $status = Charging }
      { printf "↑" }

      if { test $status = Discharging }
      printf "↓"
    }

    foreground {
      redirfd -r 0 ${bat}/capacity
      tr -d "\n"
    }

    foreground { printf "%%  " }
  }

  foreground { date "+%Y-%m-%d %H:%M:%S" }
}
importas -i -u line line

if { echo $line }

sleep 1