1{
2 pkgs,
3 lib,
4 config,
5 host,
6 ...
7}:
8{
9 home.file =
10 { }
11 // lib.optionalAttrs host.darwin (
12 lib.attrsets.mapAttrs
13 (
14 file: value: (lib.attrsets.overrideExisting value { enable = config.shared.darwin.tiling.enable; })
15 )
16 {
17 sketchybarrc = {
18 executable = true;
19 target = ".config/sketchybar/sketchybarrc";
20 text = ''
21 #!/usr/bin/env sh
22
23 source "$HOME/.config/sketchybar/colors.sh" # Loads all defined colors
24
25 ITEM_DIR="$HOME/.config/sketchybar/items" # Directory where the items are configured
26 PLUGIN_DIR="$HOME/.config/sketchybar/plugins" # Directory where all the plugin scripts are stored
27
28 FONT="SF Pro" # Needs to have Regular, Bold, Semibold, Heavy and Black variants
29 PADDINGS=3 # All paddings use this value (icon, label, background)
30
31
32 # Setting up the general bar appearance and default values
33 ${pkgs.sketchybar}/bin/sketchybar --bar height=40 \
34 blur_radius=30 \
35 position=top \
36 sticky=on \
37 padding_left=10 \
38 padding_right=10
39
40
41 ${pkgs.sketchybar}/bin/sketchybar --default icon.font="SF Pro:Semibold:12.0" \
42 icon.color=$ITEM_COLOR \
43 label.font="SF Pro:Semibold:12.0" \
44 label.color=$ITEM_COLOR \
45 background.color=$ACCENT_COLOR \
46 background.corner_radius=10 \
47 background.height=20 \
48 padding_left=4 \
49 padding_right=4 \
50 icon.padding_left=6 \
51 icon.padding_right=3 \
52 label.padding_left=3 \
53 label.padding_right=6
54
55
56 # Left
57 # source "$ITEM_DIR/apple.sh"
58 source "$ITEM_DIR/spaces.sh"
59 source "$ITEM_DIR/front_app.sh"
60
61 # Center
62 # source "$ITEM_DIR/spotify.sh"
63 source "$ITEM_DIR/calendar.sh"
64
65 # Right
66 # source $ITEM_DIR/calendar.sh
67 source $ITEM_DIR/wifi.sh
68 source $ITEM_DIR/battery.sh
69 source $ITEM_DIR/volume.sh
70
71 # Forcing all item scripts to run (never do this outside of sketchybarrc)
72 ${pkgs.sketchybar}/bin/sketchybar --update
73
74 echo "sketchybar configuation loaded.."
75 '';
76 };
77 icons = {
78 executable = true;
79 target = ".config/sketchybar/plugins/icons.sh";
80 text = ''
81 #!/usr/bin/env sh
82
83 # Source the icon map with all the application icons
84 source ${pkgs.sketchybar-app-font}/bin/icon_map.sh
85
86 # Create a cache directory if it doesn't exist
87 CACHE_DIR="$HOME/.cache/sketchybar"
88 mkdir -p "$CACHE_DIR"
89
90 # Cache file for icon mappings
91 ICON_CACHE="$CACHE_DIR/icon_cache.txt"
92
93 # Create the cache file if it doesn't exist
94 if [ ! -f "$ICON_CACHE" ]; then
95 touch "$ICON_CACHE"
96 fi
97
98 # Check if the app is already in cache
99 APP_NAME=$(if [ "$1" = "Zen" ]; then echo "Zen Browser"; else echo "$1"; fi)
100
101 CACHED_ICON=$(grep "^$APP_NAME|" "$ICON_CACHE" | cut -d '|' -f2)
102
103 if [ -n "$CACHED_ICON" ]; then
104 # Cache hit, return the icon
105 echo "$CACHED_ICON"
106 exit 0
107 fi
108
109 # Get icon from the mapping function
110 __icon_map "$APP_NAME"
111
112 if [ -n "$icon_result" ]; then
113 echo "$APP_NAME|$icon_result" >>"$ICON_CACHE"
114 fi
115
116 echo "$icon_result"
117 '';
118 };
119 colors = {
120 executable = true;
121 target = ".config/sketchybar/colors.sh";
122 text = ''
123
124 export TRANSPARENT=0x00ffffff
125
126 # -- Gray Scheme --
127 export ITEM_COLOR=0xff000000
128 export ACCENT_COLOR=0xffc3c6cb
129
130 # -- White Scheme --
131 # export ITEM_COLOR=0xff000000
132 # export ACCENT_COLOR=0xffffffff
133
134 # -- Teal Scheme --
135 # export ITEM_COLOR=0xff000000
136 # export ACCENT_COLOR=0xff2cf9ed
137
138 # -- Purple Scheme --
139 # export ITEM_COLOR=0xff000000
140 # export ACCENT_COLOR=0xffeb46f9
141
142 # -- Red Scheme ---
143 # export ITEM_COLOR=0xff000000
144 # export ACCENT_COLOR=0xffff2453
145
146 # -- Blue Scheme ---
147 # export ITEM_COLOR=0xff000000
148 # export ACCENT_COLOR=0xff15bdf9
149
150 # -- Green Scheme --
151 # export ITEM_COLOR=0xff000000
152 # export ACCENT_COLOR=0xff1dfca1
153
154 # -- Orange Scheme --
155 # export ITEM_COLOR=0xffffffff
156 # export ACCENT_COLOR=0xfff97716
157
158 # -- Yellow Scheme --
159 # export ITEM_COLOR=0xff000000
160 # export ACCENT_COLOR=0xfff7fc17
161 '';
162 };
163 items_wifi = {
164 executable = true;
165 target = ".config/sketchybar/items/wifi.sh";
166 text = ''
167 #!/usr/bin/env/ sh
168
169 sketchybar --add item wifi right \
170 --set wifi \
171 icon="􀙥" \
172 label="Updating..." \
173 script="$PLUGIN_DIR/wifi.sh" \
174 --subscribe wifi wifi_change
175 '';
176 };
177 items_battery = {
178 executable = true;
179 target = ".config/sketchybar/items/battery.sh";
180 text = ''
181 #!/usr/bin/env/ sh
182 sketchybar --add item battery right \
183 --set battery update_freq=180 \
184 script="$PLUGIN_DIR/battery.sh" \
185 --subscribe battery system_woke power_source_change
186 '';
187 };
188 items_calendar = {
189 executable = true;
190 target = ".config/sketchybar/items/calendar.sh";
191 text = ''
192 #!/usr/bin/env sh
193 sketchybar --add item calendar right \
194 --set calendar icon=􀧞 \
195 update_freq=15 \
196 script="$PLUGIN_DIR/calendar.sh"
197 '';
198 };
199 items_front_app = {
200 executable = true;
201 target = ".config/sketchybar/items/front_app.sh";
202 text = ''
203 #!/usr/bin/env sh
204
205 sketchybar --add item front_app left \
206 --set front_app background.color=$ACCENT_COLOR \
207 icon.color=$ITEM_COLOR \
208 label.color=$ITEM_COLOR \
209 icon.font="sketchybar-app-font:Regular:12.0" \
210 label.font="SF Pro:Semibold:12.0" \
211 script="$PLUGIN_DIR/front_app.sh" \
212 --subscribe front_app front_app_switched
213 '';
214 };
215 items_spaces = {
216 executable = true;
217 target = ".config/sketchybar/items/spaces.sh";
218 text = ''
219 sketchybar --add event aerospace_workspace_change
220
221 sketchybar --add item aerospace_dummy left \
222 --set aerospace_dummy display=0 \
223 script="$PLUGIN_DIR/spaces.sh" \
224 --subscribe aerospace_dummy aerospace_workspace_change
225
226 for m in $(aerospace list-monitors | awk '{print $1}'); do
227 for sid in $(aerospace list-workspaces --monitor $m); do
228 sketchybar --add space space.$sid left \
229 --set space.$sid space=$sid \
230 icon=$sid \
231 background.color=$TRANSPARENT \
232 label.color=$ACCENT_COLOR \
233 icon.color=$ACCENT_COLOR \
234 display=$m \
235 label.font="sketchybar-app-font:Regular:12.0" \
236 icon.font="SF Pro:Semibold:12.0" \
237 label.padding_right=10 \
238 label.y_offset=-1 \
239 click_script="$PLUGIN_DIR/space_click.sh $sid"
240
241 apps=$(aerospace list-windows --monitor "$m" --workspace "$sid" |
242 awk -F '|' '{gsub(/^ *| *$/, "", $2); if (!seen[$2]++) print $2}')
243
244 icon_strip=""
245 if [ "''${apps}" != "" ]; then
246 while read -r app; do
247 icon_strip+=" $($PLUGIN_DIR/icons.sh "$app")"
248 done <<<"''${apps}"
249 else
250 icon_strip=" —"
251 fi
252
253 sketchybar --set space.$sid label="$icon_strip"
254
255 done
256
257 for empty_space in $(aerospace list-workspaces --monitor $m --empty); do
258 sketchybar --set space.$empty_space display=0
259 done
260 for focus in $(aerospace list-workspaces --focused); do
261 sketchybar --set space.$focus background.drawing=on \
262 background.color=$ACCENT_COLOR \
263 label.color=$ITEM_COLOR \
264 icon.color=$ITEM_COLOR
265 done
266 done
267 '';
268 };
269
270 items_volume = {
271 executable = true;
272 target = ".config/sketchybar/items/volume.sh";
273 text = ''
274 #/usr/bin/env sh
275
276 sketchybar --add item volume right \
277 --set volume script="$PLUGIN_DIR/volume.sh" \
278 --subscribe volume volume_change
279 '';
280 };
281 plugins_wifi = {
282 executable = true;
283 target = ".config/sketchybar/plugins/wifi.sh";
284 text = ''
285 #/usr/bin/env sh
286
287 SSID=$(system_profiler SPAirPortDataType | awk '/Current Network Information:/ { getline; print substr($0, 13, (length($0) - 13)); exit }')
288
289 if [ "$SSID" = "" ]; then
290 sketchybar --set $NAME icon="􀙈" label="Disconnected"
291 else
292 sketchybar --set $NAME icon="􀙇" label="$SSID"
293 fi
294
295 '';
296 };
297 plugins_calendar = {
298 executable = true;
299 target = ".config/sketchybar/plugins/calendar.sh";
300
301 text = ''
302 #/usr/bin/env sh
303
304 sketchybar --set $NAME label="$(date +'%a %d %b %I:%M %p')"
305 '';
306 };
307 plugins_spaces = {
308 executable = true;
309 target = ".config/sketchybar/plugins/spaces.sh";
310 text = ''
311 #!/usr/bin/env sh
312
313 source "$CONFIG_DIR/colors.sh"
314
315 update_workspace_appearance() {
316 local sid=$1
317 local is_focused=$2
318
319 if [ "$is_focused" = "true" ]; then
320 sketchybar --set space.$sid background.drawing=on \
321 background.color=$ACCENT_COLOR \
322 label.color=$ITEM_COLOR \
323 icon.color=$ITEM_COLOR
324 else
325 sketchybar --set space.$sid background.drawing=off\
326 label.color=$ACCENT_COLOR \
327 icon.color=$ACCENT_COLOR
328 fi
329 }
330
331 update_icons() {
332 m=$1
333 sid=$2
334
335 apps=$(aerospace list-windows --monitor "$m" --workspace "$sid" \
336 | awk -F '|' '{gsub(/^ *| *$/, "", $2); if (!seen[$2]++) print $2}' \
337 | sort)
338
339 icon_strip=""
340 if [ "''${apps}" != "" ]; then
341 while read -r app; do
342 icon_strip+=" $($CONFIG_DIR/plugins/icons.sh "$app")"
343 done <<<"''${apps}"
344 else
345 icon_strip=" —"
346 fi
347
348 sketchybar --animate sin 10 --set space.$sid label="$icon_strip"
349 }
350
351 update_workspace_appearance "$PREV_WORKSPACE" "false"
352 update_workspace_appearance "$FOCUSED_WORKSPACE" "true"
353
354 for m in $(aerospace list-monitors | awk '{print $1}'); do
355 for sid in $(aerospace list-workspaces --monitor $m --visible); do
356 sketchybar --set space.$sid display=$m
357
358 update_icons "$m" "$sid"
359
360 update_icons "$m" "$PREV_WORKSPACE"
361
362 apps=$(aerospace list-windows --monitor "$m" --workspace "$sid" | wc -l)
363 if [ "''${apps}" -eq 0 ]; then
364 sketchybar --set space.$sid display=0
365 fi
366 done
367 done
368 '';
369 };
370
371 plugins_space_click = {
372 executable = true;
373 target = ".config/sketchybar/plugins/space_click.sh";
374 text = ''
375 #/usr/bin/env/ sh
376
377 apps=$(aerospace list-windows --workspace $1 | awk -F '|' '{gsub(/^ *| *$/, "", $2); print $2}')
378 focused=$(aerospace list-workspaces --focused)
379
380 if [ "''${apps}" = "" ] && [ "''${focused}" != "$1" ]; then
381 sketchybar --set space.$1 display=0
382 else
383 aerospace workspace $1
384 fi
385 '';
386 };
387 plugins_volume = {
388 executable = true;
389 target = ".config/sketchybar/plugins/volume.sh";
390 text = ''
391 #!/usr/bin/env sh
392
393 # The volume_change event supplies a $INFO variable in which the current volume
394 # percentage is passed to the script.
395
396 if [ "$SENDER" = "volume_change" ]; then
397
398 VOLUME=$INFO
399
400 case $VOLUME in
401 [6-9][0-9] | 100)
402 ICON="􀊩"
403 ;;
404 [3-5][0-9])
405 ICON="􀊥"
406 ;;
407 [1-9] | [1-2][0-9])
408 ICON="􀊡"
409 ;;
410 *) ICON="􀊣" ;;
411 esac
412
413 sketchybar --set $NAME icon="$ICON" label="$VOLUME%"
414 fi
415 '';
416 };
417 plugins_front_app = {
418 executable = true;
419 target = ".config/sketchybar/plugins/front_app.sh";
420 text = ''
421 # Some events send additional information specific to the event in the $INFO
422 # variable. E.g. the front_app_switched event sends the name of the newly
423 # focused application in the $INFO variable:
424 # https://felixkratz.github.io/SketchyBar/config/events#events-and-scripting
425
426 app_switched() {
427 for m in $(aerospace list-monitors | awk '{print $1}'); do
428 for sid in $(aerospace list-workspaces --monitor $m --visible); do
429
430 apps=$( (echo "$INFO"; aerospace list-windows --monitor "$m" --workspace "$sid" \
431 | awk -F '|' '{gsub(/^ *| *$/, "", $2); print $2}') \
432 | awk '!seen[$0]++' | sort)
433
434 icon_strip=""
435 if [ "''${apps}" != "" ]; then
436 while read -r app; do
437 icon_strip+=" $($CONFIG_DIR/plugins/icons.sh "$app")"
438 done <<<"''${apps}"
439 else
440 icon_strip=" —"
441 fi
442
443 sketchybar --animate sin 10 --set space.$sid label="$icon_strip"
444 done
445 done
446 }
447
448 if [ "$SENDER" = "front_app_switched" ]; then
449
450 sketchybar --set $NAME label="$INFO" icon="$($CONFIG_DIR/plugins/icons.sh "$INFO")"
451
452 app_switched
453 fi
454 '';
455 };
456 plugins_battery = {
457 executable = true;
458 target = ".config/sketchybar/plugins/battery.sh";
459 text = ''
460 #!/usr/bin/env sh
461 source "$CONFIG_DIR/colors.sh"
462
463 PERCENTAGE=$(pmset -g batt | grep -Eo "\d+%" | cut -d% -f1)
464 CHARGING=$(pmset -g batt | grep 'AC Power')
465
466 if [ $PERCENTAGE = "" ]; then
467 exit 0
468 fi
469
470 case ''${PERCENTAGE} in
471 9[0-9] | 100)
472 ICON="􀛨"
473 COLOR=$ITEM_COLOR
474 ;;
475 [6-8][0-9])
476 ICON="􀺸"
477 COLOR=$ITEM_COLOR
478 ;;
479 [3-5][0-9])
480 ICON="􀺶"
481 COLOR="0xFFd97706"
482 ;;
483 [1-2][0-9])
484 ICON="􀛩"
485 COLOR="0xFFf97316"
486 ;;
487 *)
488 ICON="􀛪"
489 COLOR="0xFFef4444"
490 ;;
491 esac
492
493 if [[ $CHARGING != "" ]]; then
494 ICON="􀢋"
495 COLOR=$ITEM_COLOR
496 fi
497
498 # The item invoking this script (name $NAME) will get its icon and label
499 # updated with the current battery status
500 sketchybar --set $NAME icon="$ICON" label="''${PERCENTAGE}%" icon.color="$COLOR"
501 '';
502 };
503 plugins_aerospace = {
504 executable = true;
505 target = ".config/sketchybar/plugins/aerospace.sh";
506 text = ''
507 #!/usr/bin/env bash
508 source "$HOME/.config/sketchybar/colors.sh" # Loads all defined colors
509
510 highlight_focused_workspace() {
511 if [[ "$1" = "$FOCUSED_WORKSPACE" ]]
512 then
513 ${pkgs.sketchybar}/bin/sketchybar --animate tanh 20 --set $NAME icon.highlight=on label.width=0
514 else
515 ${pkgs.sketchybar}/bin/sketchybar --animate tanh 20 --set $NAME icon.highlight=off label.width=dynamic
516 fi
517 }
518
519 illuminate_mode() {
520 if [[ "$mode" = "service" ]]
521 then
522 ${pkgs.sketchybar}/bin/sketchybar --animate tanh 20 --set $NAME background.color=$ORANGE
523 elif [[ "$mode" = "resize" ]]
524 then
525 ${pkgs.sketchybar}/bin/sketchybar --animate tanh 20 --set $NAME background.color=$GREEN
526 else
527 ${pkgs.sketchybar}/bin/sketchybar --animate tanh 20 --set $NAME background.color=$BACKGROUND_1
528 fi
529 }
530 case "$SENDER" in
531 "aerospace_workspace_change")
532 highlight_focused_workspace $1
533 ;;
534 "aerospace_mode_change")
535 illuminate_mode
536 ;;
537 esac
538 '';
539 };
540 }
541 );
542}