Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: lua-based sketchybar configs #36

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions home-manager/darwin/sketchybar/bar.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local colors = require("colors")

-- Equivalent to the --bar domain
sbar.bar({
topmost = "window",
height = 40,
color = colors.bar.bg,
padding_right = 2,
padding_left = 2,
})
28 changes: 28 additions & 0 deletions home-manager/darwin/sketchybar/colors.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
return {
black = 0xff181819,
white = 0xffe2e2e3,
red = 0xfffc5d7c,
green = 0xff9ed072,
blue = 0xff76cce0,
yellow = 0xffe7c664,
orange = 0xfff39660,
magenta = 0xffb39df3,
grey = 0xff7f8490,
transparent = 0x00000000,

bar = {
bg = 0xf02c2e34,
border = 0xff2c2e34,
},
popup = {
bg = 0xc02c2e34,
border = 0xff7f8490
},
bg1 = 0xff363944,
bg2 = 0xff414550,

with_alpha = function(color, alpha)
if alpha > 1.0 or alpha < 0.0 then return color end
return (color & 0x00ffffff) | (math.floor(alpha * 255.0) << 24)
end,
}
52 changes: 52 additions & 0 deletions home-manager/darwin/sketchybar/default.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
local settings = require("settings")
local colors = require("colors")

-- Equivalent to the --default domain
sbar.default({
updates = "when_shown",
icon = {
font = {
family = settings.font.text,
style = settings.font.style_map["Bold"],
size = 14.0
},
color = colors.white,
padding_left = settings.paddings,
padding_right = settings.paddings,
background = { image = { corner_radius = 9 } },
},
label = {
font = {
family = settings.font.text,
style = settings.font.style_map["Semibold"],
size = 13.0
},
color = colors.white,
padding_left = settings.paddings,
padding_right = settings.paddings,
},
background = {
height = 28,
corner_radius = 9,
border_width = 2,
border_color = colors.bg2,
image = {
corner_radius = 9,
border_color = colors.grey,
border_width = 1
}
},
popup = {
background = {
border_width = 2,
corner_radius = 9,
border_color = colors.popup.border,
color = colors.popup.bg,
shadow = { drawing = true },
},
blur_radius = 50,
},
padding_left = 5,
padding_right = 5,
scroll_texts = true,
})
1 change: 1 addition & 0 deletions home-manager/darwin/sketchybar/helpers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin
211 changes: 211 additions & 0 deletions home-manager/darwin/sketchybar/helpers/app_icons.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
return {
["Typora"] = ":text:",
["Orion"] = ":orion:",
["Orion RC"] = ":orion:",
["Grammarly Editor"] = ":grammarly:",
["kitty"] = ":kitty:",
["ClickUp"] = ":click_up:",
["Iris"] = ":iris:",
["PomoDone App"] = ":pomodone:",
["qutebrowser"] = ":qute_browser:",
["Raindrop.io"] = ":raindrop_io:",
["Airmail"] = ":airmail:",
["Affinity Publisher 2"] = ":affinity_publisher_2:",
["Calendar"] = ":calendar:",
["日历"] = ":calendar:",
["Fantastical"] = ":calendar:",
["Cron"] = ":calendar:",
["Amie"] = ":calendar:",
["Figma"] = ":figma:",
["Element"] = ":element:",
["Signal"] = ":signal:",
["Mattermost"] = ":mattermost:",
["Caprine"] = ":caprine:",
["Microsoft To Do"] = ":things:",
["Things"] = ":things:",
["Godot"] = ":godot:",
["Android Messages"] = ":android_messages:",
["Zed"] = ":zed:",
["Anytype"] = ":anytype:",
["TeamSpeak 3"] = ":team_speak:",
["LibreWolf"] = ":libre_wolf:",
["Neovide"] = ":neovide:",
["neovide"] = ":neovide:",
["Spotlight"] = ":spotlight:",
["微信"] = ":wechat:",
["Dropbox"] = ":dropbox:",
["Transmit"] = ":transmit:",
["TickTick"] = ":tick_tick:",
["Parallels Desktop"] = ":parallels:",
["Audacity"] = ":audacity:",
["Rider"] = ":rider:",
["JetBrains Rider"] = ":rider:",
["DEVONthink 3"] = ":devonthink3:",
["Docker"] = ":docker:",
["Docker Desktop"] = ":docker:",
["Matlab"] = ":matlab:",
["VLC"] = ":vlc:",
["Alacritty"] = ":alacritty:",
["Pages"] = ":pages:",
["Pages 文稿"] = ":pages:",
["Bear"] = ":bear:",
["Pine"] = ":pine:",
["Affinity Designer 2"] = ":affinity_designer_2:",
["Keyboard Maestro"] = ":keyboard_maestro:",
["Joplin"] = ":joplin:",
["mpv"] = ":mpv:",
["zoom.us"] = ":zoom:",
["Affinity Photo 2"] = ":affinity_photo_2:",
["Music"] = ":music:",
["音乐"] = ":music:",
["League of Legends"] = ":league_of_legends:",
["Tor Browser"] = ":tor_browser:",
["Hyper"] = ":hyper:",
["‎WhatsApp"] = ":whats_app:",
["카카오톡"] = ":kakaotalk:",
["Discord"] = ":discord:",
["Discord Canary"] = ":discord:",
["Discord PTB"] = ":discord:",
["Neovide"] = ":vim:",
["MacVim"] = ":vim:",
["Vim"] = ":vim:",
["VimR"] = ":vim:",
["Keynote"] = ":keynote:",
["Keynote 讲演"] = ":keynote:",
["iTerm"] = ":iterm:",
["IntelliJ IDEA"] = ":idea:",
["Finder"] = ":finder:",
["访达"] = ":finder:",
["Xcode"] = ":xcode:",
["GoLand"] = ":goland:",
["Android Studio"] = ":android_studio:",
["MoneyMoney"] = ":bank:",
["Spotify"] = ":spotify:",
["KeePassXC"] = ":kee_pass_x_c:",
["Alfred"] = ":alfred:",
["Color Picker"] = ":color_picker:",
["数码测色计"] = ":color_picker:",
["Microsoft Word"] = ":microsoft_word:",
["Microsoft PowerPoint"] = ":microsoft_power_point:",
["Notes"] = ":notes:",
["备忘录"] = ":notes:",
["Microsoft Edge"] = ":microsoft_edge:",
["Sublime Text"] = ":sublime_text:",
["Sequel Ace"] = ":sequel_ace:",
["Folx"] = ":folx:",
["DingTalk"] = ":dingtalk:",
["钉钉"] = ":dingtalk:",
["阿里钉"] = ":dingtalk:",
["WebStorm"] = ":web_storm:",
["Sequel Pro"] = ":sequel_pro:",
["Skype"] = ":skype:",
["网易云音乐"] = ":netease_music:",
["PyCharm"] = ":pycharm:",
["Canary Mail"] = ":mail:",
["HEY"] = ":mail:",
["Mail"] = ":mail:",
["Mailspring"] = ":mail:",
["MailMate"] = ":mail:",
["邮件"] = ":mail:",
["Default"] = ":default:",
["App Store"] = ":app_store:",
["Calibre"] = ":book:",
["Todoist"] = ":todoist:",
["Emacs"] = ":emacs:",
["Messenger"] = ":messenger:",
["Tower"] = ":tower:",
["VSCodium"] = ":vscodium:",
["Drafts"] = ":drafts:",
["Cypress"] = ":cypress:",
["GitHub Desktop"] = ":git_hub:",
["Telegram"] = ":telegram:",
["Firefox Developer Edition"] = ":firefox_developer_edition:",
["Firefox Nightly"] = ":firefox_developer_edition:",
["Min"] = ":min_browser:",
["Sketch"] = ":sketch:",
["Affinity Photo"] = ":affinity_photo:",
["MAMP"] = ":mamp:",
["MAMP PRO"] = ":mamp:",
["Insomnia"] = ":insomnia:",
["Bitwarden"] = ":bit_warden:",
["Warp"] = ":warp:",
["System Preferences"] = ":gear:",
["System Settings"] = ":gear:",
["系统设置"] = ":gear:",
["Affinity Designer"] = ":affinity_designer:",
["Live"] = ":ableton:",
["Arc"] = ":arc:",
["Chromium"] = ":google_chrome:",
["Google Chrome"] = ":google_chrome:",
["Google Chrome Canary"] = ":google_chrome:",
["Jellyfin Media Player"] = ":jellyfin:",
["Zulip"] = ":zulip:",
["1Password"] = ":one_password:",
["FaceTime"] = ":face_time:",
["FaceTime 通话"] = ":face_time:",
["Citrix Workspace"] = ":citrix:",
["Citrix Viewer"] = ":citrix:",
["Logseq"] = ":logseq:",
["Reeder"] = ":reeder5:",
["Code"] = ":code:",
["Code - Insiders"] = ":code:",
["Notion"] = ":notion:",
["Final Cut Pro"] = ":final_cut_pro:",
["Zotero"] = ":zotero:",
["Safari"] = ":safari:",
["Safari浏览器"] = ":safari:",
["Safari Technology Preview"] = ":safari:",
["Blender"] = ":blender:",
["Affinity Publisher"] = ":affinity_publisher:",
["Spark Desktop"] = ":spark:",
["Zeplin"] = ":zeplin:",
["Replit"] = ":replit:",
["Podcasts"] = ":podcasts:",
["播客"] = ":podcasts:",
["NordVPN"] = ":nord_vpn:",
["Notability"] = ":notability:",
["Numbers"] = ":numbers:",
["Numbers 表格"] = ":numbers:",
["Nova"] = ":nova:",
["Microsoft Excel"] = ":microsoft_excel:",
["Trello"] = ":trello:",
["Pi-hole Remote"] = ":pihole:",
["Linear"] = ":linear:",
["CleanMyMac X"] = ":desktop:",
["GrandTotal"] = ":dollar:",
["Receipts"] = ":dollar:",
["Evernote Legacy"] = ":evernote_legacy:",
["OmniFocus"] = ":omni_focus:",
["Terminal"] = ":terminal:",
["终端"] = ":terminal:",
["Atom"] = ":atom:",
["Kakoune"] = ":kakoune:",
["Reminders"] = ":reminders:",
["提醒事项"] = ":reminders:",
["Tana"] = ":tana:",
["OBS"] = ":obsstudio:",
["VMware Fusion"] = ":vmware_fusion:",
["Tweetbot"] = ":twitter:",
["Twitter"] = ":twitter:",
["Microsoft Teams"] = ":microsoft_teams:",
["Yuque"] = ":yuque:",
["语雀"] = ":yuque:",
["Slack"] = ":slack:",
["Vivaldi"] = ":vivaldi:",
["Setapp"] = ":setapp:",
["TIDAL"] = ":tidal:",
["Miro"] = ":miro:",
["Messages"] = ":messages:",
["信息"] = ":messages:",
["Nachrichten"] = ":messages:",
["Brave Browser"] = ":brave_browser:",
["Preview"] = ":pdf:",
["预览"] = ":pdf:",
["Skim"] = ":pdf:",
["zathura"] = ":pdf:",
["Obsidian"] = ":obsidian:",
["Thunderbird"] = ":thunderbird:",
["Firefox"] = ":firefox:",
["WezTerm"] = ":wezterm:",
["default"] = ":default:",
}
13 changes: 13 additions & 0 deletions home-manager/darwin/sketchybar/helpers/default_font.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
return {
text = "SF Pro", -- Used for text
numbers = "SF Mono", -- Used for numbers

-- Unified font style map
style_map = {
["Regular"] = "Regular",
["Semibold"] = "Semibold",
["Bold"] = "Bold",
["Heavy"] = "Heavy",
["Black"] = "Black",
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <mach/mach.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>

struct cpu {
host_t host;
mach_msg_type_number_t count;
host_cpu_load_info_data_t load;
host_cpu_load_info_data_t prev_load;
bool has_prev_load;

int user_load;
int sys_load;
int total_load;
};

static inline void cpu_init(struct cpu* cpu) {
cpu->host = mach_host_self();
cpu->count = HOST_CPU_LOAD_INFO_COUNT;
cpu->has_prev_load = false;
}

static inline void cpu_update(struct cpu* cpu) {
kern_return_t error = host_statistics(cpu->host,
HOST_CPU_LOAD_INFO,
(host_info_t)&cpu->load,
&cpu->count );

if (error != KERN_SUCCESS) {
printf("Error: Could not read cpu host statistics.\n");
return;
}

if (cpu->has_prev_load) {
uint32_t delta_user = cpu->load.cpu_ticks[CPU_STATE_USER]
- cpu->prev_load.cpu_ticks[CPU_STATE_USER];

uint32_t delta_system = cpu->load.cpu_ticks[CPU_STATE_SYSTEM]
- cpu->prev_load.cpu_ticks[CPU_STATE_SYSTEM];

uint32_t delta_idle = cpu->load.cpu_ticks[CPU_STATE_IDLE]
- cpu->prev_load.cpu_ticks[CPU_STATE_IDLE];

cpu->user_load = (double)delta_user / (double)(delta_system
+ delta_user
+ delta_idle) * 100.0;

cpu->sys_load = (double)delta_system / (double)(delta_system
+ delta_user
+ delta_idle) * 100.0;

cpu->total_load = cpu->user_load + cpu->sys_load;
}

cpu->prev_load = cpu->load;
cpu->has_prev_load = true;
}
Loading