aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2025-05-14 22:50:39 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2025-05-14 22:50:39 +0530
commit05da0e10926d4ade3b10a55999a0ed1b797caf65 (patch)
tree97cf6a33e5ce90d57e6894b748b1e18ad690643e
parentf9c150cf57732bb7b42c6b2a5db70039161f8c6d (diff)
added luastatus configHEADmaster
-rw-r--r--.config/fish/config.fish2
-rw-r--r--.config/luastatus-scripts-dwm/backlight.lua18
-rw-r--r--.config/luastatus-scripts-dwm/battery.lua53
-rw-r--r--.config/luastatus-scripts-dwm/bluetooth.lua177
-rw-r--r--.config/luastatus-scripts-dwm/cpu-temperature.lua45
-rw-r--r--.config/luastatus-scripts-dwm/cpu-usage.lua7
-rw-r--r--.config/luastatus-scripts-dwm/file-contents.lua7
-rw-r--r--.config/luastatus-scripts-dwm/mem-usage.lua7
-rw-r--r--.config/luastatus-scripts-dwm/time-date.lua58
-rw-r--r--.config/luastatus-scripts-dwm/wireless.lua56
-rwxr-xr-x.scripts/luastatus-dwm7
-rwxr-xr-x.xprofile10
12 files changed, 441 insertions, 6 deletions
diff --git a/.config/fish/config.fish b/.config/fish/config.fish
index 46d9e35..910fd0e 100644
--- a/.config/fish/config.fish
+++ b/.config/fish/config.fish
@@ -43,5 +43,5 @@ if status is-interactive
# disable greeting
set fish_greeting
fish_ssh_agent
- cowsay -f sus "amogus" | lolcat
+ cowsay -f sus "kernel panic? Or was it sabotage?" | lolcat
end
diff --git a/.config/luastatus-scripts-dwm/backlight.lua b/.config/luastatus-scripts-dwm/backlight.lua
new file mode 100644
index 0000000..3fa1818
--- /dev/null
+++ b/.config/luastatus-scripts-dwm/backlight.lua
@@ -0,0 +1,18 @@
+-- Note that this widget only shows backlight level when it changes.
+widget = luastatus.require_plugin('backlight-linux').widget{
+ cb = function(level)
+ if level ~= nil then
+ local brightness = level * 100
+
+ local icon = "󰃠"
+ if brightness < 30 then
+ icon = "󰃞"
+ elseif brightness < 70 then
+ icon = "󰃟"
+ end
+
+ io.write(level * 100)
+ return string.format('%s %3.0f%%', icon, brightness)
+ end
+ end,
+}
diff --git a/.config/luastatus-scripts-dwm/battery.lua b/.config/luastatus-scripts-dwm/battery.lua
new file mode 100644
index 0000000..6155fd4
--- /dev/null
+++ b/.config/luastatus-scripts-dwm/battery.lua
@@ -0,0 +1,53 @@
+widget = luastatus.require_plugin('battery-linux').widget{
+ period = 2,
+ cb = function(t)
+ icon = ""
+ if t.status == "Discharging" then
+ if t.capacity < 10 then
+ icon = "󰁺"
+ elseif t.capacity < 20 then
+ icon = "󰁻"
+ elseif t.capacity < 30 then
+ icon = "󰁼"
+ elseif t.capacity < 40 then
+ icon = "󰁽"
+ elseif t.capacity < 50 then
+ icon = "󰁾"
+ elseif t.capacity < 60 then
+ icon = "󰁿"
+ elseif t.capacity < 70 then
+ icon = "󰂀"
+ elseif t.capacity < 80 then
+ icon = "󰂁"
+ elseif t.capacity < 90 then
+ icon = "󰂂"
+ else
+ icon = "󰁹"
+ end
+ else
+ if t.capacity < 10 then
+ icon = "󰢜"
+ elseif t.capacity < 20 then
+ icon = "󰂆"
+ elseif t.capacity < 30 then
+ icon = "󰂇"
+ elseif t.capacity < 40 then
+ icon = "󰂈"
+ elseif t.capacity < 50 then
+ icon = "󰢝"
+ elseif t.capacity < 60 then
+ icon = "󰂉"
+ elseif t.capacity < 70 then
+ icon = "󰢞"
+ elseif t.capacity < 80 then
+ icon = "󰂊"
+ elseif t.capacity < 90 then
+ icon = "󰂋"
+ else
+ icon = "󰂅"
+ end
+ end
+
+ return string.format('%s %3d%%', icon, t.capacity)
+ end,
+}
diff --git a/.config/luastatus-scripts-dwm/bluetooth.lua b/.config/luastatus-scripts-dwm/bluetooth.lua
new file mode 100644
index 0000000..f4807a0
--- /dev/null
+++ b/.config/luastatus-scripts-dwm/bluetooth.lua
@@ -0,0 +1,177 @@
+-- A widget to display currently connected and paired bluetooth devices.
+-- To change output format modify reprint_devices function.
+
+separator = " "
+
+-- Object paths look like /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/somethingsomething
+function get_device_mac_address(device_object_path)
+ return device_object_path:gsub("/.*/dev_", ""):gsub("/.*", ""):gsub("_", ":")
+end
+
+-- For reference bluetoothctl devices output looks like that:
+-- Device XX:XX:XX:XX:XX:XX JBL T450BT
+-- Device YY:YY:YY:YY:YY:YY Redmi 8
+--
+-- Function returns mac addresses of all devices.
+function get_devices()
+ local devices = {}
+ local handle = io.popen(string.format("bluetoothctl devices"))
+ for line in handle:lines() do
+ table.insert(devices, string.match(line, "Device ([%x:]+)"))
+ end
+ handle:close()
+ return devices
+end
+
+function get_power_state()
+ local handle = io.popen(string.format("bluetoothctl show"))
+ local power_state = false
+ for line in handle:lines() do
+ local state = string.match(line, "^%s*PowerState:%s*(%w+)")
+ if state then
+ if state == "off" then
+ power_state = false
+ else
+ power_state = true
+ end
+ break
+ end
+ end
+ handle:close()
+
+ return power_state
+end
+
+-- For reference bluetoothctl info output looks like that:
+-- Device XX:XX:XX:XX:XX:XX (public)
+-- Name: JBL T450BT
+-- Alias: JBL T450BT
+-- Class: 0xFFFFFFFF
+-- Icon: audio-card
+-- Paired: yes
+-- Trusted: yes
+-- Blocked: no
+-- Connected: yes
+-- LegacyPairing: no
+-- UUID: Headset (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
+-- ...
+-- UUID: Handsfree (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
+--
+-- Given this input function returns a following table:
+-- [alias] string JBL T450BT
+-- [blocked] boolean false
+-- [class] string 0x00240404
+-- [connected] boolean true
+-- [icon] string audio
+-- [legacypairing] boolean false
+-- [name] string JBL T450BT
+-- [paired] boolean true
+-- [trusted] boolean true
+function get_device_info(mac_address)
+ if mac_address == nil then
+ mac_address = ""
+ end
+ local device_info = {}
+ local handle = io.popen(string.format("bluetoothctl info %s", mac_address))
+ for line in handle:lines() do
+ local key, value = string.match(line, "(%w+): (.*)")
+ -- Filter junk
+ if key ~= "UUID" and key ~= nil and value ~= nil then
+ key = string.lower(key)
+ if key ~= "name" and key ~= "alias" and key ~= "icon" then
+ if value == "yes" then
+ value = true
+ end
+ if value == "no" then
+ value = false
+ end
+ end
+ device_info[key] = value
+ end
+ end
+ handle:close()
+ return device_info
+end
+
+devices = {}
+
+function reprint_devices(power_state)
+ if power_state then
+ local t = {}
+ for mac_address, device in pairs(devices) do
+ table.insert(t, string.format("󰂱 %s", device["alias"]))
+ end
+ if next(t) == nil then
+ return "󰂯"
+ else
+ return table.concat(t, separator)
+ end
+ else
+ return "󰂲"
+ end
+end
+
+widget = {
+ plugin = "dbus",
+ opts = {
+ greet = true,
+ -- https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/device-api.txt
+ signals = {
+ {
+ sender = "org.bluez",
+ interface = "org.freedesktop.DBus.Properties",
+ signal = "PropertiesChanged",
+ arg0 = "org.bluez.Device1",
+ bus = "system"
+ }, {
+ sender = "org.bluez",
+ interface = "org.freedesktop.DBus.Properties",
+ signal = "PropertiesChanged",
+ arg0 = "org.bluez.Adapter1",
+ bus = "system"
+ }
+ }
+ },
+ cb = function(t)
+ local power_state = false
+ if t.what == "hello" then
+ power_state = get_power_state()
+ local mac_addresses = get_devices()
+ for i, mac_address in pairs(mac_addresses) do
+ local device = get_device_info(mac_address)
+ if device["connected"] and device["paired"] then
+ devices[mac_address] = device
+ end
+ end
+ elseif t.what == "signal" then
+ -- For reference message from dbus looks like that:
+ -- table
+ -- [1] string org.bluez.Device1
+ -- [2] table
+ -- [2] [1] table
+ -- [2] [1] [1] string SomethingSomething
+ -- [2] [1] [2] boolean false
+ -- [2] [2] table
+ -- [2] [2] [1] string Connected
+ -- [2] [2] [2] boolean true
+ -- [3] table
+ if t.signal == "PropertiesChanged" then
+ power_state = get_power_state()
+ for i, message in pairs(t.parameters[2]) do
+ if message[1] == "Connected" or message[1] == "Paired" then
+ local mac_address = get_device_mac_address(t.object_path)
+ if message[2] then
+ local device = get_device_info(mac_address)
+ if device["paired"] then
+ devices[mac_address] = device
+ end
+ else
+ devices[mac_address] = nil
+ end
+ end
+ end
+ end
+ end
+ return reprint_devices(power_state)
+ end
+}
diff --git a/.config/luastatus-scripts-dwm/cpu-temperature.lua b/.config/luastatus-scripts-dwm/cpu-temperature.lua
new file mode 100644
index 0000000..38b25d0
--- /dev/null
+++ b/.config/luastatus-scripts-dwm/cpu-temperature.lua
@@ -0,0 +1,45 @@
+paths = {}
+do
+ -- Replace "*" with "[^0]*" in the first glob if your zeroeth thermal sensor is virtual (and
+ -- thus useless):
+ local f = assert(io.popen([[
+ #for file in /sys/class/thermal/thermal_zone*/temp
+ #do
+ # [ -e "$file" ] || break
+ # printf "%s\n" "$file"
+ #done
+for dir in /sys/class/hwmon/*
+do
+ [ -e "$dir" ] || break
+ IFS= read -r monitor_name < "$dir"/name
+ # You may have more than one hardware monitor enabled
+ # If so, disable ones that are not needed
+ case "$monitor_name" in
+ coretemp|fam15h_power|k10temp)
+ printf "%s\n" "$dir"/temp*_input
+ esac
+done
+]]))
+ for p in f:lines() do
+ table.insert(paths, p)
+ end
+ f:close()
+end
+
+widget = {
+ plugin = 'timer',
+ opts = {period = 2},
+ cb = function()
+ for _, p in ipairs(paths) do
+ local f = assert(io.open(p, 'r'))
+ local temp = f:read('*number') / 1000
+ local icon = ""
+ if temp > 55 then
+ icon = ""
+ elseif temp > 80 then
+ icon = ""
+ end
+ return string.format('%s %.0f°C', icon, temp)
+ end
+ end,
+}
diff --git a/.config/luastatus-scripts-dwm/cpu-usage.lua b/.config/luastatus-scripts-dwm/cpu-usage.lua
new file mode 100644
index 0000000..90c75ed
--- /dev/null
+++ b/.config/luastatus-scripts-dwm/cpu-usage.lua
@@ -0,0 +1,7 @@
+widget = luastatus.require_plugin('cpu-usage-linux').widget{
+ cb = function(usage)
+ if usage ~= nil then
+ return string.format('%5.1f%%', usage * 100)
+ end
+ end,
+}
diff --git a/.config/luastatus-scripts-dwm/file-contents.lua b/.config/luastatus-scripts-dwm/file-contents.lua
new file mode 100644
index 0000000..1ed02ac
--- /dev/null
+++ b/.config/luastatus-scripts-dwm/file-contents.lua
@@ -0,0 +1,7 @@
+widget = luastatus.require_plugin('file-contents-linux').widget{
+ filename = "/tmp/bar_status",
+ cb = function(f)
+ -- show the first line of the file
+ return string.format(" %s", f:read('*line'))
+ end,
+}
diff --git a/.config/luastatus-scripts-dwm/mem-usage.lua b/.config/luastatus-scripts-dwm/mem-usage.lua
new file mode 100644
index 0000000..ad69c2e
--- /dev/null
+++ b/.config/luastatus-scripts-dwm/mem-usage.lua
@@ -0,0 +1,7 @@
+widget = luastatus.require_plugin('mem-usage-linux').widget{
+ timer_opts = {period = 2},
+ cb = function(t)
+ local used_kb = t.total.value - t.avail.value
+ return string.format(' %3.2f GiB', used_kb / 1024 / 1024)
+ end,
+}
diff --git a/.config/luastatus-scripts-dwm/time-date.lua b/.config/luastatus-scripts-dwm/time-date.lua
new file mode 100644
index 0000000..8fce7a1
--- /dev/null
+++ b/.config/luastatus-scripts-dwm/time-date.lua
@@ -0,0 +1,58 @@
+months = {'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'}
+wday = {'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'}
+widget = {
+ plugin = 'timer',
+ cb = function()
+ local d = os.date('*t')
+
+ if d.hour < 12 then
+ suffix = "a.m."
+ else
+ suffix = "p.m."
+ d.hour = d.hour - 12
+ end
+
+ local date_suffix = "th"
+ if not (d.day % 100 >= 11 and d.day % 100 <= 13) then
+ local last_digit = d.day % 10
+ if last_digit == 1 then
+ date_suffix = "st"
+ elseif last_digit == 2 then
+ date_suffix = "nd"
+ elseif last_digit == 3 then
+ date_suffix = "rd"
+ end
+ end
+
+ local time_icon = ""
+ if d.hour == 0 or d.hour == 12 then
+ time_icon = "󱑖"
+ elseif d.hour == 1 then
+ time_icon = "󱑋"
+ elseif d.hour == 2 then
+ time_icon = "󱑌"
+ elseif d.hour == 3 then
+ time_icon = "󱑍"
+ elseif d.hour == 4 then
+ time_icon = "󱑎"
+ elseif d.hour == 5 then
+ time_icon = "󱑏"
+ elseif d.hour == 6 then
+ time_icon = "󱑐"
+ elseif d.hour == 7 then
+ time_icon = "󱑑"
+ elseif d.hour == 8 then
+ time_icon = "󱑒"
+ elseif d.hour == 9 then
+ time_icon = "󱑓"
+ elseif d.hour == 10 then
+ time_icon = "󱑔"
+ elseif d.hour == 11 then
+ time_icon = "󱑕"
+ end
+
+ return {
+ string.format('󰃭 %d%s %s %d (%s) %s %d:%02d %s ', d.day, date_suffix, months[d.month], d.year, wday[d.wday], time_icon, d.hour, d.min, suffix),
+ }
+ end,
+}
diff --git a/.config/luastatus-scripts-dwm/wireless.lua b/.config/luastatus-scripts-dwm/wireless.lua
new file mode 100644
index 0000000..34300ad
--- /dev/null
+++ b/.config/luastatus-scripts-dwm/wireless.lua
@@ -0,0 +1,56 @@
+local MIN_DBM, MAX_DBM = -90, -20
+local NGAUGE = 5
+local COLOR_DIM = '#709080'
+
+local function round(x)
+ return math.floor(x + 0.5)
+end
+
+local function make_wifi_gauge(dbm)
+ if dbm < MIN_DBM then dbm = MIN_DBM end
+ if dbm > MAX_DBM then dbm = MAX_DBM end
+ local nbright = round(NGAUGE * (1 - 0.7 * (MAX_DBM - dbm) / (MAX_DBM - MIN_DBM)))
+
+ if nbright == 0 then
+ return "󰤭"
+ elseif nbright == 1 then
+ return "󰤯"
+ elseif nbright == 2 then
+ return "󰤟"
+ elseif nbright == 3 then
+ return "󰤢"
+ elseif nbright == 4 then
+ return "󰤥"
+ else
+ return "󰤨"
+ end
+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
+ local x = ""
+ if params.wireless.signal_dbm then
+ x = x .. make_wifi_gauge(params.wireless.signal_dbm) .. " "
+ end
+ if params.wireless.ssid then
+ x = x .. params.wireless.ssid
+ end
+ return x
+ elseif iface ~= 'lo' and (params.ipv4 or params.ipv6) then
+ r[#r + 1] = string.format('[%s]', iface)
+ end
+ end
+ return r
+ end,
+}
diff --git a/.scripts/luastatus-dwm b/.scripts/luastatus-dwm
new file mode 100755
index 0000000..370ae2d
--- /dev/null
+++ b/.scripts/luastatus-dwm
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+echo "" > /tmp/bar_status
+
+cd ~/.config/luastatus-scripts-dwm/
+
+luastatus -b dwm -B separator=' ' file-contents.lua wireless.lua mem-usage.lua cpu-usage.lua cpu-temperature.lua bluetooth.lua battery.lua time-date.lua backlight.lua
diff --git a/.xprofile b/.xprofile
index 837554b..24fe3a5 100755
--- a/.xprofile
+++ b/.xprofile
@@ -16,8 +16,8 @@ nitrogen --restore &
# so i know it's turned on without opening the lid
brightnessctl --device hp::hddprotect set 100%
-# autostart apps only for XMonad
if [[ "$DESKTOP_SESSION" = "dwm" ]]; then
+ luastatus-dwm &
# screensetup.sh &
# autostart apps
@@ -31,8 +31,8 @@ if [[ "$DESKTOP_SESSION" = "dwm" ]]; then
# blueman-applet &
# flameshot &
- while :; do
- xsetroot -name "BAT: $(acpi | awk '{print $4}' | sed s/,//) | $(date '+%Y-%m-%d %H:%M:%S')"
- sleep 1
- done &
+ # while :; do
+ # xsetroot -name "BAT: $(acpi | awk '{print $4}' | sed s/,//) | $(date '+%Y-%m-%d %H:%M:%S')"
+ # sleep 1
+ # done &
fi