mirror of
https://codeberg.org/tmayoff/.dotfiles.git
synced 2025-12-06 08:48:34 -05:00
added sketchybar config
This commit is contained in:
parent
87bb07f015
commit
95ebd7af03
38 changed files with 2329 additions and 0 deletions
100
dot_config/sketchybar/items/widgets/battery.lua
Normal file
100
dot_config/sketchybar/items/widgets/battery.lua
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
local icons = require("icons")
|
||||
local colors = require("colors")
|
||||
local settings = require("settings")
|
||||
|
||||
local battery = sbar.add("item", "widgets.battery", {
|
||||
position = "right",
|
||||
icon = {
|
||||
font = {
|
||||
style = settings.font.style_map["Regular"],
|
||||
size = 19.0,
|
||||
}
|
||||
},
|
||||
label = { font = { family = settings.font.numbers } },
|
||||
update_freq = 180,
|
||||
popup = { align = "center" }
|
||||
})
|
||||
|
||||
local remaining_time = sbar.add("item", {
|
||||
position = "popup." .. battery.name,
|
||||
icon = {
|
||||
string = "Time remaining:",
|
||||
width = 100,
|
||||
align = "left"
|
||||
},
|
||||
label = {
|
||||
string = "??:??h",
|
||||
width = 100,
|
||||
align = "right"
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
battery:subscribe({"routine", "power_source_change", "system_woke"}, function()
|
||||
sbar.exec("pmset -g batt", function(batt_info)
|
||||
local icon = "!"
|
||||
local label = "?"
|
||||
|
||||
local found, _, charge = batt_info:find("(%d+)%%")
|
||||
if found then
|
||||
charge = tonumber(charge)
|
||||
label = charge .. "%"
|
||||
end
|
||||
|
||||
local color = colors.green
|
||||
local charging, _, _ = batt_info:find("AC Power")
|
||||
|
||||
if charging then
|
||||
icon = icons.battery.charging
|
||||
else
|
||||
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
|
||||
color = colors.orange
|
||||
else
|
||||
icon = icons.battery._0
|
||||
color = colors.red
|
||||
end
|
||||
end
|
||||
|
||||
local lead = ""
|
||||
if found and charge < 10 then
|
||||
lead = "0"
|
||||
end
|
||||
|
||||
battery:set({
|
||||
icon = {
|
||||
string = icon,
|
||||
color = color
|
||||
},
|
||||
label = { string = lead .. label },
|
||||
})
|
||||
end)
|
||||
end)
|
||||
|
||||
battery:subscribe("mouse.clicked", function(env)
|
||||
local drawing = battery:query().popup.drawing
|
||||
battery:set( { popup = { drawing = "toggle" } })
|
||||
|
||||
if drawing == "off" then
|
||||
sbar.exec("pmset -g batt", function(batt_info)
|
||||
local found, _, remaining = batt_info:find(" (%d+:%d+) remaining")
|
||||
local label = found and remaining .. "h" or "No estimate"
|
||||
remaining_time:set( { label = label })
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
sbar.add("bracket", "widgets.battery.bracket", { battery.name }, {
|
||||
background = { color = colors.bg1 }
|
||||
})
|
||||
|
||||
sbar.add("item", "widgets.battery.padding", {
|
||||
position = "right",
|
||||
width = settings.group_paddings
|
||||
})
|
||||
69
dot_config/sketchybar/items/widgets/cpu.lua
Normal file
69
dot_config/sketchybar/items/widgets/cpu.lua
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
local icons = require("icons")
|
||||
local colors = require("colors")
|
||||
local settings = require("settings")
|
||||
|
||||
-- Execute the event provider binary which provides the event "cpu_update" for
|
||||
-- the cpu load data, which is fired every 2.0 seconds.
|
||||
sbar.exec("killall cpu_load >/dev/null; $CONFIG_DIR/helpers/event_providers/cpu_load/bin/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
|
||||
})
|
||||
|
||||
cpu:subscribe("cpu_update", function(env)
|
||||
-- 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
|
||||
|
||||
cpu:set({
|
||||
graph = { color = color },
|
||||
label = "cpu " .. env.total_load .. "%",
|
||||
})
|
||||
end)
|
||||
|
||||
cpu:subscribe("mouse.clicked", function(env)
|
||||
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 around the cpu item
|
||||
sbar.add("item", "widgets.cpu.padding", {
|
||||
position = "right",
|
||||
width = settings.group_paddings
|
||||
})
|
||||
4
dot_config/sketchybar/items/widgets/init.lua
Normal file
4
dot_config/sketchybar/items/widgets/init.lua
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
require("items.widgets.battery")
|
||||
require("items.widgets.volume")
|
||||
require("items.widgets.wifi")
|
||||
require("items.widgets.cpu")
|
||||
152
dot_config/sketchybar/items/widgets/volume.lua
Normal file
152
dot_config/sketchybar/items/widgets/volume.lua
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
local colors = require("colors")
|
||||
local icons = require("icons")
|
||||
local settings = require("settings")
|
||||
|
||||
local popup_width = 250
|
||||
|
||||
local volume_percent = sbar.add("item", "widgets.volume1", {
|
||||
position = "right",
|
||||
icon = { drawing = false },
|
||||
label = {
|
||||
string = "??%",
|
||||
padding_left = -1,
|
||||
font = { family = settings.font.numbers }
|
||||
},
|
||||
})
|
||||
|
||||
local volume_icon = sbar.add("item", "widgets.volume2", {
|
||||
position = "right",
|
||||
padding_right = -1,
|
||||
icon = {
|
||||
string = icons.volume._100,
|
||||
width = 0,
|
||||
align = "left",
|
||||
color = colors.grey,
|
||||
font = {
|
||||
style = settings.font.style_map["Regular"],
|
||||
size = 14.0,
|
||||
},
|
||||
},
|
||||
label = {
|
||||
width = 25,
|
||||
align = "left",
|
||||
font = {
|
||||
style = settings.font.style_map["Regular"],
|
||||
size = 14.0,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
local volume_bracket = sbar.add("bracket", "widgets.volume.bracket", {
|
||||
volume_icon.name,
|
||||
volume_percent.name
|
||||
}, {
|
||||
background = { color = colors.bg1 },
|
||||
popup = { align = "center" }
|
||||
})
|
||||
|
||||
sbar.add("item", "widgets.volume.padding", {
|
||||
position = "right",
|
||||
width = settings.group_paddings
|
||||
})
|
||||
|
||||
local volume_slider = sbar.add("slider", popup_width, {
|
||||
position = "popup." .. volume_bracket.name,
|
||||
slider = {
|
||||
highlight_color = colors.blue,
|
||||
background = {
|
||||
height = 6,
|
||||
corner_radius = 3,
|
||||
color = colors.bg2,
|
||||
},
|
||||
knob= {
|
||||
string = "",
|
||||
drawing = true,
|
||||
},
|
||||
},
|
||||
background = { color = colors.bg1, height = 2, y_offset = -20 },
|
||||
click_script = 'osascript -e "set volume output volume $PERCENTAGE"'
|
||||
})
|
||||
|
||||
volume_percent: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 lead = ""
|
||||
if volume < 10 then
|
||||
lead = "0"
|
||||
end
|
||||
|
||||
volume_icon:set({ label = icon })
|
||||
volume_percent:set({ label = lead .. volume .. "%" })
|
||||
volume_slider:set({ slider = { percentage = volume } })
|
||||
end)
|
||||
|
||||
local function volume_collapse_details()
|
||||
local drawing = volume_bracket:query().popup.drawing == "on"
|
||||
if not drawing then return end
|
||||
volume_bracket:set({ popup = { drawing = false } })
|
||||
sbar.remove('/volume.device\\.*/')
|
||||
end
|
||||
|
||||
local current_audio_device = "None"
|
||||
local function volume_toggle_details(env)
|
||||
if env.BUTTON == "right" then
|
||||
sbar.exec("open /System/Library/PreferencePanes/Sound.prefpane")
|
||||
return
|
||||
end
|
||||
|
||||
local should_draw = volume_bracket:query().popup.drawing == "off"
|
||||
if should_draw then
|
||||
volume_bracket:set({ popup = { drawing = true } })
|
||||
sbar.exec("SwitchAudioSource -t output -c", function(result)
|
||||
current_audio_device = result:sub(1, -2)
|
||||
sbar.exec("SwitchAudioSource -a -t output", function(available)
|
||||
current = current_audio_device
|
||||
local color = colors.grey
|
||||
local counter = 0
|
||||
|
||||
for device in string.gmatch(available, '[^\r\n]+') do
|
||||
local color = colors.grey
|
||||
if current == device then
|
||||
color = colors.white
|
||||
end
|
||||
sbar.add("item", "volume.device." .. counter, {
|
||||
position = "popup." .. volume_bracket.name,
|
||||
width = popup_width,
|
||||
align = "center",
|
||||
label = { string = device, color = color },
|
||||
click_script = 'SwitchAudioSource -s "' .. device .. '" && sketchybar --set /volume.device\\.*/ label.color=' .. colors.grey .. ' --set $NAME label.color=' .. colors.white
|
||||
|
||||
})
|
||||
counter = counter + 1
|
||||
end
|
||||
end)
|
||||
end)
|
||||
else
|
||||
volume_collapse_details()
|
||||
end
|
||||
end
|
||||
|
||||
local function volume_scroll(env)
|
||||
local delta = env.INFO.delta
|
||||
if not (env.INFO.modifier == "ctrl") then delta = delta * 10.0 end
|
||||
|
||||
sbar.exec('osascript -e "set volume output volume (output volume of (get volume settings) + ' .. delta .. ')"')
|
||||
end
|
||||
|
||||
volume_icon:subscribe("mouse.clicked", volume_toggle_details)
|
||||
volume_icon:subscribe("mouse.scrolled", volume_scroll)
|
||||
volume_percent:subscribe("mouse.clicked", volume_toggle_details)
|
||||
volume_percent:subscribe("mouse.exited.global", volume_collapse_details)
|
||||
volume_percent:subscribe("mouse.scrolled", volume_scroll)
|
||||
|
||||
234
dot_config/sketchybar/items/widgets/wifi.lua
Normal file
234
dot_config/sketchybar/items/widgets/wifi.lua
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
local icons = require("icons")
|
||||
local colors = require("colors")
|
||||
local settings = require("settings")
|
||||
|
||||
-- Execute the event provider binary which provides the event "network_update"
|
||||
-- for the network interface "en0", which is fired every 2.0 seconds.
|
||||
sbar.exec("killall network_load >/dev/null; $CONFIG_DIR/helpers/event_providers/network_load/bin/network_load en0 network_update 2.0")
|
||||
|
||||
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,
|
||||
})
|
||||
|
||||
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,
|
||||
})
|
||||
|
||||
local wifi = sbar.add("item", "widgets.wifi.padding", {
|
||||
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
|
||||
}, {
|
||||
background = { color = colors.bg1 },
|
||||
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.grey,
|
||||
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",
|
||||
}
|
||||
})
|
||||
|
||||
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",
|
||||
}
|
||||
})
|
||||
|
||||
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",
|
||||
}
|
||||
})
|
||||
|
||||
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",
|
||||
},
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
})
|
||||
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 } })
|
||||
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
|
||||
end
|
||||
|
||||
wifi_up:subscribe("mouse.clicked", toggle_details)
|
||||
wifi_down:subscribe("mouse.clicked", toggle_details)
|
||||
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)
|
||||
end
|
||||
|
||||
ssid:subscribe("mouse.clicked", copy_label_to_clipboard)
|
||||
hostname:subscribe("mouse.clicked", copy_label_to_clipboard)
|
||||
ip:subscribe("mouse.clicked", copy_label_to_clipboard)
|
||||
mask:subscribe("mouse.clicked", copy_label_to_clipboard)
|
||||
router:subscribe("mouse.clicked", copy_label_to_clipboard)
|
||||
Loading…
Add table
Add a link
Reference in a new issue