summaryrefslogtreecommitdiff
path: root/bin/statusline
diff options
context:
space:
mode:
authorSam Nystrom <sam@samnystrom.dev>2024-10-15 13:29:10 -0400
committerSam Nystrom <sam@samnystrom.dev>2024-10-15 13:29:10 -0400
commit2c98bbacc8db3b251e1679f9da84cf1f5ed5726a (patch)
tree10d44c9b82d275d66d880ff8ec33992cddda12b5 /bin/statusline
parentc8c79e6c6a5c4bb1e0ba44f309ce5ae612f97e1c (diff)
update ~/bin
Diffstat (limited to 'bin/statusline')
-rwxr-xr-xbin/statusline81
1 files changed, 81 insertions, 0 deletions
diff --git a/bin/statusline b/bin/statusline
new file mode 100755
index 0000000..948e8cb
--- /dev/null
+++ b/bin/statusline
@@ -0,0 +1,81 @@
+#!/usr/bin/env lua5.4
+
+local stdio = require('posix.stdio')
+local poll = require('posix.poll')
+
+function get_output(prog)
+ local f = assert(io.popen(prog))
+ local output = f:read('*a')
+ f:close()
+ return output
+end
+
+function volume()
+ local output = get_output('wpctl get-volume @DEFAULT_AUDIO_SINK@')
+ local muted = output:find('MUTED') ~= nil
+ local _, _, volume = output:find('^Volume: ([0-9.]+)')
+ volume = math.floor(volume * 100)
+
+ local symbol = 'ERROR'
+ if muted then
+ symbol = ' '
+ elseif volume == 0 then
+ symbol = ''
+ elseif volume <= 50 then
+ symbol = ''
+ else
+ symbol = ' '
+ end
+ return string.format('%s %d%%', symbol, volume)
+end
+
+function network()
+ local output = get_output('iwctl station wlan0 get-networks')
+ local _, _, ssid = output:find('>.- (.-) ')
+ return ssid and '󰖩 ' .. ssid or '󰖪 '
+end
+
+local current_brightness = 0
+
+function brightness()
+ return ' ' .. current_brightness .. '%'
+end
+
+function battery()
+ local f = io.open('/sys/class/power_supply/BAT0/capacity', 'r')
+ local capacity = tonumber(f:read('*a'))
+ f:close()
+ f = io.open('/sys/class/power_supply/BAT0/status', 'r')
+ local status = f:read('*a')
+ f:close()
+
+ local symbol = 'ERROR'
+ local i = capacity > 0 and (capacity - 1) // 10 or 0
+ if status == 'Discharging\n' then
+ symbol = ({"󰁺", "󰁻", "󰁼", "󰁽", "󰁾", "󰁿", "󰂀", "󰂁", "󰂂", "󰁹"})[i] -- 󰂃
+ elseif status == 'Charging\n' then
+ symbol = ({"󰢜", "󰂆", "󰂇", "󰂈", "󰢝", "󰂉", "󰢞", "󰂊", "󰂋", "󰂅"})[i]
+ elseif status == 'Full\n' then
+ symbol = "󰂄"
+ end
+ return symbol .. ' ' .. capacity .. '%'
+end
+
+function clock()
+ return os.date(' %b %d %H:%M:%S')
+end
+
+local brightness_file = assert(io.popen('brightctl -l'))
+
+while true do
+ if poll.rpoll(stdio.fileno(brightness_file), 1000) > 0 then
+ current_brightness = tonumber(brightness_file:read('l'))
+ end
+ io.write(string.format('all status %s | %s | %s | %s | %s\n',
+ volume(),
+ network(),
+ brightness(),
+ battery(),
+ clock()
+ ))
+end