update sketchybar

This commit is contained in:
Natalie 2025-05-19 17:17:16 -07:00
parent 844318f221
commit 1a6ac2017d
No known key found for this signature in database
GPG key ID: 61F4EAEB0C9C3D5F
23 changed files with 482 additions and 1574 deletions

View file

@ -1,120 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <mach/mach.h>
#include <stdbool.h>
#include <time.h>
static const char TOPPROC[32] = { "/bin/ps -Aceo pid,pcpu,comm -r" };
static const char FILTER_PATTERN[16] = { "com.apple." };
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;
char command[256];
};
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;
snprintf(cpu->command, 100, "");
}
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];
double user_perc = (double)delta_user / (double)(delta_system
+ delta_user
+ delta_idle);
double sys_perc = (double)delta_system / (double)(delta_system
+ delta_user
+ delta_idle);
double total_perc = user_perc + sys_perc;
FILE* file;
char line[1024];
file = popen(TOPPROC, "r");
if (!file) {
printf("Error: TOPPROC command errored out...\n" );
return;
}
fgets(line, sizeof(line), file);
fgets(line, sizeof(line), file);
char* start = strstr(line, FILTER_PATTERN);
char topproc[32];
uint32_t caret = 0;
for (int i = 0; i < sizeof(line); i++) {
if (start && i == start - line) {
i+=9;
continue;
}
if (caret >= 28 && caret <= 30) {
topproc[caret++] = '.';
continue;
}
if (caret > 30) break;
topproc[caret++] = line[i];
if (line[i] == '\0') break;
}
topproc[31] = '\0';
pclose(file);
char color[16];
if (total_perc >= .7) {
snprintf(color, 16, "%s", getenv("RED"));
} else if (total_perc >= .3) {
snprintf(color, 16, "%s", getenv("ORANGE"));
} else if (total_perc >= .1) {
snprintf(color, 16, "%s", getenv("YELLOW"));
} else {
snprintf(color, 16, "%s", getenv("LABEL_COLOR"));
}
snprintf(cpu->command, 256, "--push cpu.sys %.2f "
"--push cpu.user %.2f "
"--set cpu.percent label=%.0f%% label.color=%s "
"--set cpu.top label=\"%s\"",
sys_perc,
user_perc,
total_perc*100.,
color,
topproc );
}
else {
snprintf(cpu->command, 256, "");
}
cpu->prev_load = cpu->load;
cpu->has_prev_load = true;
}

View file

@ -1,32 +0,0 @@
#include "cpu.h"
#include "sketchybar.h"
struct cpu g_cpu;
void handler(env env) {
// Environment variables passed from sketchybar can be accessed as seen below
char* name = env_get_value_for_key(env, "NAME");
char* sender = env_get_value_for_key(env, "SENDER");
char* info = env_get_value_for_key(env, "INFO");
char* selected = env_get_value_for_key(env, "SELECTED");
if ((strcmp(sender, "routine") == 0)
|| (strcmp(sender, "forced") == 0)) {
// CPU graph updates
cpu_update(&g_cpu);
if (strlen(g_cpu.command) > 0) sketchybar(g_cpu.command);
}
}
int main (int argc, char** argv) {
cpu_init(&g_cpu);
if (argc < 2) {
printf("Usage: provider \"<bootstrap name>\"\n");
exit(1);
}
event_server_begin(handler, argv[1]);
return 0;
}

View file

@ -1,3 +0,0 @@
helper: helper.c cpu.h sketchybar.h
clang -std=c99 -O3 helper.c -o helper

View file

@ -1,227 +0,0 @@
#pragma once
#include <mach/mach.h>
#include <mach/message.h>
#include <bootstrap.h>
#include <stdlib.h>
#include <pthread.h>
#include <stdio.h>
typedef char* env;
#define MACH_HANDLER(name) void name(env env)
typedef MACH_HANDLER(mach_handler);
struct mach_message {
mach_msg_header_t header;
mach_msg_size_t msgh_descriptor_count;
mach_msg_ool_descriptor_t descriptor;
};
struct mach_buffer {
struct mach_message message;
mach_msg_trailer_t trailer;
};
struct mach_server {
bool is_running;
mach_port_name_t task;
mach_port_t port;
mach_port_t bs_port;
pthread_t thread;
mach_handler* handler;
};
static struct mach_server g_mach_server;
static mach_port_t g_mach_port = 0;
static inline char* env_get_value_for_key(env env, char* key) {
uint32_t caret = 0;
for(;;) {
if (!env[caret]) break;
if (strcmp(&env[caret], key) == 0)
return &env[caret + strlen(&env[caret]) + 1];
caret += strlen(&env[caret])
+ strlen(&env[caret + strlen(&env[caret]) + 1])
+ 2;
}
return (char*)"";
}
static inline mach_port_t mach_get_bs_port() {
mach_port_name_t task = mach_task_self();
mach_port_t bs_port;
if (task_get_special_port(task,
TASK_BOOTSTRAP_PORT,
&bs_port ) != KERN_SUCCESS) {
return 0;
}
mach_port_t port;
if (bootstrap_look_up(bs_port,
"git.felix.sketchybar",
&port ) != KERN_SUCCESS) {
return 0;
}
return port;
}
static inline void mach_receive_message(mach_port_t port, struct mach_buffer* buffer, bool timeout) {
*buffer = (struct mach_buffer) { 0 };
mach_msg_return_t msg_return;
if (timeout)
msg_return = mach_msg(&buffer->message.header,
MACH_RCV_MSG | MACH_RCV_TIMEOUT,
0,
sizeof(struct mach_buffer),
port,
100,
MACH_PORT_NULL );
else
msg_return = mach_msg(&buffer->message.header,
MACH_RCV_MSG,
0,
sizeof(struct mach_buffer),
port,
MACH_MSG_TIMEOUT_NONE,
MACH_PORT_NULL );
if (msg_return != MACH_MSG_SUCCESS) {
buffer->message.descriptor.address = NULL;
}
}
static inline char* mach_send_message(mach_port_t port, char* message, uint32_t len) {
if (!message || !port) {
return NULL;
}
mach_port_t response_port;
mach_port_name_t task = mach_task_self();
if (mach_port_allocate(task, MACH_PORT_RIGHT_RECEIVE,
&response_port ) != KERN_SUCCESS) {
return NULL;
}
if (mach_port_insert_right(task, response_port,
response_port,
MACH_MSG_TYPE_MAKE_SEND)!= KERN_SUCCESS) {
return NULL;
}
struct mach_message msg = { 0 };
msg.header.msgh_remote_port = port;
msg.header.msgh_local_port = response_port;
msg.header.msgh_id = response_port;
msg.header.msgh_bits = MACH_MSGH_BITS_SET(MACH_MSG_TYPE_COPY_SEND,
MACH_MSG_TYPE_MAKE_SEND,
0,
MACH_MSGH_BITS_COMPLEX );
msg.header.msgh_size = sizeof(struct mach_message);
msg.msgh_descriptor_count = 1;
msg.descriptor.address = message;
msg.descriptor.size = len * sizeof(char);
msg.descriptor.copy = MACH_MSG_VIRTUAL_COPY;
msg.descriptor.deallocate = false;
msg.descriptor.type = MACH_MSG_OOL_DESCRIPTOR;
mach_msg(&msg.header,
MACH_SEND_MSG,
sizeof(struct mach_message),
0,
MACH_PORT_NULL,
MACH_MSG_TIMEOUT_NONE,
MACH_PORT_NULL );
struct mach_buffer buffer = { 0 };
mach_receive_message(response_port, &buffer, true);
if (buffer.message.descriptor.address)
return (char*)buffer.message.descriptor.address;
mach_msg_destroy(&buffer.message.header);
return NULL;
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
static inline bool mach_server_begin(struct mach_server* mach_server, mach_handler handler, char* bootstrap_name) {
mach_server->task = mach_task_self();
if (mach_port_allocate(mach_server->task,
MACH_PORT_RIGHT_RECEIVE,
&mach_server->port ) != KERN_SUCCESS) {
return false;
}
if (mach_port_insert_right(mach_server->task,
mach_server->port,
mach_server->port,
MACH_MSG_TYPE_MAKE_SEND) != KERN_SUCCESS) {
return false;
}
if (task_get_special_port(mach_server->task,
TASK_BOOTSTRAP_PORT,
&mach_server->bs_port) != KERN_SUCCESS) {
return false;
}
if (bootstrap_register(mach_server->bs_port,
bootstrap_name,
mach_server->port ) != KERN_SUCCESS) {
return false;
}
mach_server->handler = handler;
mach_server->is_running = true;
while (mach_server->is_running) {
struct mach_buffer* buffer = (struct mach_buffer*)malloc(sizeof(struct mach_buffer));
mach_receive_message(mach_server->port, buffer, false);
mach_server->handler((env)buffer->message.descriptor.address);
mach_msg_destroy(&buffer->message.header);
}
return true;
}
#pragma clang diagnostic pop
static inline char* sketchybar(char* message) {
uint32_t message_length = strlen(message) + 1;
char formatted_message[message_length + 1];
char quote = '\0';
uint32_t caret = 0;
for (int i = 0; i < message_length; ++i) {
if (message[i] == '"' || message[i] == '\'') {
if (quote == message[i]) quote = '\0';
else quote = message[i];
continue;
}
formatted_message[caret] = message[i];
if (message[i] == ' ' && !quote) formatted_message[caret] = '\0';
caret++;
}
if (caret > 0 && formatted_message[caret] == '\0'
&& formatted_message[caret - 1] == '\0') {
caret--;
}
formatted_message[caret] = '\0';
if (!g_mach_port) g_mach_port = mach_get_bs_port();
char* response = mach_send_message(g_mach_port,
formatted_message,
caret + 1 );
if (response) return response;
else return (char*)"";
}
static inline void event_server_begin(mach_handler event_handler, char* bootstrap_name) {
mach_server_begin(&g_mach_server, event_handler, bootstrap_name);
}

View file

@ -1,31 +0,0 @@
#!/usr/bin/env sh
# General Icons
LOADING=􀖇
APPLE=􀣺
PREFERENCES=􀺽
ACTIVITY=􀒓
LOCK=􀒳
BELL=􀋚
BELL_DOT=􀝗
# Git Icons
GIT_ISSUE=􀍷
GIT_DISCUSSION=􀒤
GIT_PULL_REQUEST=􀙡
GIT_COMMIT=􀡚
GIT_INDICATOR=􀂓
# Spotify Icons
SPOTIFY_BACK=􀊎
SPOTIFY_PLAY_PAUSE=􀊈
SPOTIFY_NEXT=􀊐
SPOTIFY_SHUFFLE=􀊝
SPOTIFY_REPEAT=􀊞
# Yabai Icons
YABAI_STACK=􀏭
YABAI_FULLSCREEN_ZOOM=􀏜
YABAI_PARENT_ZOOM=􀥃
YABAI_FLOAT=􀢌
YABAI_GRID=􀧍

View file

@ -1,31 +0,0 @@
#!/usr/bin/env sh
POPUP_OFF="sketchybar --set apple.logo popup.drawing=off"
POPUP_CLICK_SCRIPT="sketchybar --set \$NAME popup.drawing=toggle"
sketchybar --add item apple.logo left \
\
--set apple.logo icon=$APPLE \
icon.font="$FONT:Black:16.0" \
icon.color=$BLUE2 \
background.padding_right=25 \
label.drawing=off \
click_script="$POPUP_CLICK_SCRIPT" \
\
--add item apple.prefs popup.apple.logo \
--set apple.prefs icon=$PREFERENCES \
label="Preferences" \
click_script="open -a 'System Preferences';
$POPUP_OFF" \
\
--add item apple.activity popup.apple.logo \
--set apple.activity icon=$ACTIVITY \
label="Activity" \
click_script="open -a 'Activity Monitor';
$POPUP_OFF"\
\
--add item apple.lock popup.apple.logo \
--set apple.lock icon=$LOCK \
label="Lock Screen" \
click_script="pmset displaysleepnow;
$POPUP_OFF"

View file

@ -1,14 +0,0 @@
#!/usr/bin/env sh
# Trigger the brew_udpate event when brew update or upgrade is run from cmdline
# e.g. via function in .zshrc
sketchybar --add event brew_update \
--add item brew right \
--set brew script="$PLUGIN_DIR/brew.sh" \
icon=󰏗 \
label=? \
label.color=$BLACK \
background.padding_right=15 \
--subscribe brew brew_update

View file

@ -1,37 +0,0 @@
#!/usr/bin/env sh
sketchybar --add item cpu.top right \
--set cpu.top label.font="$FONT:Semibold:7" \
label=CPU \
icon.drawing=off \
width=0 \
y_offset=6 \
\
--add item cpu.percent right \
--set cpu.percent label.font="$FONT:Heavy:12" \
label=CPU \
y_offset=-4 \
width=40 \
icon.drawing=off \
update_freq=2 \
mach_helper="$HELPER" \
\
--add graph cpu.sys right 100 \
--set cpu.sys width=0 \
graph.color=$RED \
graph.fill_color=$RED \
label.drawing=off \
icon.drawing=off \
background.padding_left=10 \
background.height=30 \
background.drawing=on \
background.color=$TRANSPARENT \
\
--add graph cpu.user right 100 \
--set cpu.user graph.color=$BLUE \
label.drawing=off \
icon.drawing=off \
background.padding_left=10 \
background.height=30 \
background.drawing=on \
background.color=$TRANSPARENT

View file

@ -1,9 +0,0 @@
sketchybar --add bracket status brew volume volume_alias \
--set status background.color=$WHITE
# sketchybar --add item divider right \
# --set divider label.drawing=off \
# icon=􀫰 \
# icon.font="$FONT:Black:22.0" \
# background.padding_left=15 \
# background.padding_right=20

View file

@ -1,27 +0,0 @@
#!/usr/bin/env sh
POPUP_CLICK_SCRIPT="sketchybar --set \$NAME popup.drawing=toggle"
sketchybar --add item github.bell right \
--set github.bell update_freq=180 \
icon.font="$FONT:Bold:15.0" \
icon=$BELL \
icon.color=$BLUE \
label=$LOADING \
label.highlight_color=$BLUE \
popup.align=right \
script="$PLUGIN_DIR/github.sh" \
click_script="$POPUP_CLICK_SCRIPT" \
--subscribe github.bell mouse.entered \
mouse.exited \
mouse.exited.global \
\
--add item github.template popup.github.bell \
--set github.template drawing=off \
background.corner_radius=12 \
background.padding_left=7 \
background.padding_right=7 \
background.color=$BLACK \
background.drawing=off \
icon.background.height=2 \
icon.background.y_offset=-12

View file

@ -1,125 +0,0 @@
SPOTIFY_EVENT="com.spotify.client.PlaybackStateChanged"
POPUP_SCRIPT="sketchybar -m --set spotify.anchor popup.drawing=toggle"
sketchybar --add event spotify_change $SPOTIFY_EVENT \
--add item spotify.anchor center \
--set spotify.anchor script="$PLUGIN_DIR/spotify.sh" \
click_script="$POPUP_SCRIPT" \
background.padding_left=22 \
popup.horizontal=on \
popup.align=center \
popup.height=120 \
icon=􁁒 \
icon.font="$FONT:Regular:25.0" \
icon.drawing=off \
label.drawing=off \
drawing=off \
--subscribe spotify.anchor mouse.entered mouse.exited \
mouse.exited.global \
\
--add item spotify.cover popup.spotify.anchor \
--set spotify.cover script="$PLUGIN_DIR/spotify.sh" \
label.drawing=off \
icon.drawing=off \
background.padding_left=12 \
background.padding_right=10 \
background.image.scale=0.15 \
background.image.drawing=on \
background.drawing=on \
\
--add item spotify.title popup.spotify.anchor \
--set spotify.title icon.drawing=off \
background.padding_left=0 \
background.padding_right=0 \
width=0 \
label.font="$FONT:Heavy:14.0" \
y_offset=40 \
\
--add item spotify.artist popup.spotify.anchor \
--set spotify.artist icon.drawing=off \
y_offset=20 \
background.padding_left=0 \
background.padding_right=0 \
width=0 \
\
--add item spotify.album popup.spotify.anchor \
--set spotify.album icon.drawing=off \
background.padding_left=0 \
background.padding_right=0 \
y_offset=3 \
width=0 \
\
--add item spotify.shuffle popup.spotify.anchor \
--set spotify.shuffle icon=􀊝 \
icon.padding_left=5 \
icon.padding_right=5 \
icon.color=$BLACK \
icon.highlight_color=$MAGENTA \
label.drawing=off \
script="$PLUGIN_DIR/spotify.sh" \
y_offset=-30 \
--subscribe spotify.shuffle mouse.clicked \
\
--add item spotify.back popup.spotify.anchor \
--set spotify.back icon=􀊎 \
icon.padding_left=5 \
icon.padding_right=5 \
icon.color=$BLACK \
script="$PLUGIN_DIR/spotify.sh" \
label.drawing=off \
y_offset=-30 \
--subscribe spotify.back mouse.clicked \
\
--add item spotify.play popup.spotify.anchor \
--set spotify.play icon=􀊔 \
background.height=40 \
background.corner_radius=20 \
width=40 \
align=center \
background.color=$BLACK \
background.border_color=$WHITE \
background.border_width=0 \
background.drawing=on \
icon.padding_left=4 \
icon.padding_right=5 \
icon.color=$WHITE \
updates=on \
label.drawing=off \
script="$PLUGIN_DIR/spotify.sh" \
y_offset=-30 \
--subscribe spotify.play mouse.clicked spotify_change \
\
--add item spotify.next popup.spotify.anchor \
--set spotify.next icon=􀊐 \
icon.padding_left=5 \
icon.padding_right=10 \
icon.color=$BLACK \
label.drawing=off \
script="$PLUGIN_DIR/spotify.sh" \
y_offset=-30 \
--subscribe spotify.next mouse.clicked \
\
--add item spotify.repeat popup.spotify.anchor \
--set spotify.repeat icon=􀊞 \
icon.highlight_color=$MAGENTA \
icon.padding_left=5 \
icon.padding_right=10 \
icon.color=$BLACK \
label.drawing=off \
script="$PLUGIN_DIR/spotify.sh" \
y_offset=-30 \
--subscribe spotify.repeat mouse.clicked \
\
--add item spotify.spacer popup.spotify.anchor \
--set spotify.spacer width=5 \
\
--add bracket spotify spotify.shuffle \
spotify.back \
spotify.play \
spotify.next \
spotify.repeat \
--set spotify background.color=$GREEN \
background.corner_radius=11 \
background.drawing=on \
y_offset=-30 \
drawing=off

View file

@ -1,21 +0,0 @@
#!/usr/bin/env sh
source "$HOME/.config/sketchybar/colors.sh"
COUNT=$(brew outdated | wc -l | tr -d ' ')
COLOR=$RED
case "$COUNT" in
[3-5][0-9]) COLOR=$ORANGE
;;
[1-2][0-9]) COLOR=$YELLOW
;;
[1-9]) COLOR=$BLACK
;;
0) COLOR=$GREEN
COUNT=􀆅
;;
esac
sketchybar --set $NAME label=$COUNT icon.color=$COLOR

View file

@ -1,3 +0,0 @@
#!/usr/bin/env sh
sketchybar --set $NAME icon="$(date '+%a %d. %b')" label="$(date '+%H:%M')"

View file

@ -1,87 +0,0 @@
#!/bin/sh
update() {
source "$HOME/.config/sketchybar/colors.sh"
source "$HOME/.config/sketchybar/icons.sh"
NOTIFICATIONS="$(gh api notifications)"
COUNT="$(echo "$NOTIFICATIONS" | jq 'length')"
args=()
if [ "$NOTIFICATIONS" = "[]" ]; then
args+=(--set $NAME icon=$BELL label="0")
else
args+=(--set $NAME icon=$BELL_DOT label="$COUNT")
fi
PREV_COUNT=$(sketchybar --query github.bell | jq -r .label.value)
# For sound to play around with:
# afplay /System/Library/Sounds/Morse.aiff
args+=(--remove '/github.notification\.*/')
COUNTER=0
COLOR=$BLUE
args+=(--set github.bell icon.color=$COLOR)
while read -r repo url type title
do
COUNTER=$((COUNTER + 1))
IMPORTANT="$(echo "$title" | egrep -i "(deprecat|break|broke)")"
COLOR=$BLUE
PADDING=0
if [ "${repo}" = "" ] && [ "${title}" = "" ]; then
repo="Note"
title="No new notifications"
fi
case "${type}" in
"'Issue'") COLOR=$GREEN; ICON=$GIT_ISSUE; URL="$(gh api "$(echo "${url}" | sed -e "s/^'//" -e "s/'$//")" | jq .html_url)"
;;
"'Discussion'") COLOR=$WHITE; ICON=$GIT_DISCUSSION; URL="https://www.github.com/notifications"
;;
"'PullRequest'") COLOR=$MAGENTA; ICON=$GIT_PULL_REQUEST; URL="$(gh api "$(echo "${url}" | sed -e "s/^'//" -e "s/'$//")" | jq .html_url)"
;;
"'Commit'") COLOR=$WHITE; ICON=$GIT_COMMIT; URL="$(gh api "$(echo "${url}" | sed -e "s/^'//" -e "s/'$//")" | jq .html_url)"
;;
esac
if [ "$IMPORTANT" != "" ]; then
COLOR=$RED
ICON=􀁞
args+=(--set github.bell icon.color=$COLOR)
fi
args+=(--clone github.notification.$COUNTER github.template \
--set github.notification.$COUNTER label="$(echo "$title" | sed -e "s/^'//" -e "s/'$//")" \
icon="$ICON $(echo "$repo" | sed -e "s/^'//" -e "s/'$//"):" \
icon.padding_left="$PADDING" \
label.padding_right="$PADDING" \
icon.color=$COLOR \
position=popup.github.bell \
icon.background.color=$COLOR \
drawing=on \
click_script="open $URL;
sketchybar --set github.bell popup.drawing=off")
done <<< "$(echo "$NOTIFICATIONS" | jq -r '.[] | [.repository.name, .subject.latest_comment_url, .subject.type, .subject.title] | @sh')"
sketchybar -m "${args[@]}"
if [ $COUNT -gt $PREV_COUNT ] 2>/dev/null || [ "$SENDER" = "forced" ]; then
sketchybar --animate tanh 15 --set github.bell label.y_offset=5 label.y_offset=0
fi
}
popup() {
sketchybar --set $NAME popup.drawing=$1
}
case "$SENDER" in
"routine"|"forced") update
;;
"mouse.entered") popup on
;;
"mouse.exited"|"mouse.exited.global") popup off
;;
"mouse.clicked") popup toggle
;;
esac

View file

@ -1,381 +0,0 @@
case "$1" in
"Brave Browser")
icon_result=":brave_browser:"
;;
"Keyboard Maestro")
icon_result=":keyboard_maestro:"
;;
"Min")
icon_result=":min_browser:"
;;
"Final Cut Pro")
icon_result=":final_cut_pro:"
;;
"FaceTime")
icon_result=":face_time:"
;;
"Affinity Publisher")
icon_result=":affinity_publisher:"
;;
"Messages" | "Nachrichten")
icon_result=":messages:"
;;
"Tweetbot" | "Twitter")
icon_result=":twitter:"
;;
"ClickUp")
icon_result=":click_up:"
;;
"KeePassXC")
icon_result=":kee_pass_x_c:"
;;
"Microsoft Edge")
icon_result=":microsoft_edge:"
;;
"VLC")
icon_result=":vlc:"
;;
"Emacs")
icon_result=":emacs:"
;;
"Thunderbird")
icon_result=":thunderbird:"
;;
"Notes")
icon_result=":notes:"
;;
"Caprine")
icon_result=":caprine:"
;;
"Zulip")
icon_result=":zulip:"
;;
"Spark")
icon_result=":spark:"
;;
"Microsoft To Do" | "Things")
icon_result=":things:"
;;
"DEVONthink 3")
icon_result=":devonthink3:"
;;
"GitHub Desktop")
icon_result=":git_hub:"
;;
"App Store")
icon_result=":app_store:"
;;
"Chromium" | "Google Chrome" | "Google Chrome Canary")
icon_result=":google_chrome:"
;;
"zoom.us")
icon_result=":zoom:"
;;
"MoneyMoney")
icon_result=":bank:"
;;
"Color Picker")
icon_result=":color_picker:"
;;
"Microsoft Word")
icon_result=":microsoft_word:"
;;
"Iris")
icon_result=":iris:"
;;
"WebStorm")
icon_result=":web_storm:"
;;
"Neovide" | "MacVim" | "Vim" | "VimR")
icon_result=":vim:"
;;
"Sublime Text")
icon_result=":sublime_text:"
;;
"PomoDone App")
icon_result=":pomodone:"
;;
"Setapp")
icon_result=":setapp:"
;;
"qutebrowser")
icon_result=":qute_browser:"
;;
"Mattermost")
icon_result=":mattermost:"
;;
"Notability")
icon_result=":notability:"
;;
"WhatsApp")
icon_result=":whats_app:"
;;
"OBS")
icon_result=":obsstudio:"
;;
"Parallels Desktop")
icon_result=":parallels:"
;;
"VMware Fusion")
icon_result=":vmware_fusion:"
;;
"Pine")
icon_result=":pine:"
;;
"Microsoft Excel")
icon_result=":microsoft_excel:"
;;
"Microsoft PowerPoint")
icon_result=":microsoft_power_point:"
;;
"Matlab")
icon_result=":matlab:"
;;
"Numbers")
icon_result=":numbers:"
;;
"Default")
icon_result=":default:"
;;
"Element")
icon_result=":element:"
;;
"Bear")
icon_result=":bear:"
;;
"TeamSpeak 3")
icon_result=":team_speak:"
;;
"Airmail")
icon_result=":airmail:"
;;
"Firefox Developer Edition" | "Firefox Nightly")
icon_result=":firefox_developer_edition:"
;;
"Trello")
icon_result=":trello:"
;;
"TickTick")
icon_result=":tick_tick:"
;;
"Notion")
icon_result=":notion:"
;;
"Live")
icon_result=":ableton:"
;;
"Evernote Legacy")
icon_result=":evernote_legacy:"
;;
"Calendar" | "Fantastical")
icon_result=":calendar:"
;;
"Android Studio")
icon_result=":android_studio:"
;;
"Xcode")
icon_result=":xcode:"
;;
"Slack")
icon_result=":slack:"
;;
"Sequel Pro")
icon_result=":sequel_pro:"
;;
"Bitwarden")
icon_result=":bit_warden:"
;;
"System Preferences")
icon_result=":gear:"
;;
"Discord" | "Discord Canary" | "Discord PTB")
icon_result=":discord:"
;;
"Vivaldi")
icon_result=":vivaldi:"
;;
"Firefox")
icon_result=":firefox:"
;;
"Skype")
icon_result=":skype:"
;;
"Dropbox")
icon_result=":dropbox:"
;;
"微信")
icon_result=":wechat:"
;;
"Typora")
icon_result=":text:"
;;
"Blender")
icon_result=":blender:"
;;
"Canary Mail" | "HEY" | "Mail" | "Mailspring" | "MailMate" | "邮件")
icon_result=":mail:"
;;
"Safari" | "Safari Technology Preview")
icon_result=":safari:"
;;
"Telegram")
icon_result=":telegram:"
;;
"Keynote")
icon_result=":keynote:"
;;
"Reeder")
icon_result=":reeder5:"
;;
"Spotify")
icon_result=":spotify:"
;;
"MAMP" | "MAMP PRO")
icon_result=":mamp:"
;;
"Figma")
icon_result=":figma:"
;;
"Joplin")
icon_result=":joplin:"
;;
"Spotlight")
icon_result=":spotlight:"
;;
"Music")
icon_result=":music:"
;;
"Insomnia")
icon_result=":insomnia:"
;;
"TIDAL")
icon_result=":tidal:"
;;
"Alfred")
icon_result=":alfred:"
;;
"Pages")
icon_result=":pages:"
;;
"Folx")
icon_result=":folx:"
;;
"Android Messages")
icon_result=":android_messages:"
;;
"mpv")
icon_result=":mpv:"
;;
"网易云音乐")
icon_result=":netease_music:"
;;
"Transmit")
icon_result=":transmit:"
;;
"Pi-hole Remote")
icon_result=":pihole:"
;;
"Nova")
icon_result=":nova:"
;;
"Affinity Designer")
icon_result=":affinity_designer:"
;;
"IntelliJ IDEA")
icon_result=":idea:"
;;
"Drafts")
icon_result=":drafts:"
;;
"Audacity")
icon_result=":audacity:"
;;
"Affinity Photo")
icon_result=":affinity_photo:"
;;
"Atom")
icon_result=":atom:"
;;
"Obsidian")
icon_result=":obsidian:"
;;
"CleanMyMac X")
icon_result=":desktop:"
;;
"Zotero")
icon_result=":zotero:"
;;
"Todoist")
icon_result=":todoist:"
;;
"LibreWolf")
icon_result=":libre_wolf:"
;;
"Grammarly Editor")
icon_result=":grammarly:"
;;
"OmniFocus")
icon_result=":omni_focus:"
;;
"Reminders")
icon_result=":reminders:"
;;
"Preview" | "Skim" | "zathura")
icon_result=":pdf:"
;;
"1Password 7")
icon_result=":one_password:"
;;
"Code" | "Code - Insiders")
icon_result=":code:"
;;
"VSCodium")
icon_result=":vscodium:"
;;
"Tower")
icon_result=":tower:"
;;
"Calibre")
icon_result=":book:"
;;
"Finder" | "访达")
icon_result=":finder:"
;;
"Linear")
icon_result=":linear:"
;;
"League of Legends")
icon_result=":league_of_legends:"
;;
"Zeplin")
icon_result=":zeplin:"
;;
"Signal")
icon_result=":signal:"
;;
"Podcasts")
icon_result=":podcasts:"
;;
"Alacritty" | "Hyper" | "iTerm2" | "kitty" | "Terminal" | "WezTerm")
icon_result=":terminal:"
;;
"Tor Browser")
icon_result=":tor_browser:"
;;
"Kakoune")
icon_result=":kakoune:"
;;
"GrandTotal" | "Receipts")
icon_result=":dollar:"
;;
"Sketch")
icon_result=":sketch:"
;;
"Sequel Ace")
icon_result=":sequel_ace:"
;;
*)
icon_result=":default:"
;;
esac
echo $icon_result

View file

@ -1,8 +0,0 @@
#!/usr/bin/env sh
WIDTH="dynamic"
if [ "$SELECTED" = "true" ]; then
WIDTH="0"
fi
sketchybar --animate tanh 20 --set $NAME icon.highlight=$SELECTED label.width=$WIDTH

View file

@ -1,114 +0,0 @@
#!/bin/sh
next ()
{
osascript -e 'tell application "Spotify" to play next track'
}
back ()
{
osascript -e 'tell application "Spotify" to play previous track'
}
play ()
{
osascript -e 'tell application "Spotify" to playpause'
}
repeat ()
{
REPEAT=$(osascript -e 'tell application "Spotify" to get repeating')
if [ "$REPEAT" = "false" ]; then
sketchybar -m --set spotify.repeat icon.highlight=on
osascript -e 'tell application "Spotify" to set repeating to true'
else
sketchybar -m --set spotify.repeat icon.highlight=off
osascript -e 'tell application "Spotify" to set repeating to false'
fi
}
shuffle ()
{
SHUFFLE=$(osascript -e 'tell application "Spotify" to get shuffling')
if [ "$SHUFFLE" = "false" ]; then
sketchybar -m --set spotify.shuffle icon.highlight=on
osascript -e 'tell application "Spotify" to set shuffling to true'
else
sketchybar -m --set spotify.shuffle icon.highlight=off
osascript -e 'tell application "Spotify" to set shuffling to false'
fi
}
update ()
{
PLAYING=1
if [ "$(echo "$INFO" | jq -r '.["Player State"]')" = "Playing" ]; then
PLAYING=0
TRACK="$(echo "$INFO" | jq -r .Name | sed 's/\(.\{20\}\).*/\1.../')"
ARTIST="$(echo "$INFO" | jq -r .Artist | sed 's/\(.\{20\}\).*/\1.../')"
ALBUM="$(echo "$INFO" | jq -r .Album | sed 's/\(.\{25\}\).*/\1.../')"
SHUFFLE=$(osascript -e 'tell application "Spotify" to get shuffling')
REPEAT=$(osascript -e 'tell application "Spotify" to get repeating')
COVER=$(osascript -e 'tell application "Spotify" to get artwork url of current track')
fi
args=()
if [ $PLAYING -eq 0 ]; then
curl -s --max-time 20 "$COVER" -o /tmp/cover.jpg
if [ "$ARTIST" == "" ]; then
args+=(--set spotify.title label="$TRACK" drawing=on \
--set spotify.album label="Podcast" drawing=on \
--set spotify.artist label="$ALBUM" drawing=on )
else
args+=(--set spotify.title label="$TRACK" drawing=on \
--set spotify.album label="$ALBUM" drawing=on \
--set spotify.artist label="$ARTIST" drawing=on)
fi
args+=(--set spotify.play icon=􀊆 \
--set spotify.shuffle icon.highlight=$SHUFFLE \
--set spotify.repeat icon.highlight=$REPEAT \
--set spotify.cover background.image="/tmp/cover.jpg" \
background.color=0x00000000 \
--set spotify.anchor icon.drawing=on \
drawing=on \
--set spotify drawing=on )
else
args+=(--set spotify.title drawing=off \
--set spotify.artist drawing=off \
--set spotify.anchor drawing=off popup.drawing=off \
--set spotify.play icon=􀊄 )
fi
sketchybar -m "${args[@]}"
}
mouse_clicked () {
case "$NAME" in
"spotify.next") next
;;
"spotify.back") back
;;
"spotify.play") play
;;
"spotify.shuffle") shuffle
;;
"spotify.repeat") repeat
;;
*) exit
;;
esac
}
popup () {
sketchybar --set spotify.anchor popup.drawing=$1
}
case "$SENDER" in
"mouse.clicked") mouse_clicked
;;
"mouse.entered") popup on
;;
"mouse.exited"|"mouse.exited.global") popup off
;;
*) update
;;
esac

View file

@ -1,9 +0,0 @@
#!/usr/bin/env sh
MUTED=$(osascript -e 'output muted of (get volume settings)')
if [ "$MUTED" = "false" ]; then
osascript -e 'set volume output muted true'
else
osascript -e 'set volume output muted false'
fi

View file

@ -1,45 +0,0 @@
#!/bin/sh
zen_on() {
sketchybar --set github.bell drawing=off \
--set apple.logo drawing=off \
--set '/cpu.*/' drawing=off \
--set calendar icon.drawing=off \
--set system.yabai drawing=off \
--set separator drawing=off \
--set front_app drawing=off \
--set volume_alias drawing=off \
--set spotify.anchor drawing=off \
--set spotify.play updates=off \
--set brew drawing=off \
--set divider drawing=off \
--bar padding_left=18
}
zen_off() {
sketchybar --set github.bell drawing=on \
--set apple.logo drawing=on \
--set '/cpu.*/' drawing=on \
--set calendar icon.drawing=on \
--set separator drawing=on \
--set front_app drawing=on \
--set system.yabai drawing=on \
--set volume_alias drawing=on \
--set spotify.play updates=on \
--set brew drawing=on \
--set divider drawing=on \
--bar padding_left=7
}
if [ "$1" = "on" ]; then
zen_on
elif [ "$1" = "off" ]; then
zen_off
else
if [ "$(sketchybar --query apple.logo | jq -r ".geometry.drawing")" = "on" ]; then
zen_on
else
zen_off
fi
fi

View file

@ -0,0 +1,95 @@
{
config,
pkgs,
colors,
}: let
template = pkgs.substituteAllFiles {
src = ./config;
files = [
"colors.lua"
"settings.lua"
"items/cpu.lua"
"items/spaces.lua"
];
timeout = "${pkgs.coreutils}/bin/timeout";
ping = "${pkgs.inetutils}/bin/ping";
sketchybar_cpu = "${pkgs.sketchybar-helpers}/bin/sketchybar-cpu";
colors_blue = colors.nominal.blue;
colors_red = colors.nominal.red;
colors_unifying = colors.semantic.unifying;
colors_good = colors.semantic.good;
colors_info = colors.semantic.info;
colors_warning = colors.semantic.warning;
colors_urgent = colors.semantic.urgent;
colors_primary_bg = colors.semantic.background;
colors_primary_fg = colors.semantic.foreground;
colors_secondary_bg = colors.semantic.background_highlighted;
colors_secondary_fg = colors.semantic.foreground;
colors_unselected_bg = colors.window.unselected.background;
colors_unselected_fg = colors.window.unselected.text;
colors_selected_focused_bg = colors.window.selected.focused.background;
colors_selected_focused_fg = colors.window.selected.focused.text;
colors_selected_unfocused_bg = colors.window.selected.unfocused.background;
colors_selected_unfocused_fg = colors.window.selected.unfocused.text;
font_family = config.theme.fonts.proportional.name;
};
appIconNames = pkgs.runCommand "sketchybar-app-icon-names" {} ''
mkdir -p "$out"
{
echo "return {"
"${pkgs.findutils}/bin/find" \
"${pkgs.sources.sketchybar-font-src}/mappings" \
-type f \
-mindepth 1 \
-maxdepth 1 | while read -r f
do cat $f | sed 's/ *| */\n/g;s/[*]//g' | while read -r s
do echo " [$s]" = \"''${f##*/}\",
done
done
echo ' [".kitty-wrapped"] = ":kitty:",'
echo ' ["iTerm2"] = ":iterm:",'
echo ' ["Google Chrome Beta"] = ":google_chrome:",'
echo ' ["Microsoft Edge Beta"] = ":microsoft_edge:",'
echo "}"
} > "$out/app_icon_names.lua"
'';
combined = pkgs.symlinkJoin {
name = "sketchybar-config";
paths = [template appIconNames ./config];
};
luaposix = pkgs.lua5_4.pkgs.buildLuarocksPackage {
pname = "luaposix";
version = "36.3-1";
src = pkgs.sources.luaposix;
};
lua = pkgs.lua5_4.withPackages (ps: [
ps.lua-cjson
luaposix
]);
in {
enable = true;
package = pkgs.sketchybar;
config = ''
#!${lua}/bin/lua
package.cpath = package.cpath .. ";${pkgs.sketchybar-lua}/?.so"
package.path = package.path .. ";${combined}/?.lua;${combined}/?/init.lua"
local Aerospace = require("aerospace")
local aerospace = Aerospace.new()
while not aerospace:is_initialized() do
os.execute("sleep 0.1")
end
sbar = require("sketchybar")
sbar.aerospace = aerospace
sbar.begin_config()
require("init")
sbar.hotload(false)
sbar.end_config()
sbar.event_loop()
'';
}

View file

@ -19,7 +19,6 @@ in {
#!/usr/bin/env sh #!/usr/bin/env sh
source "$HOME/.config/sketchybar/colors.sh" # Loads all defined colors source "$HOME/.config/sketchybar/colors.sh" # Loads all defined colors
source "$HOME/.config/sketchybar/icons.sh" # Loads all defined icons
ITEM_DIR="$HOME/.config/sketchybar/items" # Directory where the items are configured ITEM_DIR="$HOME/.config/sketchybar/items" # Directory where the items are configured
PLUGIN_DIR="$HOME/.config/sketchybar/plugins" # Directory where all the plugin scripts are stored PLUGIN_DIR="$HOME/.config/sketchybar/plugins" # Directory where all the plugin scripts are stored
@ -27,49 +26,33 @@ in {
FONT="SF Pro" # Needs to have Regular, Bold, Semibold, Heavy and Black variants FONT="SF Pro" # Needs to have Regular, Bold, Semibold, Heavy and Black variants
PADDINGS=3 # All paddings use this value (icon, label, background) PADDINGS=3 # All paddings use this value (icon, label, background)
# Setting up and starting the helper process
HELPER=git.felix.helper
killall helper
cd $HOME/.config/sketchybar/helper && make
$HOME/.config/sketchybar/helper/helper $HELPER > /dev/null 2>&1 &
# Unload the macOS on screen indicator overlay for volume change
# launchctl unload -F /System/Library/LaunchAgents/com.apple.OSDUIHelper.plist > /dev/null 2>&1 &
# Setting up the general bar appearance and default values # Setting up the general bar appearance and default values
${pkgs.sketchybar}/bin/sketchybar --bar height=40 \ ${pkgs.sketchybar}/bin/sketchybar --bar height=40 \
color=$BAR_COLOR \ blur_radius=30 \
shadow=off \
position=top \ position=top \
sticky=on \ sticky=on \
padding_right=0 \ padding_left=10 \
padding_left=0 \ padding_right=10
corner_radius=12 \
y_offset=0 \
margin=2 \ ${pkgs.sketchybar}/bin/sketchybar --default icon.font="SF Pro:Semibold:12.0" \
blur_radius=0 \ icon.color=$ITEM_COLOR \
notch_width=0 \ label.font="SF Pro:Semibold:12.0" \
--default updates=when_shown \ label.color=$ITEM_COLOR \
icon.font="$FONT:Bold:14.0" \ background.color=$ACCENT_COLOR \
icon.color=$ICON_COLOR \ background.corner_radius=10 \
icon.padding_left=$PADDINGS \ background.height=20 \
icon.padding_right=$PADDINGS \ padding_left=4 \
label.font="$FONT:Semibold:13.0" \ padding_right=4 \
label.color=$LABEL_COLOR \ icon.padding_left=6 \
label.padding_left=$PADDINGS \ icon.padding_right=3 \
label.padding_right=$PADDINGS \ label.padding_left=3 \
background.padding_right=$PADDINGS \ label.padding_right=6
background.padding_left=$PADDINGS \
background.height=26 \
background.corner_radius=9 \
popup.background.border_width=2 \
popup.background.corner_radius=11 \
popup.background.border_color=$POPUP_BORDER_COLOR \
popup.background.color=$POPUP_BACKGROUND_COLOR \
popup.background.shadow.drawing=on
# Left # Left
source "$ITEM_DIR/apple.sh" # source "$ITEM_DIR/apple.sh"
source "$ITEM_DIR/spaces.sh" source "$ITEM_DIR/spaces.sh"
source "$ITEM_DIR/front_app.sh" source "$ITEM_DIR/front_app.sh"
@ -78,11 +61,10 @@ in {
source "$ITEM_DIR/calendar.sh" source "$ITEM_DIR/calendar.sh"
# Right # Right
# source "$ITEM_DIR/brew.sh" source $ITEM_DIR/calendar.sh
# source "$ITEM_DIR/github.sh" source $ITEM_DIR/wifi.sh
source "$ITEM_DIR/volume.sh" source $ITEM_DIR/battery.sh
# source "$ITEM_DIR/divider.sh" source $ITEM_DIR/volume.sh
# source "$ITEM_DIR/cpu.sh"
# Forcing all item scripts to run (never do this outside of sketchybarrc) # Forcing all item scripts to run (never do this outside of sketchybarrc)
${pkgs.sketchybar}/bin/sketchybar --update ${pkgs.sketchybar}/bin/sketchybar --update
@ -92,275 +74,429 @@ in {
}; };
icons = { icons = {
executable = true; executable = true;
target = ".config/sketchybar/icons.sh"; target = ".config/sketchybar/plugins/icons.sh";
source = folder + /icons.sh; text = ''
#!/usr/bin/env sh
# Source the icon map with all the application icons
source ${pkgs.sketchybar-app-font}/bin/icon_map.sh
# Create a cache directory if it doesn't exist
CACHE_DIR="$HOME/.cache/sketchybar"
mkdir -p "$CACHE_DIR"
# Cache file for icon mappings
ICON_CACHE="$CACHE_DIR/icon_cache.txt"
# Create the cache file if it doesn't exist
if [ ! -f "$ICON_CACHE" ]; then
touch "$ICON_CACHE"
fi
# Check if the app is already in cache
APP_NAME=$(if [ "$1" = "Zen" ]; then echo "Zen Browser"; else echo "$1"; fi)
CACHED_ICON=$(grep "^$APP_NAME|" "$ICON_CACHE" | cut -d '|' -f2)
if [ -n "$CACHED_ICON" ]; then
# Cache hit, return the icon
echo "$CACHED_ICON"
exit 0
fi
# Get icon from the mapping function
__icon_map "$APP_NAME"
if [ -n "$icon_result" ]; then
echo "$APP_NAME|$icon_result" >>"$ICON_CACHE"
fi
echo "$icon_result"
'';
}; };
colors = { colors = {
executable = true; executable = true;
target = ".config/sketchybar/colors.sh"; target = ".config/sketchybar/colors.sh";
text = '' text = ''
#!/usr/bin/env sh
# Color Palette
export BLACK=0xff11111b
export WHITE=0x66cdd6f4
export RED=0xffa6e3a1
export GREEN=0xff40a02b
export BLUE=0xff89b4fa
export YELLOW=0xfff9e2af
export ORANGE=0xfffab387
export MAGENTA=0xffeba0ac
export GREY=0xff585b70
export TRANSPARENT=0xff000000
export BLUE2=0xff7287fd
export FLAMINGO=0xfff2cdcd
# General bar colors export TRANSPARENT=0x00ffffff
export BAR_COLOR=0xeff1f5ff # Color of the bar
export ICON_COLOR=0xff4c4f69
export LABEL_COLOR=0xff4c4f69 # Color of all labels
export BACKGROUND_1=0xffbcc0cc
export BACKGROUND_2=0xffbcc0cc
export POPUP_BACKGROUND_COLOR=$BLACK # -- Gray Scheme --
export POPUP_BORDER_COLOR=$WHITE export ITEM_COLOR=0xff000000
export ACCENT_COLOR=0xffc3c6cb
export SHADOW_COLOR=$BLACK # -- White Scheme --
# export ITEM_COLOR=0xff000000
# export ACCENT_COLOR=0xffffffff
# -- Teal Scheme --
# export ITEM_COLOR=0xff000000
# export ACCENT_COLOR=0xff2cf9ed
# -- Purple Scheme --
# export ITEM_COLOR=0xff000000
# export ACCENT_COLOR=0xffeb46f9
# -- Red Scheme ---
# export ITEM_COLOR=0xff000000
# export ACCENT_COLOR=0xffff2453
# -- Blue Scheme ---
# export ITEM_COLOR=0xff000000
# export ACCENT_COLOR=0xff15bdf9
# -- Green Scheme --
# export ITEM_COLOR=0xff000000
# export ACCENT_COLOR=0xff1dfca1
# -- Orange Scheme --
# export ITEM_COLOR=0xffffffff
# export ACCENT_COLOR=0xfff97716
# -- Yellow Scheme --
# export ITEM_COLOR=0xff000000
# export ACCENT_COLOR=0xfff7fc17
''; '';
}; };
items_apple = { items_wifi = {
executable = true; executable = true;
target = ".config/sketchybar/items/apple.sh"; target = ".config/sketchybar/items/wifi.sh";
source = folder + /items/executable_apple.sh; text = ''
#!/usr/bin/env/ sh
sketchybar --add item wifi right \
--set wifi \
icon="􀙥" \
label="Updating..." \
script="$PLUGIN_DIR/wifi.sh" \
--subscribe wifi wifi_change
'';
}; };
items_brew = { items_battery = {
executable = true; executable = true;
target = ".config/sketchybar/items/brew.sh"; target = ".config/sketchybar/items/battery.sh";
source = folder + /items/executable_brew.sh; text = ''
#!/usr/bin/env/ sh
sketchybar --add item battery right \
--set battery update_freq=180 \
script="$PLUGIN_DIR/battery.sh" \
--subscribe battery system_woke power_source_change
'';
}; };
items_calendar = { items_calendar = {
executable = true; executable = true;
target = ".config/sketchybar/items/calendar.sh"; target = ".config/sketchybar/items/calendar.sh";
text = '' text = ''
#!/usr/bin/env sh #!/usr/bin/env sh
sketchybar --add item calendar right \
sketchybar --add item calendar center \ --set calendar icon=􀧞 \
--set calendar icon=cal \ update_freq=15 \
display=1 \ script="$PLUGIN_DIR/calendar.sh"
icon.font="$FONT:Black:12.0" \
icon.padding_right=0 \
label.width=50 \
label.align=right \
background.padding_left=15 \
update_freq=30 \
script="$PLUGIN_DIR/calendar.sh" \
click_script="$PLUGIN_DIR/zen.sh"
''; '';
}; };
items_cpu = {
executable = true;
target = ".config/sketchybar/items/cpu.sh";
source = folder + /items/executable_cpu.sh;
};
items_divider = {
executable = true;
target = ".config/sketchybar/items/divider.sh";
source = folder + /items/executable_divider.sh;
};
items_front_app = { items_front_app = {
executable = true; executable = true;
target = ".config/sketchybar/items/front_app.sh"; target = ".config/sketchybar/items/front_app.sh";
text = '' text = ''
#!/usr/bin/env sh #!/usr/bin/env sh
FRONT_APP_SCRIPT='sketchybar --set $NAME label="$INFO"'
sketchybar --add event window_focus \ sketchybar --add item front_app left \
--add event windows_on_spaces \ --set front_app background.color=$ACCENT_COLOR \
--add item system.aerospace left \ icon.color=$ITEM_COLOR \
--set system.aerospace script="$PLUGIN_DIR/aerospace.sh" \ label.color=$ITEM_COLOR \
icon.font="$FONT:Bold:16.0" \ icon.font="sketchybar-app-font:Regular:12.0" \
label.drawing=off \ label.font="SF Pro:Semibold:12.0" \
icon.width=30 \ script="$PLUGIN_DIR/front_app.sh" \
icon=$YABAI_GRID \
icon.color=$BLACK \
updates=on \
display=active \
--subscribe system.aerospace window_focus \
windows_on_spaces \
mouse.clicked \
--add item front_app left \
--set front_app script="$FRONT_APP_SCRIPT" \
icon.drawing=off \
background.padding_left=0 \
background.padding_right=10 \
label.color=$BLACK \
label.font="$FONT:Black:12.0" \
display=active \
--subscribe front_app front_app_switched --subscribe front_app front_app_switched
''; '';
}; };
items_github = {
executable = true;
target = ".config/sketchybar/items/github.sh";
source = folder + /items/executable_github.sh;
};
items_spaces = { items_spaces = {
executable = true; executable = true;
target = ".config/sketchybar/items/spaces.sh"; target = ".config/sketchybar/items/spaces.sh";
# label.background.color=$BACKGROUND_2
text = '' text = ''
${pkgs.sketchybar}/bin/sketchybar --add event aerospace_workspace_change sketchybar --add event aerospace_workspace_change
${pkgs.sketchybar}/bin/sketchybar --add event aerospace_mode_change
for sid in $(${pkgs.aerospace}/bin/aerospace list-workspaces --all); do sketchybar --add item aerospace_dummy left \
${pkgs.sketchybar}/bin/sketchybar --add item space.$sid left \ --set aerospace_dummy display=0 \
--subscribe space.$sid aerospace_workspace_change \ script="$PLUGIN_DIR/spaces.sh" \
--subscribe space.$sid aerospace_mode_change \ --subscribe aerospace_dummy aerospace_workspace_change
--set space.$sid \
for m in $(aerospace list-monitors | awk '{print $1}'); do
for sid in $(aerospace list-workspaces --monitor $m); do
sketchybar --add space space.$sid left \
--set space.$sid space=$sid \
icon=$sid \ icon=$sid \
icon.padding_left=22 \ background.color=$TRANSPARENT \
icon.padding_right=22 \ label.color=$ACCENT_COLOR \
icon.highlight_color=$WHITE \ icon.color=$ACCENT_COLOR \
icon.highlight=off \ display=$m \
icon.color=0xff4c566a \ label.font="sketchybar-app-font:Regular:12.0" \
background.padding_left=-8 \ icon.font="SF Pro:Semibold:12.0" \
background.padding_right=-8 \ label.padding_right=10 \
background.color=$BACKGROUND_1 \ label.y_offset=-1 \
background.drawing=on \ click_script="$PLUGIN_DIR/space_click.sh $sid"
script="$PLUGIN_DIR/aerospace.sh $sid" \
click_script="aerospace workspace $sid" \ apps=$(aerospace list-windows --monitor "$m" --workspace "$sid" |
label.font="Iosevka Nerd Font:Regular:16.0" \ awk -F '|' '{gsub(/^ *| *$/, "", $2); if (!seen[$2]++) print $2}')
label.padding_right=33 \
label.background.height=26 \ icon_strip=""
label.background.drawing=on \ if [ "''${apps}" != "" ]; then
label.background.corner_radius=9 \ while read -r app; do
label.drawing=off icon_strip+=" $($PLUGIN_DIR/icons.sh "$app")"
done <<<"''${apps}"
else
icon_strip=" "
fi
sketchybar --set space.$sid label="$icon_strip"
done
for empty_space in $(aerospace list-workspaces --monitor $m --empty); do
sketchybar --set space.$empty_space display=0
done
for focus in $(aerospace list-workspaces --focused); do
sketchybar --set space.$focus background.drawing=on \
background.color=$ACCENT_COLOR \
label.color=$ITEM_COLOR \
icon.color=$ITEM_COLOR
done
done done
${pkgs.sketchybar}/bin/sketchybar --add item separator left \
--set separator icon= \
icon.font="Iosevka Nerd Font:Regular:16.0" \
background.padding_left=26 \
background.padding_right=15 \
label.drawing=off \
display=active \
icon.color=$GREEN
''; '';
}; };
items_spotify = {
executable = true;
target = ".config/sketchybar/items/spotify.sh";
source = folder + /items/executable_spotify.sh;
};
items_volume = { items_volume = {
executable = true; executable = true;
target = ".config/sketchybar/items/volume.sh"; target = ".config/sketchybar/items/volume.sh";
text = '' text = ''
INITIAL_WIDTH=$(osascript -e 'set ovol to output volume of (get volume settings)') #/usr/bin/env sh
${pkgs.sketchybar}/bin/sketchybar --add item volume right \
--subscribe volume volume_change \ sketchybar --add item volume right \
--set volume script="$PLUGIN_DIR/volume.sh" \ --set volume script="$PLUGIN_DIR/volume.sh" \
updates=on \ --subscribe volume volume_change
icon.background.drawing=on \
icon.background.color=$FLAMINGO \
icon.background.height=8 \
icon.background.corner_radius=3 \
icon.width=$INITIAL_WIDTH \
width=100 \
icon.align=right \
label.drawing=off \
background.drawing=on \
background.color=$BACKGROUND_2 \
background.height=8 \
background.corner_radius=3 \
align=left
${pkgs.sketchybar}/bin/sketchybar --add alias "Control Center,Sound" right \
--rename "Control Center,Sound" volume_alias \
--set volume_alias icon.drawing=off \
label.drawing=off \
alias.color=$BLUE2 \
background.padding_right=0 \
background.padding_left=5 \
width=50 \
align=right \
click_script="$PLUGIN_DIR/volume_click.sh"
''; '';
}; };
plugins_brew = { plugins_wifi = {
executable = true; executable = true;
target = ".config/sketchybar/plugins/brew.sh"; target = ".config/sketchybar/plugins/wifi.sh";
source = folder + /plugins/executable_brew.sh; text = ''
#/usr/bin/env sh
SSID=$(system_profiler SPAirPortDataType | awk '/Current Network Information:/ { getline; print substr($0, 13, (length($0) - 13)); exit }')
if [ "$SSID" = "" ]; then
sketchybar --set $NAME icon="􀙈" label="Disconnected"
else
sketchybar --set $NAME icon="􀙇" label="$SSID"
fi
'';
}; };
plugins_calendar = { plugins_calendar = {
executable = true; executable = true;
target = ".config/sketchybar/plugins/calendar.sh"; target = ".config/sketchybar/plugins/calendar.sh";
source = folder + /plugins/executable_calendar.sh;
text = ''
#/usr/bin/env sh
sketchybar --set $NAME label="$(date +'%a %d %b %I:%M %p')"
'';
}; };
plugins_github = { plugins_spaces = {
executable = true; executable = true;
target = ".config/sketchybar/plugins/github.sh"; target = ".config/sketchybar/plugins/spaces.sh";
source = folder + /plugins/executable_github.sh; text = ''
#!/usr/bin/env sh
source "$CONFIG_DIR/colors.sh"
update_workspace_appearance() {
local sid=$1
local is_focused=$2
if [ "$is_focused" = "true" ]; then
sketchybar --set space.$sid background.drawing=on \
background.color=$ACCENT_COLOR \
label.color=$ITEM_COLOR \
icon.color=$ITEM_COLOR
else
sketchybar --set space.$sid background.drawing=off \
label.color=$ACCENT_COLOR \
icon.color=$ACCENT_COLOR
fi
}
update_icons() {
m=$1
sid=$2
apps=$(aerospace list-windows --monitor "$m" --workspace "$sid" \
| awk -F '|' '{gsub(/^ *| *$/, "", $2); if (!seen[$2]++) print $2}' \
| sort)
icon_strip=""
if [ "''${apps}" != "" ]; then
while read -r app; do
icon_strip+=" $($CONFIG_DIR/plugins/icons.sh "$app")"
done <<<"''${apps}"
else
icon_strip=" "
fi
sketchybar --animate sin 10 --set space.$sid label="$icon_strip"
}
update_workspace_appearance "$PREV_WORKSPACE" "false"
update_workspace_appearance "$FOCUSED_WORKSPACE" "true"
for m in $(aerospace list-monitors | awk '{print $1}'); do
for sid in $(aerospace list-workspaces --monitor $m --visible); do
sketchybar --set space.$sid display=$m
update_icons "$m" "$sid"
update_icons "$m" "$PREV_WORKSPACE"
apps=$(aerospace list-windows --monitor "$m" --workspace "$sid" | wc -l)
if [ "''${apps}" -eq 0 ]; then
sketchybar --set space.$sid display=0
fi
done
done
'';
}; };
plugins_icon_map = {
plugins_space_click = {
executable = true; executable = true;
target = ".config/sketchybar/plugins/icon_map.sh"; target = ".config/sketchybar/plugins/space_click.sh";
source = folder + /plugins/executable_icon_map.sh; text = ''
}; #/usr/bin/env/ sh
plugins_space = {
executable = true; apps=$(aerospace list-windows --workspace $1 | awk -F '|' '{gsub(/^ *| *$/, "", $2); print $2}')
target = ".config/sketchybar/plugins/space.sh"; focused=$(aerospace list-workspaces --focused)
source = folder + /plugins/executable_space.sh;
}; if [ "''${apps}" = "" ] && [ "''${focused}" != "$1" ]; then
plugins_spotify = { sketchybar --set space.$1 display=0
executable = true; else
target = ".config/sketchybar/plugins/spotify.sh"; aerospace workspace $1
source = folder + /plugins/executable_spotify.sh; fi
}; '';
;
plugins_volume = { plugins_volume = {
executable = true; executable = true;
target = ".config/sketchybar/plugins/volume.sh"; target = ".config/sketchybar/plugins/volume.sh";
text = '' text = ''
#!/usr/bin/env sh #!/usr/bin/env sh
WIDTH=100
volume_change() { # The volume_change event supplies a $INFO variable in which the current volume
# INITIAL_WIDTH=$(${pkgs.sketchybar}/bin/sketchybar --query $NAME | ${pkgs.jq}/bin/jq ".icon.width") # percentage is passed to the script.
# if [ "$INITIAL_WIDTH" -eq "0" ]; then
# ${pkgs.sketchybar}/bin/sketchybar --animate tanh 30 --set $NAME width=$WIDTH icon.width=$INFO
# else
# ${pkgs.sketchybar}/bin/sketchybar --set $NAME icon.width=$INFO width=$WIDTH
# fi
${pkgs.sketchybar}/bin/sketchybar --set $NAME icon.width=$INFO
if [ "$SENDER" = "volume_change" ]; then
# sleep 5 VOLUME=$INFO
# FINAL_WIDTH=$(${pkgs.sketchybar}/bin/sketchybar --query $NAME | ${pkgs.jq}/bin/jq ".icon.width")
# if [ "$FINAL_WIDTH" -eq "$INFO" ]; then
# ${pkgs.sketchybar}/bin/sketchybar --animate tanh 30 --set $NAME width=0 icon.width=0
# fi
}
case "$SENDER" in case $VOLUME in
"volume_change") volume_change [6-9][0-9] | 100)
ICON="􀊩"
;; ;;
[3-5][0-9])
ICON="􀊥"
;;
[1-9] | [1-2][0-9])
ICON="􀊡"
;;
*) ICON="􀊣" ;;
esac esac
'';
}; sketchybar --set $NAME icon="$ICON" label="$VOLUME%"
plugins_volume_click = {
executable = true;
target = ".config/sketchybar/plugins/volume_click.sh";
text = ''
#!/usr/bin/env sh
MUTED=$(osascript -e 'output muted of (get volume settings)')
if [ "$MUTED" = "false" ]; then
osascript -e 'set volume output muted true'
else
osascript -e 'set volume output muted false'
fi fi
''; '';
}; };
plugins_zen = { plugins_front_app = {
executable = true; executable = true;
target = ".config/sketchybar/plugins/zen.sh"; target = ".config/sketchybar/plugins/front_app.sh";
source = folder + /plugins/executable_zen.sh; text = ''
# Some events send additional information specific to the event in the $INFO
# variable. E.g. the front_app_switched event sends the name of the newly
# focused application in the $INFO variable:
# https://felixkratz.github.io/SketchyBar/config/events#events-and-scripting
app_switched() {
for m in $(aerospace list-monitors | awk '{print $1}'); do
for sid in $(aerospace list-workspaces --monitor $m --visible); do
apps=$( (echo "$INFO"; aerospace list-windows --monitor "$m" --workspace "$sid" \
| awk -F '|' '{gsub(/^ *| *$/, "", $2); print $2}') \
| awk '!seen[$0]++' | sort)
icon_strip=""
if [ "''${apps}" != "" ]; then
while read -r app; do
icon_strip+=" $($CONFIG_DIR/plugins/icons.sh "$app")"
done <<<"''${apps}"
else
icon_strip=" "
fi
sketchybar --animate sin 10 --set space.$sid label="$icon_strip"
done
done
}
if [ "$SENDER" = "front_app_switched" ]; then
sketchybar --set $NAME label="$INFO" icon="$($CONFIG_DIR/plugins/icons.sh "$INFO")"
app_switched
fi
'';
};
plugins_battery = {
executable = true;
target = ".config/sketchybar/plugins/battery.sh";
text = ''
#!/usr/bin/env sh
source "$CONFIG_DIR/colors.sh"
PERCENTAGE=$(pmset -g batt | grep -Eo "\d+%" | cut -d% -f1)
CHARGING=$(pmset -g batt | grep 'AC Power')
if [ $PERCENTAGE = "" ]; then
exit 0
fi
case ''${PERCENTAGE} in
9[0-9] | 100)
ICON="􀛨"
COLOR=$ITEM_COLOR
;;
[6-8][0-9])
ICON="􀺸"
COLOR=$ITEM_COLOR
;;
[3-5][0-9])
ICON="􀺶"
COLOR="0xFFd97706"
;;
[1-2][0-9])
ICON="􀛩"
COLOR="0xFFf97316"
;;
*)
ICON="􀛪"
COLOR="0xFFef4444"
;;
esac
if [[ $CHARGING != "" ]]; then
ICON="􀢋"
COLOR=$ITEM_COLOR
fi
# The item invoking this script (name $NAME) will get its icon and label
# updated with the current battery status
sketchybar --set $NAME icon="$ICON" label="''${PERCENTAGE}%" icon.color="$COLOR"
'';
}; };
plugins_aerospace = { plugins_aerospace = {
executable = true; executable = true;

View file

@ -13,6 +13,7 @@
nerd-fonts.symbols-only nerd-fonts.symbols-only
nerd-fonts.iosevka nerd-fonts.iosevka
inputs.apple-fonts.packages.${pkgs.system}.sf-pro inputs.apple-fonts.packages.${pkgs.system}.sf-pro
sketchybar-app-font
]; ];
# configuration for shared modules. # configuration for shared modules.