From 37f5757b2c8fa9b915bdbca7fe724ab2c62cec2a Mon Sep 17 00:00:00 2001 From: Nico Date: Sat, 3 May 2025 16:16:03 +1000 Subject: [PATCH] sketchybar: init --- modules/darwin/sketchybar.nix | 7 + stow/.config/sketchybar/plugins/backlight.sh | 32 +++++ stow/.config/sketchybar/plugins/battery.sh | 28 ++++ stow/.config/sketchybar/plugins/clock.sh | 15 +++ stow/.config/sketchybar/plugins/front_app.sh | 10 ++ stow/.config/sketchybar/plugins/space.sh | 13 ++ stow/.config/sketchybar/plugins/volume.sh | 20 +++ stow/.config/sketchybar/sketchybarrc | 132 +++++++++++++++++++ 8 files changed, 257 insertions(+) create mode 100644 modules/darwin/sketchybar.nix create mode 100755 stow/.config/sketchybar/plugins/backlight.sh create mode 100755 stow/.config/sketchybar/plugins/battery.sh create mode 100755 stow/.config/sketchybar/plugins/clock.sh create mode 100755 stow/.config/sketchybar/plugins/front_app.sh create mode 100755 stow/.config/sketchybar/plugins/space.sh create mode 100755 stow/.config/sketchybar/plugins/volume.sh create mode 100755 stow/.config/sketchybar/sketchybarrc diff --git a/modules/darwin/sketchybar.nix b/modules/darwin/sketchybar.nix new file mode 100644 index 0000000..f23e6a8 --- /dev/null +++ b/modules/darwin/sketchybar.nix @@ -0,0 +1,7 @@ +{ config, lib, pkgs, ... }: + +{ + services.skhd.enable = true; + services.sketchybar.enable = true; + system.defaults.NSGlobalDomain._HIHideMenuBar = true; +} diff --git a/stow/.config/sketchybar/plugins/backlight.sh b/stow/.config/sketchybar/plugins/backlight.sh new file mode 100755 index 0000000..27cc1cb --- /dev/null +++ b/stow/.config/sketchybar/plugins/backlight.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +# The brightness_change event supplies a $INFO variable in which the current backlight brightness +# percentage is passed to the script. + +if [ "$SENDER" = "brightness_change" ]; then + BRIGHTNESS="$INFO" + + case "$BRIGHTNESS" in + [9][0-9]|100) ICON="" + ;; + [8][0-9]) ICON="" + ;; + [7][0-9]) ICON="" + ;; + [6][0-9]) ICON="" + ;; + [5][0-9]) ICON="" + ;; + [4][0-9]) ICON="" + ;; + [3][0-9]) ICON="" + ;; + [2][0-9]) ICON="" + ;; + [1][0-9]) ICON="" + ;; + *) ICON="" + esac + + sketchybar --set "$NAME" icon="$ICON" label="$BRIGHTNESS%" +fi diff --git a/stow/.config/sketchybar/plugins/battery.sh b/stow/.config/sketchybar/plugins/battery.sh new file mode 100755 index 0000000..440d2d8 --- /dev/null +++ b/stow/.config/sketchybar/plugins/battery.sh @@ -0,0 +1,28 @@ +#!/bin/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=" " + ;; + [6-8][0-9]) ICON=" " + ;; + [3-5][0-9]) ICON=" " + ;; + [1-2][0-9]) ICON=" " + ;; + *) ICON=" " +esac + +if [[ "$CHARGING" != "" ]]; then + ICON="" +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}%" diff --git a/stow/.config/sketchybar/plugins/clock.sh b/stow/.config/sketchybar/plugins/clock.sh new file mode 100755 index 0000000..2716ee4 --- /dev/null +++ b/stow/.config/sketchybar/plugins/clock.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# The $NAME variable is passed from sketchybar and holds the name of +# the item invoking this script: +# https://felixkratz.github.io/SketchyBar/config/events#events-and-scripting + +HOUR=$(date +%l) + +if (( $HOUR >= 10 )); then + sketchybar --set "$NAME" label.padding_right=10 +else + sketchybar --set "$NAME" label.padding_right=20 +fi + +sketchybar --set "$NAME" label=" $(date +'%a %d %b')  $(date +'%I:%M %p')" diff --git a/stow/.config/sketchybar/plugins/front_app.sh b/stow/.config/sketchybar/plugins/front_app.sh new file mode 100755 index 0000000..fb6d0b3 --- /dev/null +++ b/stow/.config/sketchybar/plugins/front_app.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# 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 + +if [ "$SENDER" = "front_app_switched" ]; then + sketchybar --set "$NAME" label="$INFO" +fi diff --git a/stow/.config/sketchybar/plugins/space.sh b/stow/.config/sketchybar/plugins/space.sh new file mode 100755 index 0000000..b9bf8f6 --- /dev/null +++ b/stow/.config/sketchybar/plugins/space.sh @@ -0,0 +1,13 @@ +#!/usr/local/bin/bash + +# The $SELECTED variable is available for space components and indicates if +# the space invoking this script (with name: $NAME) is currently selected: +# https://felixkratz.github.io/SketchyBar/config/components#space----associate-mission-control-spaces-with-an-item + +#sketchybar --set "$NAME" background.drawing="$SELECTED" + +if [ $SELECTED = 'true' ]; then + sketchybar --set "$NAME" background.color=0xfff48fb1 +else + sketchybar --set "$NAME" background.color=0xffffffff +fi diff --git a/stow/.config/sketchybar/plugins/volume.sh b/stow/.config/sketchybar/plugins/volume.sh new file mode 100755 index 0000000..6e69a5d --- /dev/null +++ b/stow/.config/sketchybar/plugins/volume.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# The volume_change event supplies a $INFO variable in which the current volume +# percentage is passed to the script. + +if [ "$SENDER" = "volume_change" ]; then + VOLUME="$INFO" + + case "$VOLUME" in + [6-9][0-9]|100) ICON="󰕾" + ;; + [3-5][0-9]) ICON="󰖀" + ;; + [1-9]|[1-2][0-9]) ICON="󰕿" + ;; + *) ICON="󰖁" + esac + + sketchybar --set "$NAME" icon="$ICON" label="$VOLUME%" +fi diff --git a/stow/.config/sketchybar/sketchybarrc b/stow/.config/sketchybar/sketchybarrc new file mode 100755 index 0000000..2b1366e --- /dev/null +++ b/stow/.config/sketchybar/sketchybarrc @@ -0,0 +1,132 @@ +# vim: set filetype=sh : +# This is a demo config to showcase some of the most important commands. +# It is meant to be changed and configured, as it is intentionally kept sparse. +# For a (much) more advanced configuration example see my dotfiles: +# https://github.com/FelixKratz/dotfiles + +PLUGIN_DIR="$HOME/.config/sketchybar/plugins" + +##### Bar Appearance ##### +# Configuring the general appearance of the bar. +# These are only some of the options available. For all options see: +# https://felixkratz.github.io/SketchyBar/config/bar +# If you are looking for other colors, see the color picker: +# https://felixkratz.github.io/SketchyBar/config/tricks#color-picker + +sketchybar --bar position=top \ + height=32 \ + blur_radius=30 \ + color=0x00000000 \ + padding_right=10 \ + padding_left=10 \ + y_offset=3 + +default=( + icon.font="ComicShannsMono Nerd Font:Regular:11.0" + label.font="ComicShannsMono Nerd Font:Bold:11.0" + + padding_left=1 + padding_right=1 + icon.color=$PRIMARY_COLOUR + label.color=$PRIMARY_COLOUR + icon.padding_left=10 + icon.padding_right=1 + label.padding_left=5 + label.padding_right=10 + + background.padding_left=2 + background.padding_right=2 + background.corner_radius=10 +) + +sketchybar --default "${default[@]}" + +##### Adding Mission Control Space Indicators ##### +# Let's add some mission control spaces: +# https://felixkratz.github.io/SketchyBar/config/components#space----associate-mission-control-spaces-with-an-item +# to indicate active and available mission control spaces. + +SPACE_ICONS=("1" "2" "3" "4" "5" "6" "7" "8" "9" "10") +for i in "${!SPACE_ICONS[@]}" +do + sid="$(($i+1))" + space=( + icon.color=$PRIMARY_COLOUR + background.color=$BACKGROUND_COLOUR + + space="$sid" + icon="${SPACE_ICONS[i]}" + icon.padding_left=12 + icon.padding_right=12 + background.height=32 + background.padding_left=0 + background.padding_right=0 + label.drawing=off + script="$PLUGIN_DIR/space.sh" + click_script="yabai -m space --focus $sid" + ) + sketchybar --add space space."$sid" left --set space."$sid" "${space[@]}" +done + +##### Adding Left Items ##### +# We add some regular items to the left side of the bar, where +# only the properties deviating from the current defaults need to be set + +#sketchybar --add item chevron left \ +# --set chevron icon= label.drawing=off \ +# --add item front_app left \ +# --set front_app icon.drawing=off script="$PLUGIN_DIR/front_app.sh" \ +# --subscribe front_app front_app_switched + +sketchybar --add item front_app left \ + --set front_app icon.drawing=off \ + label.color=$PRIMARY_COLOUR \ + padding_left=10 \ + label.padding_left=10 \ + background.color=$BACKGROUND_COLOUR \ + background.height=32 \ + script="$PLUGIN_DIR/front_app.sh" \ + --subscribe front_app front_app_switched \ + + + +##### Adding Right Items ##### + +sketchybar --add item clock right \ + --set clock \ + update_freq=10 \ + icon.color=$PRIMARY_COLOUR \ + label.color=$PRIMARY_COLOUR \ + background.color=$BACKGROUND_COLOUR \ + background.height=32 \ + label.padding_right=20 \ + script="$PLUGIN_DIR/clock.sh" + +sketchybar --add item battery right \ + --set battery update_freq=10 \ + script="$PLUGIN_DIR/battery.sh" \ + icon.color=$SECONDARY_COLOUR \ + label.color=$SECONDARY_COLOUR \ + background.color=$BACKGROUND_COLOUR \ + background.height=32 \ + +sketchybar --add item backlight right \ + --set backlight icon="" \ + icon.color=$TERTIARY_COLOUR \ + label.color=$TERTIARY_COLOUR \ + background.color=$BACKGROUND_COLOUR \ + background.height=32 \ + script="$PLUGIN_DIR/backlight.sh" \ + --subscribe backlight brightness_change \ + +sketchybar --add item audio right \ + --set audio icon = "" \ + icon.color=$TERTIARY_COLOUR \ + label.color=$TERTIARY_COLOUR \ + background.color=$BACKGROUND_COLOUR \ + background.height=32 \ + script="$PLUGIN_DIR/volume.sh" \ + --subscribe audio volume_change \ + +##### Force all scripts to run the first time (never do this in a script) ##### +sketchybar --update