about summary refs log tree commit diff
path: root/.config/luastatus
diff options
context:
space:
mode:
Diffstat (limited to '.config/luastatus')
-rw-r--r--.config/luastatus/alsa.lua23
-rw-r--r--.config/luastatus/battery.lua57
-rw-r--r--.config/luastatus/playerctl.lua43
-rw-r--r--.config/luastatus/separator.lua6
-rw-r--r--.config/luastatus/time-date.lua13
-rw-r--r--.config/luastatus/wireless.lua70
6 files changed, 212 insertions, 0 deletions
diff --git a/.config/luastatus/alsa.lua b/.config/luastatus/alsa.lua
new file mode 100644
index 0000000..fb97270
--- /dev/null
+++ b/.config/luastatus/alsa.lua
@@ -0,0 +1,23 @@
+widget = {
+  plugin = 'alsa',
+  cb = function(t)
+    local symbol = '󰖀'
+    if t.mute then
+      return { full_text = '  󰝟  ', color = '#ed8796' }
+    else
+      local percent = (t.vol.cur - t.vol.min) / (t.vol.max - t.vol.min) * 100
+      if percent <= 30 then
+        symbol = '󰕿'
+      elseif percent >= 70 then
+        symbol = '󰕾'
+      end
+      return { full_text = string.format('%s%3d%%', symbol, math.floor(0.5 + percent)), color = '#b7bdf8' }
+    end
+  end,
+  event = [[
+        local t = ...
+        if t.button == 1 then
+            os.execute('pactl set-sink-mute @DEFAULT_SINK@ toggle &')
+        end
+    ]],
+}
diff --git a/.config/luastatus/battery.lua b/.config/luastatus/battery.lua
new file mode 100644
index 0000000..459599e
--- /dev/null
+++ b/.config/luastatus/battery.lua
@@ -0,0 +1,57 @@
+local function read(path)
+  local f = io.open(path)
+  if not f then return nil end
+  local v = tonumber(f:read('*l'))
+  f:close()
+  return v
+end
+
+widget = {
+  plugin = 'timer',
+  opts = { period = 2 },
+  cb = function()
+    local base        = '/sys/class/power_supply/macsmc-battery/'
+
+    local energy_now  = read(base .. 'energy_now')
+    local energy_full = read(base .. 'energy_full')
+    local status_f    = io.open(base .. 'status')
+
+    if not energy_now or not energy_full or not status_f then
+      return { { full_text = 'bat ?' } }
+    end
+
+    local status = status_f:read('*l')
+    status_f:close()
+
+    local capacity = math.floor(energy_now / energy_full * 100 + 0.5)
+
+    local text_color = '#ffffff'
+    local battery_symbol = ' '
+
+    if capacity < 30 then
+      text_color = '#ed8796'
+      battery_symbol = '󰁼'
+    elseif capacity > 70 then
+      text_color = '#a6da95'
+      battery_symbol = '󰂁'
+    else
+      text_color = '#eed49f'
+      battery_symbol = '󰁾'
+    end
+
+    local symbol = ({
+      Charging    = '󱐋',
+      Discharging = battery_symbol,
+    })[status] or ' '
+
+    return {
+      { full_text = string.format('%s %2d%%', symbol, capacity), color = text_color }
+    }
+  end,
+  event = [[
+        local t = ...
+        if t.button == 1 then
+            os.execute('~/.local/bin/rofi-ppd &')
+        end
+    ]],
+}
diff --git a/.config/luastatus/playerctl.lua b/.config/luastatus/playerctl.lua
new file mode 100644
index 0000000..a3e743c
--- /dev/null
+++ b/.config/luastatus/playerctl.lua
@@ -0,0 +1,43 @@
+local player = 'jellyfin-tui'
+
+widget = {
+  plugin = 'timer',
+  opts = { period = 2 },
+  cb = function()
+
+    local handle = io.popen('playerctl -p ' .. player .. ' status')
+    local playerctl_status = string.sub(handle:read("*a"), 1, -2)
+    handle:close()
+
+    local symbol = '󰏤'
+
+    if (playerctl_status == 'Playing') or (playerctl_status == 'Paused') then
+      local handle = io.popen('playerctl -p ' .. player ..' metadata title')
+      local playerctl_title = string.sub(handle:read("*a"), 1, -2)
+      handle:close()
+
+      local handle = io.popen('playerctl -p ' .. player .. ' metadata artist')
+      local playerctl_artist = string.sub(handle:read("*a"), 1, -2)
+      handle:close()
+
+      if playerctl_status == 'Playing' then
+        symbol = '󰐊'
+      end
+
+      return {
+        { full_text = string.format('%s - %s %s', playerctl_artist, playerctl_title, symbol), color = "#f2cdcd" }
+      }
+    end
+
+    return {
+      { full_text = " "}
+    }
+  end,
+  -- TODO: Figure out if this can stop being hardcoded
+  event = [[
+        local t = ...
+        if t.button == 1 then
+            os.execute('playerctl -p jellyfin-tui play-pause')
+        end
+    ]],
+}
diff --git a/.config/luastatus/separator.lua b/.config/luastatus/separator.lua
new file mode 100644
index 0000000..1a3ef01
--- /dev/null
+++ b/.config/luastatus/separator.lua
@@ -0,0 +1,6 @@
+widget = {
+  plugin = 'fs',
+  cb = function()
+    return { full_text = "|", color = "#333333" }
+  end,
+}
diff --git a/.config/luastatus/time-date.lua b/.config/luastatus/time-date.lua
new file mode 100644
index 0000000..8d5bfe7
--- /dev/null
+++ b/.config/luastatus/time-date.lua
@@ -0,0 +1,13 @@
+local months = {'Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Sep', 'Out', 'Nov', 'Dez'}
+local days = {'Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', ''}
+
+widget = {
+    plugin = 'timer',
+    cb = function()
+        local d = os.date('*t')
+        return {
+            {full_text = string.format('%s %d %s', days[d.wday] , d.day, months[d.month])},
+            {full_text = string.format('%02d:%02d ', d.hour, d.min)},
+        }
+    end,
+}
diff --git a/.config/luastatus/wireless.lua b/.config/luastatus/wireless.lua
new file mode 100644
index 0000000..e3d53d7
--- /dev/null
+++ b/.config/luastatus/wireless.lua
@@ -0,0 +1,70 @@
+local MIN_DBM, MAX_DBM = -90, -20
+local COLOR_DIM = '#709080'
+
+local function clamp(x, lo, hi)
+  if x < lo then return lo end
+  if x > hi then return hi end
+  return x
+end
+
+local function make_wifi_level(dbm)
+  dbm = clamp(dbm, MIN_DBM, MAX_DBM)
+
+  -- Normalize to [0, 1]
+  local t = (dbm - MIN_DBM) / (MAX_DBM - MIN_DBM)
+
+  local level
+  if t < 0.25 then
+    level = '󰢿'
+  elseif t < 0.50 then
+    level = '󰢼'
+  elseif t < 0.75 then
+    level = '󰢽'
+  else
+    level = '󰢾'
+  end
+
+  return {
+    full_text = level,
+    color = COLOR_DIM,
+  }
+end
+
+widget = {
+  plugin = 'network-linux',
+  opts = {
+    wireless = true,
+    timeout = 10,
+  },
+  cb = function(t)
+    if not t then
+      return nil
+    end
+    local r = {}
+    for iface, params in pairs(t) do
+      if params.wireless then
+        if params.wireless.ssid then
+          r[#r + 1] = {
+            full_text = params.wireless.ssid,
+            color = COLOR_DIM,
+          }
+        end
+        if params.wireless.signal_dbm then
+          r[#r + 1] = make_wifi_level(params.wireless.signal_dbm)
+        end
+      elseif iface ~= 'lo' and (params.ipv4 or params.ipv6) then
+        r[#r + 1] = {
+          full_text = string.format('[%s]', iface),
+          color = COLOR_DIM,
+        }
+      end
+    end
+    return r
+  end,
+  event = [[
+        local t = ...
+        if t.button == 1 then
+            os.execute('~/.local/bin/rofi-wifimenu &')
+        end
+    ]],
+}