format lua files

This commit is contained in:
Ray Andrew 2025-04-08 23:41:12 -05:00
parent 1efeda4130
commit b9eea0f86b
Signed by: rayandrew
SSH key fingerprint: SHA256:XYrYrxF0Z3A72n8P/p6mqPRNQZT22F88XcLsG+kX4xw
14 changed files with 636 additions and 627 deletions

View file

@ -1,24 +1,26 @@
local function with_alpha(color, alpha) local function with_alpha(color, alpha)
if alpha > 1.0 or alpha < 0.0 then return color end if alpha > 1.0 or alpha < 0.0 then
return (color & 0x00ffffff) | (math.floor(alpha * 255.0) << 24) return color
end
return (color & 0x00ffffff) | (math.floor(alpha * 255.0) << 24)
end end
return { return {
black = 0xff181819, black = 0xff181819,
white = 0xffd3b58d, white = 0xffd3b58d,
red = 0xffF92672, red = 0xffF92672,
blue = 0xff66D9EF, blue = 0xff66D9EF,
grey = 0xff7f8490, grey = 0xff7f8490,
transparent = 0x00000000, transparent = 0x00000000,
bar = { bar = {
bg = 0xff072626, bg = 0xff072626,
border = 0xffFD971F, border = 0xffFD971F,
}, },
popup = { popup = {
bg = with_alpha(0xff072626, 0.6), bg = with_alpha(0xff072626, 0.6),
border = 0xffFD971F, border = 0xffFD971F,
}, },
with_alpha = with_alpha, with_alpha = with_alpha,
} }

View file

@ -1,92 +1,92 @@
local settings = require("settings") local settings = require("settings")
local icons = { local icons = {
sf_symbols = { sf_symbols = {
plus = "􀅼", plus = "􀅼",
loading = "􀖇", loading = "􀖇",
apple = "􀣺", apple = "􀣺",
gear = "􀍟", gear = "􀍟",
cpu = "􀫥", cpu = "􀫥",
clipboard = "􀉄", clipboard = "􀉄",
switch = { switch = {
on = "􁏮", on = "􁏮",
off = "􁏯", off = "􁏯",
}, },
volume = { volume = {
_100="􀊩", _100 = "􀊩",
_66="􀊧", _66 = "􀊧",
_33="􀊥", _33 = "􀊥",
_10="􀊡", _10 = "􀊡",
_0="􀊣", _0 = "􀊣",
}, },
battery = { battery = {
_100 = "􀛨", _100 = "􀛨",
_75 = "􀺸", _75 = "􀺸",
_50 = "􀺶", _50 = "􀺶",
_25 = "􀛩", _25 = "􀛩",
_0 = "􀛪", _0 = "􀛪",
charging = "􀢋" charging = "􀢋",
}, },
wifi = { wifi = {
upload = "􀄨", upload = "􀄨",
download = "􀄩", download = "􀄩",
connected = "􀙇", connected = "􀙇",
disconnected = "􀙈", disconnected = "􀙈",
router = "􁓤", router = "􁓤",
}, },
media = { media = {
back = "􀊊", back = "􀊊",
forward = "􀊌", forward = "􀊌",
play_pause = "􀊈", play_pause = "􀊈",
}, },
}, },
-- Alternative NerdFont icons -- Alternative NerdFont icons
nerdfont = { nerdfont = {
plus = "", plus = "",
loading = "", loading = "",
apple = "", apple = "",
gear = "", gear = "",
cpu = "", cpu = "",
clipboard = "Missing Icon", clipboard = "Missing Icon",
switch = { switch = {
on = "󱨥", on = "󱨥",
off = "󱨦", off = "󱨦",
}, },
volume = { volume = {
_100="", _100 = "",
_66="", _66 = "",
_33="", _33 = "",
_10="", _10 = "",
_0="", _0 = "",
}, },
battery = { battery = {
_100 = "", _100 = "",
_75 = "", _75 = "",
_50 = "", _50 = "",
_25 = "", _25 = "",
_0 = "", _0 = "",
charging = "" charging = "",
}, },
wifi = { wifi = {
upload = "", upload = "",
download = "", download = "",
connected = "󰖩", connected = "󰖩",
disconnected = "󰖪", disconnected = "󰖪",
router = "Missing Icon" router = "Missing Icon",
}, },
media = { media = {
back = "", back = "",
forward = "", forward = "",
play_pause = "", play_pause = "",
}, },
}, },
} }
if not (settings.icons == "NerdFont") then if not (settings.icons == "NerdFont") then
return icons.sf_symbols return icons.sf_symbols
else else
return icons.nerdfont return icons.nerdfont
end end

View file

@ -7,11 +7,15 @@ local settings = require("settings")
local app_icons = require("app_icons") local app_icons = require("app_icons")
local function getAllWorkspaces() local function getAllWorkspaces()
return utils.sbarExecP("aerospace list-workspaces --all --format '%{workspace}%{monitor-appkit-nsscreen-screens-id}%{monitor-id}%{monitor-name}' --json") return utils.sbarExecP(
"aerospace list-workspaces --all --format '%{workspace}%{monitor-appkit-nsscreen-screens-id}%{monitor-id}%{monitor-name}' --json"
)
end end
local function getVisibleWorkspaces() local function getVisibleWorkspaces()
return utils.sbarExecP("aerospace list-workspaces --visible --monitor all --format '%{workspace}%{monitor-appkit-nsscreen-screens-id}%{monitor-id}%{monitor-name}' --json") return utils.sbarExecP(
"aerospace list-workspaces --visible --monitor all --format '%{workspace}%{monitor-appkit-nsscreen-screens-id}%{monitor-id}%{monitor-name}' --json"
)
end end
local function getAllWindows() local function getAllWindows()
@ -21,17 +25,17 @@ local function getAllWindows()
end end
local function getMonitorId(obj) local function getMonitorId(obj)
if obj["monitor-name"] then if obj["monitor-name"] then
if obj["monitor-name"] == "ZOWIE XL LCD" then if obj["monitor-name"] == "ZOWIE XL LCD" then
return "2" return "2"
elseif obj["monitor-name"] == "LG ULTRAWIDE" then elseif obj["monitor-name"] == "LG ULTRAWIDE" then
return "1" return "1"
end end
end end
if obj["monitor-appkit-nsscreen-screens-id"] then if obj["monitor-appkit-nsscreen-screens-id"] then
return obj["monitor-appkit-nsscreen-screens-id"] return obj["monitor-appkit-nsscreen-screens-id"]
end end
return obj["monitor-id"] return obj["monitor-id"]
end end
local spaces = {} local spaces = {}
@ -43,41 +47,41 @@ local state = {
} }
function getState() function getState()
local newstate = { local newstate = {
workspaces = {}, workspaces = {},
} }
for workspaceid, space in pairs(spaces) do for workspaceid, space in pairs(spaces) do
newstate.workspaces[workspaceid] = { newstate.workspaces[workspaceid] = {
monitor = 0, monitor = 0,
active = false, active = false,
empty = true, empty = true,
apps = {}, apps = {},
appicons = "", appicons = "",
} }
end end
return Promise.all({ getAllWorkspaces(), getVisibleWorkspaces(), getAllWindows() }):thenCall(function(values) return Promise.all({ getAllWorkspaces(), getVisibleWorkspaces(), getAllWindows() }):thenCall(function(values)
local all, visible, apps = values[1], values[2], values[3] local all, visible, apps = values[1], values[2], values[3]
for _, workspace in ipairs(all) do for _, workspace in ipairs(all) do
local workspaceid = workspace["workspace"] local workspaceid = workspace["workspace"]
newstate.workspaces[workspaceid]["id"] = workspaceid newstate.workspaces[workspaceid]["id"] = workspaceid
newstate.workspaces[workspaceid]["monitor"] = getMonitorId(workspace) newstate.workspaces[workspaceid]["monitor"] = getMonitorId(workspace)
end end
for _, workspace in ipairs(visible) do for _, workspace in ipairs(visible) do
local workspaceid = workspace["workspace"] local workspaceid = workspace["workspace"]
newstate.workspaces[workspaceid]["active"] = true newstate.workspaces[workspaceid]["active"] = true
end end
for _, window in ipairs(apps) do for _, window in ipairs(apps) do
local workspaceid = window["workspace"] local workspaceid = window["workspace"]
local appname = window["app-name"] local appname = window["app-name"]
newstate.workspaces[workspaceid]["apps"][appname] = true newstate.workspaces[workspaceid]["apps"][appname] = true
newstate.workspaces[workspaceid]["empty"] = false newstate.workspaces[workspaceid]["empty"] = false
end end
for workspaceid, workspacestate in pairs(newstate.workspaces) do for workspaceid, workspacestate in pairs(newstate.workspaces) do
local appkeys = {} local appkeys = {}
for app in pairs(workspacestate["apps"]) do for app in pairs(workspacestate["apps"]) do
table.insert(appkeys, app) table.insert(appkeys, app)
@ -92,11 +96,11 @@ function getState()
else else
workspacestate["appicons"] = "" workspacestate["appicons"] = ""
end end
-- print(utils.dump(workspacestate)) -- print(utils.dump(workspacestate))
end end
return newstate return newstate
end) end)
end end
local function updateState() local function updateState()
@ -110,22 +114,21 @@ local function updateState()
return Promise.reject("State is already updating") return Promise.reject("State is already updating")
end end
local function highlightSpace(space, space_padding, space_bracket, selected) local function highlightSpace(space, space_padding, space_bracket, selected)
space:set({ space:set({
drawing = true, drawing = true,
icon = { highlight = selected, }, icon = { highlight = selected },
label = { highlight = selected }, label = { highlight = selected },
-- background = { border_color = selected and colors.white or colors.bg2 } -- background = { border_color = selected and colors.white or colors.bg2 }
}) })
space_padding:set({ space_padding:set({
drawing = true, drawing = true,
}) })
if space_bracket then if space_bracket then
space_bracket:set({ space_bracket:set({
-- background = { border_color = selected and colors.grey or colors.bg2 }, -- background = { border_color = selected and colors.grey or colors.bg2 },
}) })
end end
end end
local function onActiveSpaceChange(env) local function onActiveSpaceChange(env)
@ -142,7 +145,7 @@ local function onActiveSpaceChange(env)
sbar.animate("tanh", 10, function() sbar.animate("tanh", 10, function()
highlightSpace(space, space_padding, nil, true) highlightSpace(space, space_padding, nil, true)
if state.workspaces[last_workspace]["monitor"] == state.workspaces[focused_workspace]["monitor"] then if state.workspaces[last_workspace]["monitor"] == state.workspaces[focused_workspace]["monitor"] then
highlightSpace(prev_space, prev_space_padding, nil, false) highlightSpace(prev_space, prev_space_padding, nil, false)
end end
end) end)
@ -150,41 +153,41 @@ local function onActiveSpaceChange(env)
end end
local function syncState() local function syncState()
sbar.animate("tanh", 10, function() sbar.animate("tanh", 10, function()
for workspaceid, workspacestate in pairs(state.workspaces) do for workspaceid, workspacestate in pairs(state.workspaces) do
if not workspacestate["empty"] then if not workspacestate["empty"] then
spaces[workspaceid]:set({ spaces[workspaceid]:set({
drawing = true, drawing = true,
display = workspacestate["monitor"], display = workspacestate["monitor"],
-- label = { -- label = {
-- string = workspaceid, -- string = workspaceid,
-- highlight = workspacestate["active"], -- highlight = workspacestate["active"],
-- }, -- },
-- icon = { -- icon = {
-- string = workspaceid, -- string = workspaceid,
-- color = colors.white, -- color = colors.white,
-- highlight = workspacestate["active"], -- highlight = workspacestate["active"],
-- }, -- },
label = { label = {
string = workspacestate["appicons"], string = workspacestate["appicons"],
highlight = workspacestate["active"], highlight = workspacestate["active"],
}, },
icon = { icon = {
highlight = workspacestate["active"], highlight = workspacestate["active"],
}, },
}) })
space_paddings[workspaceid]:set({ drawing = true }) space_paddings[workspaceid]:set({ drawing = true })
else else
-- These should be hidden -- These should be hidden
spaces[workspaceid]:set({ spaces[workspaceid]:set({
drawing = false, drawing = false,
display = workspacestate["monitor"], display = workspacestate["monitor"],
label = workspacestate["appicons"], label = workspacestate["appicons"],
}) })
space_paddings[workspaceid]:set({ drawing = false }) space_paddings[workspaceid]:set({ drawing = false })
end end
end end
end) end)
end end
local function updateStateAndSync() local function updateStateAndSync()
@ -192,57 +195,58 @@ local function updateStateAndSync()
end end
function setup() function setup()
getAllWorkspaces():thenCall(function(workspaces) getAllWorkspaces()
for _, workspace in ipairs(workspaces) do :thenCall(function(workspaces)
local workspaceid = workspace["workspace"] for _, workspace in ipairs(workspaces) do
local display = getMonitorId(workspace) local workspaceid = workspace["workspace"]
local display = getMonitorId(workspace)
local space = sbar.add("item", "space." .. workspaceid, { local space = sbar.add("item", "space." .. workspaceid, {
drawing = false, -- default to not showing the space -- we'll show if it has windows or is activated drawing = false, -- default to not showing the space -- we'll show if it has windows or is activated
updates = "when_shown", updates = "when_shown",
display = display, display = display,
icon = { icon = {
string = workspaceid, string = workspaceid,
color = colors.white, color = colors.white,
highlight_color = colors.red, highlight_color = colors.red,
}, },
label = { label = {
padding_right = 12, padding_right = 12,
color = colors.grey, color = colors.grey,
highlight_color = colors.white, highlight_color = colors.white,
font = "sketchybar-app-font:Regular:14.0", font = "sketchybar-app-font:Regular:14.0",
y_offset = -1, y_offset = -1,
-- drawing = false -- drawing = false
}, },
padding_left = 1, padding_left = 1,
padding_right = 1, padding_right = 1,
click_script = "aerospace workspace " .. workspaceid, click_script = "aerospace workspace " .. workspaceid,
}) })
spaces[workspaceid] = space spaces[workspaceid] = space
local padding = sbar.add("space", "space.padding." .. space.name, { local padding = sbar.add("space", "space.padding." .. space.name, {
drawing = false, drawing = false,
updates = "when_shown", updates = "when_shown",
display = display, display = display,
script = "", script = "",
width = settings.space_paddings, width = settings.space_paddings,
}) })
space_paddings[workspaceid] = padding space_paddings[workspaceid] = padding
end end
end) end)
:thenCall(function() :thenCall(function()
local space_window_observer = sbar.add("item", { local space_window_observer = sbar.add("item", {
drawing = false, drawing = false,
updates = true, updates = true,
}) })
space_window_observer:subscribe("aerospace_workspace_change", onActiveSpaceChange) space_window_observer:subscribe("aerospace_workspace_change", onActiveSpaceChange)
space_window_observer:subscribe("space_windows_change", updateStateAndSync) space_window_observer:subscribe("space_windows_change", updateStateAndSync)
space_window_observer:subscribe("system_woke", updateStateAndSync) space_window_observer:subscribe("system_woke", updateStateAndSync)
space_window_observer:subscribe("front_app_switched", updateStateAndSync) space_window_observer:subscribe("front_app_switched", updateStateAndSync)
end) end)
:thenCall(updateStateAndSync) :thenCall(updateStateAndSync)
end end
setup() setup()

View file

@ -6,21 +6,21 @@ local settings = require("settings")
sbar.add("item", { width = 5 }) sbar.add("item", { width = 5 })
local apple = sbar.add("item", { local apple = sbar.add("item", {
icon = { icon = {
font = { size = 16.0 }, font = { size = 16.0 },
string = icons.apple, string = icons.apple,
padding_right = settings.paddings, padding_right = settings.paddings,
padding_left = 0, padding_left = 0,
}, },
label = { drawing = false }, label = { drawing = false },
background = { background = {
color = colors.bg2, color = colors.bg2,
-- border_color = colors.black, -- border_color = colors.black,
-- border_width = 1 -- border_width = 1
}, },
padding_left = 1, padding_left = 1,
padding_right = 1, padding_right = 1,
click_script = "sk-menus -s 0" click_script = "sk-menus -s 0",
}) })
-- Double border for apple using a single item bracket -- Double border for apple using a single item bracket

View file

@ -1,45 +1,44 @@
local icons = require("icons") local icons = require("icons")
local battery = sbar.add("item", { local battery = sbar.add("item", {
position = "right", position = "right",
icon = { icon = {
font = { font = {
style = "Regular", style = "Regular",
size = 19.0, size = 19.0,
} },
}, },
label = { drawing = false }, label = { drawing = false },
update_freq = 120, update_freq = 120,
}) })
local function battery_update() local function battery_update()
sbar.exec("pmset -g batt", function(batt_info) sbar.exec("pmset -g batt", function(batt_info)
local icon = "!" local icon = "!"
if (string.find(batt_info, 'AC Power')) then if string.find(batt_info, "AC Power") then
icon = icons.battery.charging icon = icons.battery.charging
else else
local found, _, charge = batt_info:find("(%d+)%%") local found, _, charge = batt_info:find("(%d+)%%")
if found then if found then
charge = tonumber(charge) charge = tonumber(charge)
end end
if found and charge > 80 then if found and charge > 80 then
icon = icons.battery._100 icon = icons.battery._100
elseif found and charge > 60 then elseif found and charge > 60 then
icon = icons.battery._75 icon = icons.battery._75
elseif found and charge > 40 then elseif found and charge > 40 then
icon = icons.battery._50 icon = icons.battery._50
elseif found and charge > 20 then elseif found and charge > 20 then
icon = icons.battery._25 icon = icons.battery._25
else else
icon = icons.battery._0 icon = icons.battery._0
end end
end end
battery:set({ icon = icon }) battery:set({ icon = icon })
end) end)
end end
battery:subscribe({ "routine", "power_source_change", "system_woke" }, battery_update)
battery:subscribe({"routine", "power_source_change", "system_woke"}, battery_update)

View file

@ -19,7 +19,7 @@ local cal = sbar.add("item", {
update_freq = 30, update_freq = 30,
padding_left = 0, padding_left = 0,
padding_right = 0, padding_right = 0,
click_script = "open -n -a Calendar", click_script = "open -n -a Calendar",
-- background = { -- background = {
-- color = colors.bg1, -- color = colors.bg1,
-- border_color = colors.bar.border, -- border_color = colors.bar.border,
@ -45,6 +45,6 @@ sbar.add("item", { position = "right", width = settings.group_paddings })
cal:subscribe({ "forced", "routine", "system_woke" }, function(env) cal:subscribe({ "forced", "routine", "system_woke" }, function(env)
cal:set({ cal:set({
icon = os.date("􀉉 %B %d %a"), icon = os.date("􀉉 %B %d %a"),
label = os.date("􀐫 %I:%M %p") -- 12-hour format with AM/PM label = os.date("􀐫 %I:%M %p"), -- 12-hour format with AM/PM
}) })
end) end)

View file

@ -6,64 +6,64 @@ local settings = require("settings")
-- the cpu load data, which is fired every 2.0 seconds. -- the cpu load data, which is fired every 2.0 seconds.
sbar.exec("killall sk-cpu-load >/dev/null; sk-cpu-load cpu_update 2.0") sbar.exec("killall sk-cpu-load >/dev/null; sk-cpu-load cpu_update 2.0")
local cpu = sbar.add("graph", "widgets.cpu" , 42, { local cpu = sbar.add("graph", "widgets.cpu", 42, {
position = "right", position = "right",
graph = { color = colors.blue }, graph = { color = colors.blue },
background = { background = {
height = 22, height = 22,
color = { alpha = 0 }, color = { alpha = 0 },
border_color = { alpha = 0 }, border_color = { alpha = 0 },
drawing = true, drawing = true,
}, },
icon = { string = icons.cpu }, icon = { string = icons.cpu },
label = { label = {
string = "cpu ??%", string = "cpu ??%",
font = { font = {
family = settings.font.numbers, family = settings.font.numbers,
style = settings.font.style_map["Bold"], style = settings.font.style_map["Bold"],
size = 9.0, size = 9.0,
}, },
align = "right", align = "right",
padding_right = 0, padding_right = 0,
width = 0, width = 0,
y_offset = 4 y_offset = 4,
}, },
padding_right = settings.paddings + 6 padding_right = settings.paddings + 6,
}) })
cpu:subscribe("cpu_update", function(env) cpu:subscribe("cpu_update", function(env)
-- Also available: env.user_load, env.sys_load -- Also available: env.user_load, env.sys_load
local load = tonumber(env.total_load) local load = tonumber(env.total_load)
cpu:push({ load / 100. }) cpu:push({ load / 100. })
local color = colors.blue local color = colors.blue
if load > 30 then if load > 30 then
if load < 60 then if load < 60 then
color = colors.yellow color = colors.yellow
elseif load < 80 then elseif load < 80 then
color = colors.orange color = colors.orange
else else
color = colors.red color = colors.red
end end
end end
cpu:set({ cpu:set({
graph = { color = color }, graph = { color = color },
label = "cpu " .. env.total_load .. "%", label = "cpu " .. env.total_load .. "%",
}) })
end) end)
cpu:subscribe("mouse.clicked", function(env) cpu:subscribe("mouse.clicked", function(env)
sbar.exec("open -a 'Activity Monitor'") sbar.exec("open -a 'Activity Monitor'")
end) end)
-- Background around the cpu item -- Background around the cpu item
sbar.add("bracket", "widgets.cpu.bracket", { cpu.name }, { sbar.add("bracket", "widgets.cpu.bracket", { cpu.name }, {
background = { color = colors.bg1 } background = { color = colors.bg1 },
}) })
-- Background around the cpu item -- Background around the cpu item
sbar.add("item", "widgets.cpu.padding", { sbar.add("item", "widgets.cpu.padding", {
position = "right", position = "right",
width = settings.group_paddings width = settings.group_paddings,
}) })

View file

@ -1,28 +1,28 @@
local settings = require("settings") local settings = require("settings")
local front_app = sbar.add("item", { local front_app = sbar.add("item", {
icon = { icon = {
drawing = false drawing = false,
}, },
label = { label = {
font = { font = {
style = settings.font.style_map["Bold"], style = settings.font.style_map["Bold"],
size = 12.0, size = 12.0,
} },
} },
}) })
front_app:subscribe("front_app_switched", function(env) front_app:subscribe("front_app_switched", function(env)
front_app:set({ front_app:set({
label = { label = {
string = env.INFO:upper() string = env.INFO:upper(),
} },
}) })
-- Or equivalently: -- Or equivalently:
-- sbar.set(env.NAME, { -- sbar.set(env.NAME, {
-- label = { -- label = {
-- string = env.INFO -- string = env.INFO
-- } -- }
-- }) -- })
end) end)

View file

@ -3,74 +3,76 @@ local icons = require("icons")
local settings = require("settings") local settings = require("settings")
local menu_watcher = sbar.add("item", { local menu_watcher = sbar.add("item", {
drawing = false, drawing = false,
updates = false, updates = false,
}) })
local space_menu_swap = sbar.add("item", { local space_menu_swap = sbar.add("item", {
drawing = false, drawing = false,
updates = true, updates = true,
}) })
sbar.add("event", "swap_menus_and_spaces") sbar.add("event", "swap_menus_and_spaces")
local max_items = 15 local max_items = 15
local menu_items = {} local menu_items = {}
for i = 1, max_items, 1 do for i = 1, max_items, 1 do
local menu = sbar.add("item", "menu." .. i, { local menu = sbar.add("item", "menu." .. i, {
padding_left = settings.paddings, padding_left = settings.paddings,
padding_right = settings.paddings, padding_right = settings.paddings,
drawing = false, drawing = false,
icon = { drawing = false }, icon = { drawing = false },
label = { label = {
font = { font = {
style = settings.font.style_map[i == 1 and "Heavy" or "Semibold"] style = settings.font.style_map[i == 1 and "Heavy" or "Semibold"],
}, },
padding_left = 6, padding_left = 6,
padding_right = 6, padding_right = 6,
}, },
click_script = "sk-menus -s " .. i, click_script = "sk-menus -s " .. i,
}) })
menu_items[i] = menu menu_items[i] = menu
end end
sbar.add("bracket", { '/menu\\..*/' }, { sbar.add("bracket", { "/menu\\..*/" }, {
background = { color = colors.bg1 } background = { color = colors.bg1 },
}) })
local menu_padding = sbar.add("item", "menu.padding", { local menu_padding = sbar.add("item", "menu.padding", {
drawing = false, drawing = false,
width = 5 width = 5,
}) })
local function update_menus(env) local function update_menus(env)
sbar.exec("sk-menus -l", function(menus) sbar.exec("sk-menus -l", function(menus)
sbar.set('/menu\\..*/', { drawing = false }) sbar.set("/menu\\..*/", { drawing = false })
menu_padding:set({ drawing = true }) menu_padding:set({ drawing = true })
id = 1 id = 1
for menu in string.gmatch(menus, '[^\r\n]+') do for menu in string.gmatch(menus, "[^\r\n]+") do
if id < max_items then if id < max_items then
menu_items[id]:set( { label = menu, drawing = true } ) menu_items[id]:set({ label = menu, drawing = true })
else break end else
id = id + 1 break
end end
end) id = id + 1
end
end)
end end
menu_watcher:subscribe("front_app_switched", update_menus) menu_watcher:subscribe("front_app_switched", update_menus)
space_menu_swap:subscribe("swap_menus_and_spaces", function(env) space_menu_swap:subscribe("swap_menus_and_spaces", function(env)
local drawing = menu_items[1]:query().geometry.drawing == "on" local drawing = menu_items[1]:query().geometry.drawing == "on"
if drawing then if drawing then
menu_watcher:set( { updates = false }) menu_watcher:set({ updates = false })
sbar.set("/menu\\..*/", { drawing = false }) sbar.set("/menu\\..*/", { drawing = false })
sbar.set("/space\\..*/", { drawing = true }) sbar.set("/space\\..*/", { drawing = true })
sbar.set("front_app", { drawing = true }) sbar.set("front_app", { drawing = true })
else else
menu_watcher:set( { updates = true }) menu_watcher:set({ updates = true })
sbar.set("/space\\..*/", { drawing = false }) sbar.set("/space\\..*/", { drawing = false })
sbar.set("front_app", { drawing = false }) sbar.set("front_app", { drawing = false })
update_menus() update_menus()
end end
end) end)
return menu_watcher return menu_watcher

View file

@ -2,78 +2,78 @@ local colors = require("colors")
local icons = require("icons") local icons = require("icons")
local volume_slider = sbar.add("slider", 100, { local volume_slider = sbar.add("slider", 100, {
position = "right", position = "right",
updates = true, updates = true,
label = { drawing = false }, label = { drawing = false },
icon = { drawing = false }, icon = { drawing = false },
slider = { slider = {
highlight_color = colors.blue, highlight_color = colors.blue,
width = 0, width = 0,
background = { background = {
height = 6, height = 6,
corner_radius = 3, corner_radius = 3,
color = colors.bg2, color = colors.bg2,
}, },
knob= { knob = {
string = "􀀁", string = "􀀁",
drawing = false, drawing = false,
}, },
}, },
}) })
local volume_icon = sbar.add("item", { local volume_icon = sbar.add("item", {
position = "right", position = "right",
icon = { icon = {
string = icons.volume._100, string = icons.volume._100,
width = 0, width = 0,
align = "left", align = "left",
color = colors.grey, color = colors.grey,
font = { font = {
style = "Regular", style = "Regular",
size = 14.0, size = 14.0,
}, },
}, },
label = { label = {
width = 25, width = 25,
align = "left", align = "left",
font = { font = {
style = "Regular", style = "Regular",
size = 14.0, size = 14.0,
}, },
}, },
}) })
volume_slider:subscribe("mouse.clicked", function(env) volume_slider:subscribe("mouse.clicked", function(env)
sbar.exec("osascript -e 'set volume output volume " .. env["PERCENTAGE"] .. "'") sbar.exec("osascript -e 'set volume output volume " .. env["PERCENTAGE"] .. "'")
end) end)
volume_slider:subscribe("volume_change", function(env) volume_slider:subscribe("volume_change", function(env)
local volume = tonumber(env.INFO) local volume = tonumber(env.INFO)
local icon = icons.volume._0 local icon = icons.volume._0
if volume > 60 then if volume > 60 then
icon = icons.volume._100 icon = icons.volume._100
elseif volume > 30 then elseif volume > 30 then
icon = icons.volume._66 icon = icons.volume._66
elseif volume > 10 then elseif volume > 10 then
icon = icons.volume._33 icon = icons.volume._33
elseif volume > 0 then elseif volume > 0 then
icon = icons.volume._10 icon = icons.volume._10
end end
volume_icon:set({ label = icon }) volume_icon:set({ label = icon })
volume_slider:set({ slider = { percentage = volume } }) volume_slider:set({ slider = { percentage = volume } })
end) end)
local function animate_slider_width(width) local function animate_slider_width(width)
sbar.animate("tanh", 30.0, function() sbar.animate("tanh", 30.0, function()
volume_slider:set({ slider = { width = width }}) volume_slider:set({ slider = { width = width } })
end) end)
end end
volume_icon:subscribe("mouse.clicked", function() volume_icon:subscribe("mouse.clicked", function()
if tonumber(volume_slider:query().slider.width) > 0 then if tonumber(volume_slider:query().slider.width) > 0 then
animate_slider_width(0) animate_slider_width(0)
else else
animate_slider_width(100) animate_slider_width(100)
end end
end) end)

View file

@ -9,208 +9,208 @@ sbar.exec("killall sk-network-load >/dev/null; sk-network-load en0 network_updat
local popup_width = 250 local popup_width = 250
local wifi_up = sbar.add("item", "widgets.wifi1", { local wifi_up = sbar.add("item", "widgets.wifi1", {
position = "right", position = "right",
padding_left = -5, padding_left = -5,
width = 0, width = 0,
icon = { icon = {
padding_right = 0, padding_right = 0,
font = { font = {
style = settings.font.style_map["Bold"], style = settings.font.style_map["Bold"],
size = 9.0, size = 9.0,
}, },
string = icons.wifi.upload, string = icons.wifi.upload,
}, },
label = { label = {
font = { font = {
family = settings.font.numbers, family = settings.font.numbers,
style = settings.font.style_map["Bold"], style = settings.font.style_map["Bold"],
size = 9.0, size = 9.0,
}, },
color = colors.red, color = colors.red,
string = "??? Bps", string = "??? Bps",
}, },
y_offset = 4, y_offset = 4,
}) })
local wifi_down = sbar.add("item", "widgets.wifi2", { local wifi_down = sbar.add("item", "widgets.wifi2", {
position = "right", position = "right",
padding_left = -5, padding_left = -5,
icon = { icon = {
padding_right = 0, padding_right = 0,
font = { font = {
style = settings.font.style_map["Bold"], style = settings.font.style_map["Bold"],
size = 9.0, size = 9.0,
}, },
string = icons.wifi.download, string = icons.wifi.download,
}, },
label = { label = {
font = { font = {
family = settings.font.numbers, family = settings.font.numbers,
style = settings.font.style_map["Bold"], style = settings.font.style_map["Bold"],
size = 9.0, size = 9.0,
}, },
color = colors.blue, color = colors.blue,
string = "??? Bps", string = "??? Bps",
}, },
y_offset = -4, y_offset = -4,
}) })
local wifi = sbar.add("item", "widgets.wifi.padding", { local wifi = sbar.add("item", "widgets.wifi.padding", {
position = "right", position = "right",
label = { drawing = false }, label = { drawing = false },
}) })
-- Background around the item -- Background around the item
local wifi_bracket = sbar.add("bracket", "widgets.wifi.bracket", { local wifi_bracket = sbar.add("bracket", "widgets.wifi.bracket", {
wifi.name, wifi.name,
wifi_up.name, wifi_up.name,
wifi_down.name wifi_down.name,
}, { }, {
-- background = { color = colors.bar.bg }, -- background = { color = colors.bar.bg },
popup = { align = "center", height = 30 } popup = { align = "center", height = 30 },
}) })
local ssid = sbar.add("item", { local ssid = sbar.add("item", {
position = "popup." .. wifi_bracket.name, position = "popup." .. wifi_bracket.name,
icon = { icon = {
font = { font = {
style = settings.font.style_map["Bold"] style = settings.font.style_map["Bold"],
}, },
string = icons.wifi.router, string = icons.wifi.router,
}, },
width = popup_width, width = popup_width,
align = "center", align = "center",
label = { label = {
font = { font = {
size = 15, size = 15,
style = settings.font.style_map["Bold"] style = settings.font.style_map["Bold"],
}, },
max_chars = 18, max_chars = 18,
string = "????????????", string = "????????????",
}, },
background = { background = {
height = 2, height = 2,
color = colors.bar.bg, color = colors.bar.bg,
y_offset = -15 y_offset = -15,
} },
}) })
local hostname = sbar.add("item", { local hostname = sbar.add("item", {
position = "popup." .. wifi_bracket.name, position = "popup." .. wifi_bracket.name,
icon = { icon = {
align = "left", align = "left",
string = "Hostname:", string = "Hostname:",
width = popup_width / 2, width = popup_width / 2,
}, },
label = { label = {
max_chars = 20, max_chars = 20,
string = "????????????", string = "????????????",
width = popup_width / 2, width = popup_width / 2,
align = "right", align = "right",
} },
}) })
local ip = sbar.add("item", { local ip = sbar.add("item", {
position = "popup." .. wifi_bracket.name, position = "popup." .. wifi_bracket.name,
icon = { icon = {
align = "left", align = "left",
string = "IP:", string = "IP:",
width = popup_width / 2, width = popup_width / 2,
}, },
label = { label = {
string = "???.???.???.???", string = "???.???.???.???",
width = popup_width / 2, width = popup_width / 2,
align = "right", align = "right",
} },
}) })
local mask = sbar.add("item", { local mask = sbar.add("item", {
position = "popup." .. wifi_bracket.name, position = "popup." .. wifi_bracket.name,
icon = { icon = {
align = "left", align = "left",
string = "Subnet mask:", string = "Subnet mask:",
width = popup_width / 2, width = popup_width / 2,
}, },
label = { label = {
string = "???.???.???.???", string = "???.???.???.???",
width = popup_width / 2, width = popup_width / 2,
align = "right", align = "right",
} },
}) })
local router = sbar.add("item", { local router = sbar.add("item", {
position = "popup." .. wifi_bracket.name, position = "popup." .. wifi_bracket.name,
icon = { icon = {
align = "left", align = "left",
string = "Router:", string = "Router:",
width = popup_width / 2, width = popup_width / 2,
}, },
label = { label = {
string = "???.???.???.???", string = "???.???.???.???",
width = popup_width / 2, width = popup_width / 2,
align = "right", align = "right",
}, },
}) })
sbar.add("item", { position = "right", width = settings.group_paddings }) sbar.add("item", { position = "right", width = settings.group_paddings })
wifi_up:subscribe("network_update", function(env) wifi_up:subscribe("network_update", function(env)
local up_color = (env.upload == "000 Bps") and colors.grey or colors.red local up_color = (env.upload == "000 Bps") and colors.grey or colors.red
local down_color = (env.download == "000 Bps") and colors.grey or colors.blue local down_color = (env.download == "000 Bps") and colors.grey or colors.blue
wifi_up:set({ wifi_up:set({
icon = { color = up_color }, icon = { color = up_color },
label = { label = {
string = env.upload, string = env.upload,
color = up_color color = up_color,
} },
}) })
wifi_down:set({ wifi_down:set({
icon = { color = down_color }, icon = { color = down_color },
label = { label = {
string = env.download, string = env.download,
color = down_color color = down_color,
} },
}) })
end) end)
wifi:subscribe({"wifi_change", "system_woke"}, function(env) wifi:subscribe({ "wifi_change", "system_woke" }, function(env)
sbar.exec("ipconfig getifaddr en0", function(ip) sbar.exec("ipconfig getifaddr en0", function(ip)
local connected = not (ip == "") local connected = not (ip == "")
wifi:set({ wifi:set({
icon = { icon = {
string = connected and icons.wifi.connected or icons.wifi.disconnected, string = connected and icons.wifi.connected or icons.wifi.disconnected,
color = connected and colors.white or colors.red, color = connected and colors.white or colors.red,
}, },
}) })
end) end)
end) end)
local function hide_details() local function hide_details()
wifi_bracket:set({ popup = { drawing = false } }) wifi_bracket:set({ popup = { drawing = false } })
end end
local function toggle_details() local function toggle_details()
local should_draw = wifi_bracket:query().popup.drawing == "off" local should_draw = wifi_bracket:query().popup.drawing == "off"
if should_draw then if should_draw then
wifi_bracket:set({ popup = { drawing = true }}) wifi_bracket:set({ popup = { drawing = true } })
sbar.exec("networksetup -getcomputername", function(result) sbar.exec("networksetup -getcomputername", function(result)
hostname:set({ label = result }) hostname:set({ label = result })
end) end)
sbar.exec("ipconfig getifaddr en0", function(result) sbar.exec("ipconfig getifaddr en0", function(result)
ip:set({ label = result }) ip:set({ label = result })
end) end)
sbar.exec("ipconfig getsummary en0 | awk -F ' SSID : ' '/ SSID : / {print $2}'", function(result) sbar.exec("ipconfig getsummary en0 | awk -F ' SSID : ' '/ SSID : / {print $2}'", function(result)
ssid:set({ label = result }) ssid:set({ label = result })
end) end)
sbar.exec("networksetup -getinfo Wi-Fi | awk -F 'Subnet mask: ' '/^Subnet mask: / {print $2}'", function(result) sbar.exec("networksetup -getinfo Wi-Fi | awk -F 'Subnet mask: ' '/^Subnet mask: / {print $2}'", function(result)
mask:set({ label = result }) mask:set({ label = result })
end) end)
sbar.exec("networksetup -getinfo Wi-Fi | awk -F 'Router: ' '/^Router: / {print $2}'", function(result) sbar.exec("networksetup -getinfo Wi-Fi | awk -F 'Router: ' '/^Router: / {print $2}'", function(result)
router:set({ label = result }) router:set({ label = result })
end) end)
else else
hide_details() hide_details()
end end
end end
wifi_up:subscribe("mouse.clicked", toggle_details) wifi_up:subscribe("mouse.clicked", toggle_details)
@ -219,12 +219,12 @@ wifi:subscribe("mouse.clicked", toggle_details)
wifi:subscribe("mouse.exited.global", hide_details) wifi:subscribe("mouse.exited.global", hide_details)
local function copy_label_to_clipboard(env) local function copy_label_to_clipboard(env)
local label = sbar.query(env.NAME).label.value local label = sbar.query(env.NAME).label.value
sbar.exec("echo \"" .. label .. "\" | pbcopy") sbar.exec('echo "' .. label .. '" | pbcopy')
sbar.set(env.NAME, { label = { string = icons.clipboard, align="center" } }) sbar.set(env.NAME, { label = { string = icons.clipboard, align = "center" } })
sbar.delay(1, function() sbar.delay(1, function()
sbar.set(env.NAME, { label = { string = label, align = "right" } }) sbar.set(env.NAME, { label = { string = label, align = "right" } })
end) end)
end end
ssid:subscribe("mouse.clicked", copy_label_to_clipboard) ssid:subscribe("mouse.clicked", copy_label_to_clipboard)

View file

@ -1,19 +1,19 @@
#!/usr/bin/env lua #!/usr/bin/env lua
return { return {
icons = "sf-symbols", icons = "sf-symbols",
font = { font = {
text = "SF Pro", text = "SF Pro",
numbers = "SF Pro", numbers = "SF Pro",
style_map = { style_map = {
["Regular"] = "Regular", ["Regular"] = "Regular",
["Semibold"] = "Semibold", ["Semibold"] = "Semibold",
["Bold"] = "Bold", ["Bold"] = "Bold",
["Heavy"] = "Heavy", ["Heavy"] = "Heavy",
["Black"] = "Black", ["Black"] = "Black",
}, },
}, },
paddings = 3, paddings = 3,
group_paddings = 0, group_paddings = 0,
space_paddings = 5, space_paddings = 5,
} }

View file

@ -18,7 +18,7 @@ function M.dump(o)
end end
local function onErrorP(reason) local function onErrorP(reason)
print("Error found: " .. (reason and M.dump(reason) or "unknown")) print("Error found: " .. (reason and M.dump(reason) or "unknown"))
end end
-- https://github.com/Tnixc/nix-config/blob/main/home/programs/aerospace-sketchybar/sbar-config-libs/items/aerospaces.lua -- https://github.com/Tnixc/nix-config/blob/main/home/programs/aerospace-sketchybar/sbar-config-libs/items/aerospaces.lua

View file

@ -87,7 +87,9 @@
{ pkgs, ... }: { pkgs, ... }:
treefmt-nix.lib.evalModule pkgs { treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix"; projectRootFile = "flake.nix";
programs.nixfmt-rfc-style.enable = true; programs.nixfmt.enable = true;
programs.stylua.enable = true;
programs.shfmt.enable = true;
settings.global.excludes = [ "flake.lock" ]; settings.global.excludes = [ "flake.lock" ];
} }
); );
@ -137,7 +139,7 @@
sops sops
age age
ssh-to-age ssh-to-age
nixfmt-rfc-style # nixfmt-rfc-style
]; ];
DIRENV_LOG_FORMAT = ""; DIRENV_LOG_FORMAT = "";
}; };