From b9eea0f86b67885f120c5ea3c1b6221d17890b9a Mon Sep 17 00:00:00 2001 From: Ray Andrew Date: Tue, 8 Apr 2025 23:41:12 -0500 Subject: [PATCH] format lua files --- darwin/sketchybar/config/colors.lua | 36 +- darwin/sketchybar/config/icons.lua | 162 ++++----- darwin/sketchybar/config/items/aerospace.lua | 254 +++++++------- darwin/sketchybar/config/items/apple.lua | 30 +- darwin/sketchybar/config/items/battery.lua | 67 ++-- darwin/sketchybar/config/items/cal.lua | 4 +- darwin/sketchybar/config/items/cpu.lua | 88 ++--- darwin/sketchybar/config/items/front_app.lua | 40 +-- darwin/sketchybar/config/items/menu.lua | 94 +++--- darwin/sketchybar/config/items/volume.lua | 116 +++---- darwin/sketchybar/config/items/wifi.lua | 338 +++++++++---------- darwin/sketchybar/config/settings.lua | 26 +- darwin/sketchybar/config/utils.lua | 2 +- flake.nix | 6 +- 14 files changed, 636 insertions(+), 627 deletions(-) diff --git a/darwin/sketchybar/config/colors.lua b/darwin/sketchybar/config/colors.lua index ee1f5ae..6a06e70 100644 --- a/darwin/sketchybar/config/colors.lua +++ b/darwin/sketchybar/config/colors.lua @@ -1,24 +1,26 @@ local function with_alpha(color, alpha) - if alpha > 1.0 or alpha < 0.0 then return color end - return (color & 0x00ffffff) | (math.floor(alpha * 255.0) << 24) + if alpha > 1.0 or alpha < 0.0 then + return color + end + return (color & 0x00ffffff) | (math.floor(alpha * 255.0) << 24) end return { - black = 0xff181819, - white = 0xffd3b58d, - red = 0xffF92672, - blue = 0xff66D9EF, - grey = 0xff7f8490, - transparent = 0x00000000, + black = 0xff181819, + white = 0xffd3b58d, + red = 0xffF92672, + blue = 0xff66D9EF, + grey = 0xff7f8490, + transparent = 0x00000000, - bar = { - bg = 0xff072626, - border = 0xffFD971F, - }, - popup = { - bg = with_alpha(0xff072626, 0.6), - border = 0xffFD971F, - }, + bar = { + bg = 0xff072626, + border = 0xffFD971F, + }, + popup = { + bg = with_alpha(0xff072626, 0.6), + border = 0xffFD971F, + }, - with_alpha = with_alpha, + with_alpha = with_alpha, } diff --git a/darwin/sketchybar/config/icons.lua b/darwin/sketchybar/config/icons.lua index 2e52a91..844b35c 100644 --- a/darwin/sketchybar/config/icons.lua +++ b/darwin/sketchybar/config/icons.lua @@ -1,92 +1,92 @@ local settings = require("settings") local icons = { - sf_symbols = { - plus = "􀅼", - loading = "􀖇", - apple = "􀣺", - gear = "􀍟", - cpu = "􀫥", - clipboard = "􀉄", + sf_symbols = { + plus = "􀅼", + loading = "􀖇", + apple = "􀣺", + gear = "􀍟", + cpu = "􀫥", + clipboard = "􀉄", - switch = { - on = "􁏮", - off = "􁏯", - }, - volume = { - _100="􀊩", - _66="􀊧", - _33="􀊥", - _10="􀊡", - _0="􀊣", - }, - battery = { - _100 = "􀛨", - _75 = "􀺸", - _50 = "􀺶", - _25 = "􀛩", - _0 = "􀛪", - charging = "􀢋" - }, - wifi = { - upload = "􀄨", - download = "􀄩", - connected = "􀙇", - disconnected = "􀙈", - router = "􁓤", - }, - media = { - back = "􀊊", - forward = "􀊌", - play_pause = "􀊈", - }, - }, + switch = { + on = "􁏮", + off = "􁏯", + }, + volume = { + _100 = "􀊩", + _66 = "􀊧", + _33 = "􀊥", + _10 = "􀊡", + _0 = "􀊣", + }, + battery = { + _100 = "􀛨", + _75 = "􀺸", + _50 = "􀺶", + _25 = "􀛩", + _0 = "􀛪", + charging = "􀢋", + }, + wifi = { + upload = "􀄨", + download = "􀄩", + connected = "􀙇", + disconnected = "􀙈", + router = "􁓤", + }, + media = { + back = "􀊊", + forward = "􀊌", + play_pause = "􀊈", + }, + }, - -- Alternative NerdFont icons - nerdfont = { - plus = "", - loading = "", - apple = "", - gear = "", - cpu = "", - clipboard = "Missing Icon", + -- Alternative NerdFont icons + nerdfont = { + plus = "", + loading = "", + apple = "", + gear = "", + cpu = "", + clipboard = "Missing Icon", - switch = { - on = "󱨥", - off = "󱨦", - }, - volume = { - _100="", - _66="", - _33="", - _10="", - _0="", - }, - battery = { - _100 = "", - _75 = "", - _50 = "", - _25 = "", - _0 = "", - charging = "" - }, - wifi = { - upload = "", - download = "", - connected = "󰖩", - disconnected = "󰖪", - router = "Missing Icon" - }, - media = { - back = "", - forward = "", - play_pause = "", - }, - }, + switch = { + on = "󱨥", + off = "󱨦", + }, + volume = { + _100 = "", + _66 = "", + _33 = "", + _10 = "", + _0 = "", + }, + battery = { + _100 = "", + _75 = "", + _50 = "", + _25 = "", + _0 = "", + charging = "", + }, + wifi = { + upload = "", + download = "", + connected = "󰖩", + disconnected = "󰖪", + router = "Missing Icon", + }, + media = { + back = "", + forward = "", + play_pause = "", + }, + }, } if not (settings.icons == "NerdFont") then - return icons.sf_symbols + return icons.sf_symbols else - return icons.nerdfont + return icons.nerdfont end diff --git a/darwin/sketchybar/config/items/aerospace.lua b/darwin/sketchybar/config/items/aerospace.lua index 510ef86..26e263a 100644 --- a/darwin/sketchybar/config/items/aerospace.lua +++ b/darwin/sketchybar/config/items/aerospace.lua @@ -7,11 +7,15 @@ local settings = require("settings") local app_icons = require("app_icons") 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 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 local function getAllWindows() @@ -21,17 +25,17 @@ local function getAllWindows() end local function getMonitorId(obj) - if obj["monitor-name"] then + if obj["monitor-name"] then if obj["monitor-name"] == "ZOWIE XL LCD" then return "2" elseif obj["monitor-name"] == "LG ULTRAWIDE" then return "1" end end - if obj["monitor-appkit-nsscreen-screens-id"] then - return obj["monitor-appkit-nsscreen-screens-id"] - end - return obj["monitor-id"] + if obj["monitor-appkit-nsscreen-screens-id"] then + return obj["monitor-appkit-nsscreen-screens-id"] + end + return obj["monitor-id"] end local spaces = {} @@ -43,41 +47,41 @@ local state = { } function getState() - local newstate = { - workspaces = {}, - } + local newstate = { + workspaces = {}, + } - for workspaceid, space in pairs(spaces) do - newstate.workspaces[workspaceid] = { - monitor = 0, - active = false, - empty = true, - apps = {}, - appicons = "", - } - end + for workspaceid, space in pairs(spaces) do + newstate.workspaces[workspaceid] = { + monitor = 0, + active = false, + empty = true, + apps = {}, + appicons = "", + } + end - return Promise.all({ getAllWorkspaces(), getVisibleWorkspaces(), getAllWindows() }):thenCall(function(values) - local all, visible, apps = values[1], values[2], values[3] - for _, workspace in ipairs(all) do - local workspaceid = workspace["workspace"] - newstate.workspaces[workspaceid]["id"] = workspaceid - newstate.workspaces[workspaceid]["monitor"] = getMonitorId(workspace) - end + return Promise.all({ getAllWorkspaces(), getVisibleWorkspaces(), getAllWindows() }):thenCall(function(values) + local all, visible, apps = values[1], values[2], values[3] + for _, workspace in ipairs(all) do + local workspaceid = workspace["workspace"] + newstate.workspaces[workspaceid]["id"] = workspaceid + newstate.workspaces[workspaceid]["monitor"] = getMonitorId(workspace) + end - for _, workspace in ipairs(visible) do - local workspaceid = workspace["workspace"] - newstate.workspaces[workspaceid]["active"] = true - end + for _, workspace in ipairs(visible) do + local workspaceid = workspace["workspace"] + newstate.workspaces[workspaceid]["active"] = true + end - for _, window in ipairs(apps) do + for _, window in ipairs(apps) do local workspaceid = window["workspace"] local appname = window["app-name"] newstate.workspaces[workspaceid]["apps"][appname] = true 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 = {} for app in pairs(workspacestate["apps"]) do table.insert(appkeys, app) @@ -92,11 +96,11 @@ function getState() else workspacestate["appicons"] = "" end - -- print(utils.dump(workspacestate)) + -- print(utils.dump(workspacestate)) end - return newstate - end) + return newstate + end) end local function updateState() @@ -110,22 +114,21 @@ local function updateState() return Promise.reject("State is already updating") end - local function highlightSpace(space, space_padding, space_bracket, selected) - space:set({ - drawing = true, - icon = { highlight = selected, }, - label = { highlight = selected }, - -- background = { border_color = selected and colors.white or colors.bg2 } - }) + space:set({ + drawing = true, + icon = { highlight = selected }, + label = { highlight = selected }, + -- background = { border_color = selected and colors.white or colors.bg2 } + }) space_padding:set({ drawing = true, }) - if space_bracket then - space_bracket:set({ - -- background = { border_color = selected and colors.grey or colors.bg2 }, - }) - end + if space_bracket then + space_bracket:set({ + -- background = { border_color = selected and colors.grey or colors.bg2 }, + }) + end end local function onActiveSpaceChange(env) @@ -142,7 +145,7 @@ local function onActiveSpaceChange(env) sbar.animate("tanh", 10, function() highlightSpace(space, space_padding, nil, true) 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) @@ -150,41 +153,41 @@ local function onActiveSpaceChange(env) end local function syncState() - sbar.animate("tanh", 10, function() - for workspaceid, workspacestate in pairs(state.workspaces) do - if not workspacestate["empty"] then - spaces[workspaceid]:set({ - drawing = true, - display = workspacestate["monitor"], - -- label = { - -- string = workspaceid, - -- highlight = workspacestate["active"], - -- }, - -- icon = { - -- string = workspaceid, - -- color = colors.white, - -- highlight = workspacestate["active"], - -- }, - label = { + sbar.animate("tanh", 10, function() + for workspaceid, workspacestate in pairs(state.workspaces) do + if not workspacestate["empty"] then + spaces[workspaceid]:set({ + drawing = true, + display = workspacestate["monitor"], + -- label = { + -- string = workspaceid, + -- highlight = workspacestate["active"], + -- }, + -- icon = { + -- string = workspaceid, + -- color = colors.white, + -- highlight = workspacestate["active"], + -- }, + label = { string = workspacestate["appicons"], highlight = workspacestate["active"], }, icon = { highlight = workspacestate["active"], }, - }) - space_paddings[workspaceid]:set({ drawing = true }) - else - -- These should be hidden - spaces[workspaceid]:set({ - drawing = false, - display = workspacestate["monitor"], - label = workspacestate["appicons"], - }) - space_paddings[workspaceid]:set({ drawing = false }) - end - end - end) + }) + space_paddings[workspaceid]:set({ drawing = true }) + else + -- These should be hidden + spaces[workspaceid]:set({ + drawing = false, + display = workspacestate["monitor"], + label = workspacestate["appicons"], + }) + space_paddings[workspaceid]:set({ drawing = false }) + end + end + end) end local function updateStateAndSync() @@ -192,57 +195,58 @@ local function updateStateAndSync() end function setup() - getAllWorkspaces():thenCall(function(workspaces) - for _, workspace in ipairs(workspaces) do - local workspaceid = workspace["workspace"] - local display = getMonitorId(workspace) + getAllWorkspaces() + :thenCall(function(workspaces) + for _, workspace in ipairs(workspaces) do + local workspaceid = workspace["workspace"] + local display = getMonitorId(workspace) - 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 - updates = "when_shown", - display = display, - icon = { - string = workspaceid, - color = colors.white, - highlight_color = colors.red, - }, - label = { - padding_right = 12, - color = colors.grey, - highlight_color = colors.white, - font = "sketchybar-app-font:Regular:14.0", - y_offset = -1, - -- drawing = false - }, - padding_left = 1, - padding_right = 1, - click_script = "aerospace workspace " .. 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 + updates = "when_shown", + display = display, + icon = { + string = workspaceid, + color = colors.white, + highlight_color = colors.red, + }, + label = { + padding_right = 12, + color = colors.grey, + highlight_color = colors.white, + font = "sketchybar-app-font:Regular:14.0", + y_offset = -1, + -- drawing = false + }, + padding_left = 1, + padding_right = 1, + click_script = "aerospace workspace " .. workspaceid, + }) - spaces[workspaceid] = space + spaces[workspaceid] = space - local padding = sbar.add("space", "space.padding." .. space.name, { - drawing = false, - updates = "when_shown", - display = display, - script = "", - width = settings.space_paddings, - }) - space_paddings[workspaceid] = padding - end - end) - :thenCall(function() - local space_window_observer = sbar.add("item", { - drawing = false, - updates = true, - }) + local padding = sbar.add("space", "space.padding." .. space.name, { + drawing = false, + updates = "when_shown", + display = display, + script = "", + width = settings.space_paddings, + }) + space_paddings[workspaceid] = padding + end + end) + :thenCall(function() + local space_window_observer = sbar.add("item", { + drawing = false, + updates = true, + }) - space_window_observer:subscribe("aerospace_workspace_change", onActiveSpaceChange) - space_window_observer:subscribe("space_windows_change", updateStateAndSync) - space_window_observer:subscribe("system_woke", updateStateAndSync) - space_window_observer:subscribe("front_app_switched", updateStateAndSync) - end) - :thenCall(updateStateAndSync) + space_window_observer:subscribe("aerospace_workspace_change", onActiveSpaceChange) + space_window_observer:subscribe("space_windows_change", updateStateAndSync) + space_window_observer:subscribe("system_woke", updateStateAndSync) + space_window_observer:subscribe("front_app_switched", updateStateAndSync) + end) + :thenCall(updateStateAndSync) end setup() diff --git a/darwin/sketchybar/config/items/apple.lua b/darwin/sketchybar/config/items/apple.lua index e48a993..b75637b 100644 --- a/darwin/sketchybar/config/items/apple.lua +++ b/darwin/sketchybar/config/items/apple.lua @@ -6,21 +6,21 @@ local settings = require("settings") sbar.add("item", { width = 5 }) local apple = sbar.add("item", { - icon = { - font = { size = 16.0 }, - string = icons.apple, - padding_right = settings.paddings, - padding_left = 0, - }, - label = { drawing = false }, - background = { - color = colors.bg2, - -- border_color = colors.black, - -- border_width = 1 - }, - padding_left = 1, - padding_right = 1, - click_script = "sk-menus -s 0" + icon = { + font = { size = 16.0 }, + string = icons.apple, + padding_right = settings.paddings, + padding_left = 0, + }, + label = { drawing = false }, + background = { + color = colors.bg2, + -- border_color = colors.black, + -- border_width = 1 + }, + padding_left = 1, + padding_right = 1, + click_script = "sk-menus -s 0", }) -- Double border for apple using a single item bracket diff --git a/darwin/sketchybar/config/items/battery.lua b/darwin/sketchybar/config/items/battery.lua index 4f9b927..8239081 100644 --- a/darwin/sketchybar/config/items/battery.lua +++ b/darwin/sketchybar/config/items/battery.lua @@ -1,45 +1,44 @@ local icons = require("icons") local battery = sbar.add("item", { - position = "right", - icon = { - font = { - style = "Regular", - size = 19.0, - } - }, - label = { drawing = false }, - update_freq = 120, + position = "right", + icon = { + font = { + style = "Regular", + size = 19.0, + }, + }, + label = { drawing = false }, + update_freq = 120, }) local function battery_update() - sbar.exec("pmset -g batt", function(batt_info) - local icon = "!" + sbar.exec("pmset -g batt", function(batt_info) + local icon = "!" - if (string.find(batt_info, 'AC Power')) then - icon = icons.battery.charging - else - local found, _, charge = batt_info:find("(%d+)%%") - if found then - charge = tonumber(charge) - end + if string.find(batt_info, "AC Power") then + icon = icons.battery.charging + else + local found, _, charge = batt_info:find("(%d+)%%") + if found then + charge = tonumber(charge) + end - if found and charge > 80 then - icon = icons.battery._100 - elseif found and charge > 60 then - icon = icons.battery._75 - elseif found and charge > 40 then - icon = icons.battery._50 - elseif found and charge > 20 then - icon = icons.battery._25 - else - icon = icons.battery._0 - end - end + if found and charge > 80 then + icon = icons.battery._100 + elseif found and charge > 60 then + icon = icons.battery._75 + elseif found and charge > 40 then + icon = icons.battery._50 + elseif found and charge > 20 then + icon = icons.battery._25 + else + icon = icons.battery._0 + end + end - battery:set({ icon = icon }) - end) + battery:set({ icon = icon }) + end) end - -battery:subscribe({"routine", "power_source_change", "system_woke"}, battery_update) +battery:subscribe({ "routine", "power_source_change", "system_woke" }, battery_update) diff --git a/darwin/sketchybar/config/items/cal.lua b/darwin/sketchybar/config/items/cal.lua index 58de614..9116e08 100644 --- a/darwin/sketchybar/config/items/cal.lua +++ b/darwin/sketchybar/config/items/cal.lua @@ -19,7 +19,7 @@ local cal = sbar.add("item", { update_freq = 30, padding_left = 0, padding_right = 0, - click_script = "open -n -a Calendar", + click_script = "open -n -a Calendar", -- background = { -- color = colors.bg1, -- 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:set({ 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) diff --git a/darwin/sketchybar/config/items/cpu.lua b/darwin/sketchybar/config/items/cpu.lua index 748ed29..d468419 100644 --- a/darwin/sketchybar/config/items/cpu.lua +++ b/darwin/sketchybar/config/items/cpu.lua @@ -6,64 +6,64 @@ local settings = require("settings") -- 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") -local cpu = sbar.add("graph", "widgets.cpu" , 42, { - position = "right", - graph = { color = colors.blue }, - background = { - height = 22, - color = { alpha = 0 }, - border_color = { alpha = 0 }, - drawing = true, - }, - icon = { string = icons.cpu }, - label = { - string = "cpu ??%", - font = { - family = settings.font.numbers, - style = settings.font.style_map["Bold"], - size = 9.0, - }, - align = "right", - padding_right = 0, - width = 0, - y_offset = 4 - }, - padding_right = settings.paddings + 6 +local cpu = sbar.add("graph", "widgets.cpu", 42, { + position = "right", + graph = { color = colors.blue }, + background = { + height = 22, + color = { alpha = 0 }, + border_color = { alpha = 0 }, + drawing = true, + }, + icon = { string = icons.cpu }, + label = { + string = "cpu ??%", + font = { + family = settings.font.numbers, + style = settings.font.style_map["Bold"], + size = 9.0, + }, + align = "right", + padding_right = 0, + width = 0, + y_offset = 4, + }, + padding_right = settings.paddings + 6, }) cpu:subscribe("cpu_update", function(env) - -- Also available: env.user_load, env.sys_load - local load = tonumber(env.total_load) - cpu:push({ load / 100. }) + -- Also available: env.user_load, env.sys_load + local load = tonumber(env.total_load) + cpu:push({ load / 100. }) - local color = colors.blue - if load > 30 then - if load < 60 then - color = colors.yellow - elseif load < 80 then - color = colors.orange - else - color = colors.red - end - end + local color = colors.blue + if load > 30 then + if load < 60 then + color = colors.yellow + elseif load < 80 then + color = colors.orange + else + color = colors.red + end + end - cpu:set({ - graph = { color = color }, - label = "cpu " .. env.total_load .. "%", - }) + cpu:set({ + graph = { color = color }, + label = "cpu " .. env.total_load .. "%", + }) end) cpu:subscribe("mouse.clicked", function(env) - sbar.exec("open -a 'Activity Monitor'") + sbar.exec("open -a 'Activity Monitor'") end) -- Background around the cpu item sbar.add("bracket", "widgets.cpu.bracket", { cpu.name }, { - background = { color = colors.bg1 } + background = { color = colors.bg1 }, }) -- Background around the cpu item sbar.add("item", "widgets.cpu.padding", { - position = "right", - width = settings.group_paddings + position = "right", + width = settings.group_paddings, }) diff --git a/darwin/sketchybar/config/items/front_app.lua b/darwin/sketchybar/config/items/front_app.lua index f4bacd9..04fc65b 100644 --- a/darwin/sketchybar/config/items/front_app.lua +++ b/darwin/sketchybar/config/items/front_app.lua @@ -1,28 +1,28 @@ local settings = require("settings") local front_app = sbar.add("item", { - icon = { - drawing = false - }, - label = { - font = { - style = settings.font.style_map["Bold"], - size = 12.0, - } - } + icon = { + drawing = false, + }, + label = { + font = { + style = settings.font.style_map["Bold"], + size = 12.0, + }, + }, }) front_app:subscribe("front_app_switched", function(env) - front_app:set({ - label = { - string = env.INFO:upper() - } - }) + front_app:set({ + label = { + string = env.INFO:upper(), + }, + }) - -- Or equivalently: - -- sbar.set(env.NAME, { - -- label = { - -- string = env.INFO - -- } - -- }) + -- Or equivalently: + -- sbar.set(env.NAME, { + -- label = { + -- string = env.INFO + -- } + -- }) end) diff --git a/darwin/sketchybar/config/items/menu.lua b/darwin/sketchybar/config/items/menu.lua index 064334b..431c123 100644 --- a/darwin/sketchybar/config/items/menu.lua +++ b/darwin/sketchybar/config/items/menu.lua @@ -3,74 +3,76 @@ local icons = require("icons") local settings = require("settings") local menu_watcher = sbar.add("item", { - drawing = false, - updates = false, + drawing = false, + updates = false, }) local space_menu_swap = sbar.add("item", { - drawing = false, - updates = true, + drawing = false, + updates = true, }) sbar.add("event", "swap_menus_and_spaces") local max_items = 15 local menu_items = {} for i = 1, max_items, 1 do - local menu = sbar.add("item", "menu." .. i, { - padding_left = settings.paddings, - padding_right = settings.paddings, - drawing = false, - icon = { drawing = false }, - label = { - font = { - style = settings.font.style_map[i == 1 and "Heavy" or "Semibold"] - }, - padding_left = 6, - padding_right = 6, - }, - click_script = "sk-menus -s " .. i, - }) + local menu = sbar.add("item", "menu." .. i, { + padding_left = settings.paddings, + padding_right = settings.paddings, + drawing = false, + icon = { drawing = false }, + label = { + font = { + style = settings.font.style_map[i == 1 and "Heavy" or "Semibold"], + }, + padding_left = 6, + padding_right = 6, + }, + click_script = "sk-menus -s " .. i, + }) - menu_items[i] = menu + menu_items[i] = menu end -sbar.add("bracket", { '/menu\\..*/' }, { - background = { color = colors.bg1 } +sbar.add("bracket", { "/menu\\..*/" }, { + background = { color = colors.bg1 }, }) local menu_padding = sbar.add("item", "menu.padding", { - drawing = false, - width = 5 + drawing = false, + width = 5, }) local function update_menus(env) - sbar.exec("sk-menus -l", function(menus) - sbar.set('/menu\\..*/', { drawing = false }) - menu_padding:set({ drawing = true }) - id = 1 - for menu in string.gmatch(menus, '[^\r\n]+') do - if id < max_items then - menu_items[id]:set( { label = menu, drawing = true } ) - else break end - id = id + 1 - end - end) + sbar.exec("sk-menus -l", function(menus) + sbar.set("/menu\\..*/", { drawing = false }) + menu_padding:set({ drawing = true }) + id = 1 + for menu in string.gmatch(menus, "[^\r\n]+") do + if id < max_items then + menu_items[id]:set({ label = menu, drawing = true }) + else + break + end + id = id + 1 + end + end) end menu_watcher:subscribe("front_app_switched", update_menus) space_menu_swap:subscribe("swap_menus_and_spaces", function(env) - local drawing = menu_items[1]:query().geometry.drawing == "on" - if drawing then - menu_watcher:set( { updates = false }) - sbar.set("/menu\\..*/", { drawing = false }) - sbar.set("/space\\..*/", { drawing = true }) - sbar.set("front_app", { drawing = true }) - else - menu_watcher:set( { updates = true }) - sbar.set("/space\\..*/", { drawing = false }) - sbar.set("front_app", { drawing = false }) - update_menus() - end + local drawing = menu_items[1]:query().geometry.drawing == "on" + if drawing then + menu_watcher:set({ updates = false }) + sbar.set("/menu\\..*/", { drawing = false }) + sbar.set("/space\\..*/", { drawing = true }) + sbar.set("front_app", { drawing = true }) + else + menu_watcher:set({ updates = true }) + sbar.set("/space\\..*/", { drawing = false }) + sbar.set("front_app", { drawing = false }) + update_menus() + end end) return menu_watcher diff --git a/darwin/sketchybar/config/items/volume.lua b/darwin/sketchybar/config/items/volume.lua index b338310..7566cfe 100644 --- a/darwin/sketchybar/config/items/volume.lua +++ b/darwin/sketchybar/config/items/volume.lua @@ -2,78 +2,78 @@ local colors = require("colors") local icons = require("icons") local volume_slider = sbar.add("slider", 100, { - position = "right", - updates = true, - label = { drawing = false }, - icon = { drawing = false }, - slider = { - highlight_color = colors.blue, - width = 0, - background = { - height = 6, - corner_radius = 3, - color = colors.bg2, - }, - knob= { - string = "􀀁", - drawing = false, - }, - }, + position = "right", + updates = true, + label = { drawing = false }, + icon = { drawing = false }, + slider = { + highlight_color = colors.blue, + width = 0, + background = { + height = 6, + corner_radius = 3, + color = colors.bg2, + }, + knob = { + string = "􀀁", + drawing = false, + }, + }, }) local volume_icon = sbar.add("item", { - position = "right", - icon = { - string = icons.volume._100, - width = 0, - align = "left", - color = colors.grey, - font = { - style = "Regular", - size = 14.0, - }, - }, - label = { - width = 25, - align = "left", - font = { - style = "Regular", - size = 14.0, - }, - }, + position = "right", + icon = { + string = icons.volume._100, + width = 0, + align = "left", + color = colors.grey, + font = { + style = "Regular", + size = 14.0, + }, + }, + label = { + width = 25, + align = "left", + font = { + style = "Regular", + size = 14.0, + }, + }, }) 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) volume_slider:subscribe("volume_change", function(env) - local volume = tonumber(env.INFO) - local icon = icons.volume._0 - if volume > 60 then - icon = icons.volume._100 - elseif volume > 30 then - icon = icons.volume._66 - elseif volume > 10 then - icon = icons.volume._33 - elseif volume > 0 then - icon = icons.volume._10 - end + local volume = tonumber(env.INFO) + local icon = icons.volume._0 + if volume > 60 then + icon = icons.volume._100 + elseif volume > 30 then + icon = icons.volume._66 + elseif volume > 10 then + icon = icons.volume._33 + elseif volume > 0 then + icon = icons.volume._10 + end - volume_icon:set({ label = icon }) - volume_slider:set({ slider = { percentage = volume } }) + volume_icon:set({ label = icon }) + volume_slider:set({ slider = { percentage = volume } }) end) local function animate_slider_width(width) - sbar.animate("tanh", 30.0, function() - volume_slider:set({ slider = { width = width }}) - end) + sbar.animate("tanh", 30.0, function() + volume_slider:set({ slider = { width = width } }) + end) end volume_icon:subscribe("mouse.clicked", function() - if tonumber(volume_slider:query().slider.width) > 0 then - animate_slider_width(0) - else - animate_slider_width(100) - end + if tonumber(volume_slider:query().slider.width) > 0 then + animate_slider_width(0) + else + animate_slider_width(100) + end end) diff --git a/darwin/sketchybar/config/items/wifi.lua b/darwin/sketchybar/config/items/wifi.lua index bd8f20c..998f2e4 100644 --- a/darwin/sketchybar/config/items/wifi.lua +++ b/darwin/sketchybar/config/items/wifi.lua @@ -9,208 +9,208 @@ sbar.exec("killall sk-network-load >/dev/null; sk-network-load en0 network_updat local popup_width = 250 local wifi_up = sbar.add("item", "widgets.wifi1", { - position = "right", - padding_left = -5, - width = 0, - icon = { - padding_right = 0, - font = { - style = settings.font.style_map["Bold"], - size = 9.0, - }, - string = icons.wifi.upload, - }, - label = { - font = { - family = settings.font.numbers, - style = settings.font.style_map["Bold"], - size = 9.0, - }, - color = colors.red, - string = "??? Bps", - }, - y_offset = 4, + position = "right", + padding_left = -5, + width = 0, + icon = { + padding_right = 0, + font = { + style = settings.font.style_map["Bold"], + size = 9.0, + }, + string = icons.wifi.upload, + }, + label = { + font = { + family = settings.font.numbers, + style = settings.font.style_map["Bold"], + size = 9.0, + }, + color = colors.red, + string = "??? Bps", + }, + y_offset = 4, }) local wifi_down = sbar.add("item", "widgets.wifi2", { - position = "right", - padding_left = -5, - icon = { - padding_right = 0, - font = { - style = settings.font.style_map["Bold"], - size = 9.0, - }, - string = icons.wifi.download, - }, - label = { - font = { - family = settings.font.numbers, - style = settings.font.style_map["Bold"], - size = 9.0, - }, - color = colors.blue, - string = "??? Bps", - }, - y_offset = -4, + position = "right", + padding_left = -5, + icon = { + padding_right = 0, + font = { + style = settings.font.style_map["Bold"], + size = 9.0, + }, + string = icons.wifi.download, + }, + label = { + font = { + family = settings.font.numbers, + style = settings.font.style_map["Bold"], + size = 9.0, + }, + color = colors.blue, + string = "??? Bps", + }, + y_offset = -4, }) local wifi = sbar.add("item", "widgets.wifi.padding", { - position = "right", - label = { drawing = false }, + position = "right", + label = { drawing = false }, }) -- Background around the item local wifi_bracket = sbar.add("bracket", "widgets.wifi.bracket", { - wifi.name, - wifi_up.name, - wifi_down.name + wifi.name, + wifi_up.name, + wifi_down.name, }, { - -- background = { color = colors.bar.bg }, - popup = { align = "center", height = 30 } + -- background = { color = colors.bar.bg }, + popup = { align = "center", height = 30 }, }) local ssid = sbar.add("item", { - position = "popup." .. wifi_bracket.name, - icon = { - font = { - style = settings.font.style_map["Bold"] - }, - string = icons.wifi.router, - }, - width = popup_width, - align = "center", - label = { - font = { - size = 15, - style = settings.font.style_map["Bold"] - }, - max_chars = 18, - string = "????????????", - }, - background = { - height = 2, - color = colors.bar.bg, - y_offset = -15 - } + position = "popup." .. wifi_bracket.name, + icon = { + font = { + style = settings.font.style_map["Bold"], + }, + string = icons.wifi.router, + }, + width = popup_width, + align = "center", + label = { + font = { + size = 15, + style = settings.font.style_map["Bold"], + }, + max_chars = 18, + string = "????????????", + }, + background = { + height = 2, + color = colors.bar.bg, + y_offset = -15, + }, }) local hostname = sbar.add("item", { - position = "popup." .. wifi_bracket.name, - icon = { - align = "left", - string = "Hostname:", - width = popup_width / 2, - }, - label = { - max_chars = 20, - string = "????????????", - width = popup_width / 2, - align = "right", - } + position = "popup." .. wifi_bracket.name, + icon = { + align = "left", + string = "Hostname:", + width = popup_width / 2, + }, + label = { + max_chars = 20, + string = "????????????", + width = popup_width / 2, + align = "right", + }, }) local ip = sbar.add("item", { - position = "popup." .. wifi_bracket.name, - icon = { - align = "left", - string = "IP:", - width = popup_width / 2, - }, - label = { - string = "???.???.???.???", - width = popup_width / 2, - align = "right", - } + position = "popup." .. wifi_bracket.name, + icon = { + align = "left", + string = "IP:", + width = popup_width / 2, + }, + label = { + string = "???.???.???.???", + width = popup_width / 2, + align = "right", + }, }) local mask = sbar.add("item", { - position = "popup." .. wifi_bracket.name, - icon = { - align = "left", - string = "Subnet mask:", - width = popup_width / 2, - }, - label = { - string = "???.???.???.???", - width = popup_width / 2, - align = "right", - } + position = "popup." .. wifi_bracket.name, + icon = { + align = "left", + string = "Subnet mask:", + width = popup_width / 2, + }, + label = { + string = "???.???.???.???", + width = popup_width / 2, + align = "right", + }, }) local router = sbar.add("item", { - position = "popup." .. wifi_bracket.name, - icon = { - align = "left", - string = "Router:", - width = popup_width / 2, - }, - label = { - string = "???.???.???.???", - width = popup_width / 2, - align = "right", - }, + position = "popup." .. wifi_bracket.name, + icon = { + align = "left", + string = "Router:", + width = popup_width / 2, + }, + label = { + string = "???.???.???.???", + width = popup_width / 2, + align = "right", + }, }) sbar.add("item", { position = "right", width = settings.group_paddings }) wifi_up:subscribe("network_update", function(env) - 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 - wifi_up:set({ - icon = { color = up_color }, - label = { - string = env.upload, - color = up_color - } - }) - wifi_down:set({ - icon = { color = down_color }, - label = { - string = env.download, - color = down_color - } - }) + 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 + wifi_up:set({ + icon = { color = up_color }, + label = { + string = env.upload, + color = up_color, + }, + }) + wifi_down:set({ + icon = { color = down_color }, + label = { + string = env.download, + color = down_color, + }, + }) end) -wifi:subscribe({"wifi_change", "system_woke"}, function(env) - sbar.exec("ipconfig getifaddr en0", function(ip) - local connected = not (ip == "") - wifi:set({ - icon = { - string = connected and icons.wifi.connected or icons.wifi.disconnected, - color = connected and colors.white or colors.red, - }, - }) - end) +wifi:subscribe({ "wifi_change", "system_woke" }, function(env) + sbar.exec("ipconfig getifaddr en0", function(ip) + local connected = not (ip == "") + wifi:set({ + icon = { + string = connected and icons.wifi.connected or icons.wifi.disconnected, + color = connected and colors.white or colors.red, + }, + }) + end) end) local function hide_details() - wifi_bracket:set({ popup = { drawing = false } }) + wifi_bracket:set({ popup = { drawing = false } }) end local function toggle_details() - local should_draw = wifi_bracket:query().popup.drawing == "off" - if should_draw then - wifi_bracket:set({ popup = { drawing = true }}) - sbar.exec("networksetup -getcomputername", function(result) - hostname:set({ label = result }) - end) - sbar.exec("ipconfig getifaddr en0", function(result) - ip:set({ label = result }) - end) - sbar.exec("ipconfig getsummary en0 | awk -F ' SSID : ' '/ SSID : / {print $2}'", function(result) - ssid:set({ label = result }) - end) - sbar.exec("networksetup -getinfo Wi-Fi | awk -F 'Subnet mask: ' '/^Subnet mask: / {print $2}'", function(result) - mask:set({ label = result }) - end) - sbar.exec("networksetup -getinfo Wi-Fi | awk -F 'Router: ' '/^Router: / {print $2}'", function(result) - router:set({ label = result }) - end) - else - hide_details() - end + local should_draw = wifi_bracket:query().popup.drawing == "off" + if should_draw then + wifi_bracket:set({ popup = { drawing = true } }) + sbar.exec("networksetup -getcomputername", function(result) + hostname:set({ label = result }) + end) + sbar.exec("ipconfig getifaddr en0", function(result) + ip:set({ label = result }) + end) + sbar.exec("ipconfig getsummary en0 | awk -F ' SSID : ' '/ SSID : / {print $2}'", function(result) + ssid:set({ label = result }) + end) + sbar.exec("networksetup -getinfo Wi-Fi | awk -F 'Subnet mask: ' '/^Subnet mask: / {print $2}'", function(result) + mask:set({ label = result }) + end) + sbar.exec("networksetup -getinfo Wi-Fi | awk -F 'Router: ' '/^Router: / {print $2}'", function(result) + router:set({ label = result }) + end) + else + hide_details() + end end wifi_up:subscribe("mouse.clicked", toggle_details) @@ -219,12 +219,12 @@ wifi:subscribe("mouse.clicked", toggle_details) wifi:subscribe("mouse.exited.global", hide_details) local function copy_label_to_clipboard(env) - local label = sbar.query(env.NAME).label.value - sbar.exec("echo \"" .. label .. "\" | pbcopy") - sbar.set(env.NAME, { label = { string = icons.clipboard, align="center" } }) - sbar.delay(1, function() - sbar.set(env.NAME, { label = { string = label, align = "right" } }) - end) + local label = sbar.query(env.NAME).label.value + sbar.exec('echo "' .. label .. '" | pbcopy') + sbar.set(env.NAME, { label = { string = icons.clipboard, align = "center" } }) + sbar.delay(1, function() + sbar.set(env.NAME, { label = { string = label, align = "right" } }) + end) end ssid:subscribe("mouse.clicked", copy_label_to_clipboard) diff --git a/darwin/sketchybar/config/settings.lua b/darwin/sketchybar/config/settings.lua index 621936c..a7fe033 100644 --- a/darwin/sketchybar/config/settings.lua +++ b/darwin/sketchybar/config/settings.lua @@ -1,19 +1,19 @@ #!/usr/bin/env lua return { - icons = "sf-symbols", + icons = "sf-symbols", font = { - text = "SF Pro", - numbers = "SF Pro", - style_map = { - ["Regular"] = "Regular", - ["Semibold"] = "Semibold", - ["Bold"] = "Bold", - ["Heavy"] = "Heavy", - ["Black"] = "Black", - }, - }, - paddings = 3, - group_paddings = 0, + text = "SF Pro", + numbers = "SF Pro", + style_map = { + ["Regular"] = "Regular", + ["Semibold"] = "Semibold", + ["Bold"] = "Bold", + ["Heavy"] = "Heavy", + ["Black"] = "Black", + }, + }, + paddings = 3, + group_paddings = 0, space_paddings = 5, } diff --git a/darwin/sketchybar/config/utils.lua b/darwin/sketchybar/config/utils.lua index 12c3163..dac811e 100644 --- a/darwin/sketchybar/config/utils.lua +++ b/darwin/sketchybar/config/utils.lua @@ -18,7 +18,7 @@ function M.dump(o) end 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 -- https://github.com/Tnixc/nix-config/blob/main/home/programs/aerospace-sketchybar/sbar-config-libs/items/aerospaces.lua diff --git a/flake.nix b/flake.nix index 3b087c9..b636de2 100644 --- a/flake.nix +++ b/flake.nix @@ -87,7 +87,9 @@ { pkgs, ... }: treefmt-nix.lib.evalModule pkgs { 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" ]; } ); @@ -137,7 +139,7 @@ sops age ssh-to-age - nixfmt-rfc-style + # nixfmt-rfc-style ]; DIRENV_LOG_FORMAT = ""; };