Skip to content

Commit

Permalink
sketchybar: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Feb 27, 2024
1 parent 6fbeab1 commit e00732e
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 42 deletions.
6 changes: 3 additions & 3 deletions modules/home/desktop/addons/sketchybar/lua-config/colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ local colors = {
rosewater = 0xfff4dbd6,
}

local random_cat_color = {
colors.random_cat_color = {
colors.blue, colors.lavender, colors.sapphire, colors.sky, colors.teal,
colors.green, colors.yellow, colors.peach, colors.maroon, colors.red,
colors.mauve, colors.pink, colors.flamingo, colors.rosewater,
}

local function getRandomCatColor()
return random_cat_color[math.random(1, #random_cat_color)]
colors.getRandomCatColor = function()
return colors.random_cat_color[math.random(1, #colors.random_cat_color)]
end

return colors
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
local icons = require("icons")
local settings = require("settings")
local colors = require("colors")
local percent = 0

local wifi = sbar.add("item", "wifi", {
position = "right",
Expand Down Expand Up @@ -41,10 +39,6 @@ local wifi_details = sbar.add("item", "wifi_details", {
},
})

local function isempty(s)
return s == nil or s == ''
end

local function wifi_update()
-- Get current WiFi info
sbar.exec(
Expand All @@ -56,7 +50,7 @@ local function wifi_update()
-- Extract current transmission rate
local currTx = string.match(currentWifi, "lastTxRate: (.-)\n")

if isempty(ssid) then
if IS_EMPTY(ssid) then
wifi:set({ icon = { string = icons.wifi_off } })
wifi_details:set({ label = "No WiFi" })
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ for i = 1, 10, 1 do
padding_left = 7,
padding_right = 7,
color = colors.white,
highlight_color = colors.red,
highlight_color = colors.getRandomCatColor(),
},
padding_left = 2,
padding_right = 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ local memory = require("items.stats.memory")
local disk = require("items.stats.disk")
local network = require("items.stats.network")

sbar.add("event", "hide_stats")
sbar.add("event", "show_stats")
sbar.add("event", "toggle_stats")

separator:subscribe("hide_stats", function()
cpu:set({ drawing = false })
memory:set({ drawing = false })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
local settings = require('settings')
local colors = require('colors')
local icons = require('icons')

local separator_right = sbar.add("item", "separator_right", {
background = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,6 @@ local ical_details = sbar.add("item", "ical_details", {
click_script = "sketchybar --set $NAME popup.drawing=off",
})

local function split(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
table.insert(t, str)
end
return t
end

-- Update function
ical:subscribe({ "routine", "forced" }, function()
-- Constants
Expand All @@ -74,7 +63,7 @@ ical:subscribe({ "routine", "forced" }, function()
end

-- Parse and organize events
for _, line in ipairs(split(events, "\n")) do
for _, line in ipairs(STR_SPLIT(events, "\n")) do
local title, time = line:match("^(.-)%s*%%(.*)$")

if title and time then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,6 @@ local weather_details = sbar.add("item", "weather_details", {
click_script = "sketchybar --set $NAME popup.drawing=off",
})

local function split(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
table.insert(t, str)
end
return t
end

-- Update function
weather_temp:subscribe({ "routine", "forced", "weather_update" }, function()
-- Reset popup state
Expand All @@ -74,7 +63,7 @@ weather_temp:subscribe({ "routine", "forced", "weather_update" }, function()
-- Fetch events from calendar
sbar.exec("wttrbar --fahrenheit --ampm", function(forecast)
-- Extract icon and temperature
for i, value in ipairs(split(forecast.text)) do
for i, value in ipairs(STR_SPLIT(forecast.text)) do
-- first part of response is icon
if i == 1 then
weather_icon:set({ icon = { string = value } })
Expand All @@ -93,7 +82,7 @@ weather_temp:subscribe({ "routine", "forced", "weather_update" }, function()
end
end

for _, line in ipairs(split(forecast.tooltip, "\n")) do
for _, line in ipairs(STR_SPLIT(forecast.tooltip, "\n")) do
if string.find(line, "<b>") then
local replacedString = string.gsub(line, "<b>", "")
replacedString = string.gsub(replacedString, "</b>", "")
Expand Down
25 changes: 25 additions & 0 deletions modules/home/desktop/addons/sketchybar/lua-config/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,28 @@ POPUP_TOGGLE = function(name)
print("Toggling " .. name)
sbar.exec("sketchybar --set " .. name .. " popup.drawing=toggle")
end

POPUP_OFF = function(name)
print("Hiding " .. name)
sbar.exec("sketchybar --set " .. name .. " popup.drawing=off")
end

POPUP_ON = function(name)
print("Showing " .. name)
sbar.exec("sketchybar --set " .. name .. " popup.drawing=on")
end

IS_EMPTY = function(s)
return s == nil or s == ''
end

STR_SPLIT = function(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
table.insert(t, str)
end
return t
end

0 comments on commit e00732e

Please sign in to comment.