From d164167c86f8dfd999d2d0e79eae7a8bae41ec97 Mon Sep 17 00:00:00 2001 From: Badstagram Date: Wed, 22 Oct 2025 04:54:21 +0100 Subject: [PATCH] temp add sketchybar --- .../sketchybar/executable_sketchybarrc | 134 ++++++++++++++++++ .../plugins-laptop/executable_battery.sh | 43 ++++++ .../plugins-laptop/executable_spotify.sh | 65 +++++++++ .../sketchybar/plugins/executable_clock.sh | 3 + .../plugins/executable_current_space.sh | 34 +++++ .../plugins/executable_front_app.sh | 77 ++++++++++ .../sketchybar/plugins/executable_volume.sh | 18 +++ .../sketchybar/plugins/executable_weather.sh | 55 +++++++ 8 files changed, 429 insertions(+) create mode 100644 private_dot_config/sketchybar/executable_sketchybarrc create mode 100644 private_dot_config/sketchybar/plugins-laptop/executable_battery.sh create mode 100644 private_dot_config/sketchybar/plugins-laptop/executable_spotify.sh create mode 100644 private_dot_config/sketchybar/plugins/executable_clock.sh create mode 100644 private_dot_config/sketchybar/plugins/executable_current_space.sh create mode 100644 private_dot_config/sketchybar/plugins/executable_front_app.sh create mode 100644 private_dot_config/sketchybar/plugins/executable_volume.sh create mode 100644 private_dot_config/sketchybar/plugins/executable_weather.sh diff --git a/private_dot_config/sketchybar/executable_sketchybarrc b/private_dot_config/sketchybar/executable_sketchybarrc new file mode 100644 index 0000000..fd23786 --- /dev/null +++ b/private_dot_config/sketchybar/executable_sketchybarrc @@ -0,0 +1,134 @@ +#!/usr/bin/env zsh + +FONT_FACE="JetBrainsMono Nerd Font" + +PLUGIN_DIR="$HOME/.config/sketchybar/plugins-laptop" +PLUGIN_SHARED_DIR="$HOME/.config/sketchybar/plugins" + +SPOTIFY_EVENT="com.spotify.client.PlaybackStateChanged" + +sketchybar --bar \ + height=32 \ + color=0x00000000 \ + margin=0 \ + sticky=on \ + padding_left=23 \ + padding_right=23 \ + notch_width=188 \ + display=main + +# Alternatiive background colors +# label.color=0xffffffff +# background.color=0x9924273a +sketchybar --default \ + background.color=0x66494d64 \ + background.corner_radius=5 \ + background.padding_right=5 \ + background.height=26 \ + icon.font="$FONT_FACE:Medium:15.0" \ + icon.padding_left=5 \ + icon.padding_right=5 \ + label.font="$FONT_FACE:Medium:12.0" \ + label.color=0xffcad3f5 \ + label.y_offset=0 \ + label.padding_left=0 \ + label.padding_right=5 + +sketchybar --add event spotify_change $SPOTIFY_EVENT \ + --add item spotify e \ + --set spotify \ + icon= \ + icon.y_offset=1 \ + icon.font="$FONT_FACE:Bold:20.0" \ + label.drawing=off \ + label.padding_left=3 \ + script="$PLUGIN_DIR/spotify.sh" \ + --subscribe spotify spotify_change mouse.clicked + +sketchybar --add item current_space left \ + --set current_space \ + background.color=0xfff5a97f \ + icon.color=0xff24273a \ + label.drawing=off \ + script="$PLUGIN_SHARED_DIR/current_space.sh" \ + --subscribe current_space space_change mouse.clicked + +sketchybar --add item front_app left \ + --set front_app \ + background.color=0xffa6da95 \ + background.padding_left=0 \ + background.padding_right=0 \ + icon.y_offset=1 \ + icon.color=0xff24273a \ + label.drawing=no \ + script="$PLUGIN_SHARED_DIR/front_app.sh" \ + --add item front_app.separator left \ + --set front_app.separator \ + background.color=0x00000000 \ + background.padding_left=-3 \ + icon= \ + icon.color=0xffa6da95 \ + icon.font="$FONT_FACE:Bold:20.0" \ + icon.padding_left=0 \ + icon.padding_right=0 \ + icon.y_offset=1 \ + label.drawing=no \ + --add item front_app.name left \ + --set front_app.name \ + background.color=0x00000000 \ + background.padding_right=0 \ + icon.drawing=off \ + label.font="$FONT_FACE:Bold:12.0" \ + label.drawing=yes + +sketchybar --add item weather.moon q \ + --set weather.moon \ + background.color=0x667dc4e4 \ + background.padding_right=-1 \ + icon.color=0xff181926 \ + icon.font="$FONT_FACE:Bold:22.0" \ + icon.padding_left=4 \ + icon.padding_right=3 \ + label.drawing=off \ + --subscribe weather.moon mouse.clicked + +sketchybar --add item weather q \ + --set weather \ + icon= \ + icon.color=0xfff5bde6 \ + icon.font="$FONT_FACE:Bold:15.0" \ + update_freq=1800 \ + script="$PLUGIN_SHARED_DIR/weather.sh" \ + --subscribe weather system_woke + +sketchybar --add bracket front_app_bracket \ + front_app \ + front_app.separator \ + front_app.name \ + --subscribe front_app front_app_switched + +sketchybar --add item clock right \ + --set clock \ + icon=󰃰 \ + icon.color=0xffed8796 \ + update_freq=10 \ + script="$PLUGIN_SHARED_DIR/clock.sh" + +sketchybar --add item battery right \ + --set battery \ + update_freq=20 \ + script="$PLUGIN_DIR/battery.sh" + +sketchybar --add item volume right \ + --set volume \ + icon.color=0xff8aadf4 \ + label.drawing=true \ + script="$PLUGIN_SHARED_DIR/volume.sh" \ + --subscribe volume volume_change + +# osascript -e 'quit app "Rectangle"' +# open -a Rectangle + +##### Finalizing Setup ##### +sketchybar --update +sketchybar --trigger space_change diff --git a/private_dot_config/sketchybar/plugins-laptop/executable_battery.sh b/private_dot_config/sketchybar/plugins-laptop/executable_battery.sh new file mode 100644 index 0000000..ea880a4 --- /dev/null +++ b/private_dot_config/sketchybar/plugins-laptop/executable_battery.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env sh + +# Battery is here bcause the ICON_COLOR doesn't play well with all background colors + +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 +[8-9][0-9] | 100) + ICON="" + ICON_COLOR=0xffa6da95 + ;; +7[0-9]) + ICON="" + ICON_COLOR=0xffeed49f + ;; +[4-6][0-9]) + ICON="" + ICON_COLOR=0xfff5a97f + ;; +[1-3][0-9]) + ICON="" + ICON_COLOR=0xffee99a0 + ;; +[0-9]) + ICON="" + ICON_COLOR=0xffed8796 + ;; +esac + +if [[ $CHARGING != "" ]]; then + ICON="" + ICON_COLOR=0xffeed49f +fi + +sketchybar --set $NAME \ + icon=$ICON \ + label="${PERCENTAGE}%" \ + icon.color=${ICON_COLOR} diff --git a/private_dot_config/sketchybar/plugins-laptop/executable_spotify.sh b/private_dot_config/sketchybar/plugins-laptop/executable_spotify.sh new file mode 100644 index 0000000..ce54953 --- /dev/null +++ b/private_dot_config/sketchybar/plugins-laptop/executable_spotify.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env zsh + +# Max number of characters so it fits nicely to the right of the notch +# MAY NOT WORK WITH NON-ENGLISH CHARACTERS + +MAX_LENGTH=35 + +# Logic starts here, do not modify +HALF_LENGTH=$(((MAX_LENGTH + 1) / 2)) + +# Spotify JSON / $INFO comes in malformed, line below sanitizes it +SPOTIFY_JSON="$INFO" + +update_track() { + + if [[ -z $SPOTIFY_JSON ]]; then + sketchybar --set $NAME icon.color=0xffeed49f label.drawing=no + return + fi + + PLAYER_STATE=$(echo "$SPOTIFY_JSON" | jq -r '.["Player State"]') + + if [ $PLAYER_STATE = "Playing" ]; then + TRACK="$(echo "$SPOTIFY_JSON" | jq -r .Name)" + ARTIST="$(echo "$SPOTIFY_JSON" | jq -r .Artist)" + + # Calculations so it fits nicely + TRACK_LENGTH=${#TRACK} + ARTIST_LENGTH=${#ARTIST} + + if [ $((TRACK_LENGTH + ARTIST_LENGTH)) -gt $MAX_LENGTH ]; then + # If the total length exceeds the max + if [ $TRACK_LENGTH -gt $HALF_LENGTH ] && [ $ARTIST_LENGTH -gt $HALF_LENGTH ]; then + # If both the track and artist are too long, cut both at half length - 1 + + # If MAX_LENGTH is odd, HALF_LENGTH is calculated with an extra space, so give it an extra char + TRACK="${TRACK:0:$((MAX_LENGTH % 2 == 0 ? HALF_LENGTH - 2 : HALF_LENGTH - 1))}…" + ARTIST="${ARTIST:0:$((HALF_LENGTH - 2))}…" + + elif [ $TRACK_LENGTH -gt $HALF_LENGTH ]; then + # Else if only the track is too long, cut it by the difference of the max length and artist length + TRACK="${TRACK:0:$((MAX_LENGTH - ARTIST_LENGTH - 1))}…" + elif [ $ARTIST_LENGTH -gt $HALF_LENGTH ]; then + ARTIST="${ARTIST:0:$((MAX_LENGTH - TRACK_LENGTH - 1))}…" + fi + fi + sketchybar --set $NAME label="${TRACK}  ${ARTIST}" label.drawing=yes icon.color=0xffa6da95 + + elif [ $PLAYER_STATE = "Paused" ]; then + sketchybar --set $NAME icon.color=0xffeed49f + elif [ $PLAYER_STATE = "Stopped" ]; then + sketchybar --set $NAME icon.color=0xffeed49f label.drawing=no + else + sketchybar --set $NAME icon.color=0xffeed49f + fi +} + +case "$SENDER" in +"mouse.clicked") + osascript -e 'tell application "Spotify" to playpause' + ;; +*) + update_track + ;; +esac diff --git a/private_dot_config/sketchybar/plugins/executable_clock.sh b/private_dot_config/sketchybar/plugins/executable_clock.sh new file mode 100644 index 0000000..12c2452 --- /dev/null +++ b/private_dot_config/sketchybar/plugins/executable_clock.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env zsh + +sketchybar --set $NAME label="$(date '+%a %b %-d %-H:%M')" diff --git a/private_dot_config/sketchybar/plugins/executable_current_space.sh b/private_dot_config/sketchybar/plugins/executable_current_space.sh new file mode 100644 index 0000000..65dd20d --- /dev/null +++ b/private_dot_config/sketchybar/plugins/executable_current_space.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env zsh + +update_space() { + SPACE_ID=$(echo "$INFO" | jq -r '."display-1"') + + case $SPACE_ID in + 1) + ICON=󰅶 + ICON_PADDING_LEFT=7 + ICON_PADDING_RIGHT=7 + ;; + *) + ICON=$SPACE_ID + ICON_PADDING_LEFT=9 + ICON_PADDING_RIGHT=10 + ;; + esac + + sketchybar --set $NAME \ + icon=$ICON \ + icon.padding_left=$ICON_PADDING_LEFT \ + icon.padding_right=$ICON_PADDING_RIGHT +} + +case "$SENDER" in +"mouse.clicked") + # Reload sketchybar + sketchybar --remove '/.*/' + source $HOME/.config/sketchybar/sketchybarrc + ;; +*) + update_space + ;; +esac diff --git a/private_dot_config/sketchybar/plugins/executable_front_app.sh b/private_dot_config/sketchybar/plugins/executable_front_app.sh new file mode 100644 index 0000000..5aefa29 --- /dev/null +++ b/private_dot_config/sketchybar/plugins/executable_front_app.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env zsh + +ICON_PADDING_RIGHT=5 + +case $INFO in +"Arc") + ICON_PADDING_RIGHT=5 + ICON=󰞍 + ;; +"Code") + ICON_PADDING_RIGHT=4 + ICON=󰨞 + ;; +"Calendar") + ICON_PADDING_RIGHT=3 + ICON= + ;; +"Discord Canary") + ICON= + ;; +"FaceTime") + ICON_PADDING_RIGHT=5 + ICON= + ;; +"Finder") + ICON=󰀶 + ;; +"Google Chrome") + ICON_PADDING_RIGHT=7 + ICON= + ;; +"IINA") + ICON_PADDING_RIGHT=4 + ICON=󰕼 + ;; +"kitty") + ICON=󰄛 + ;; +"Messages") + ICON= + ;; +"Notion") + ICON_PADDING_RIGHT=6 + ICON=󰎚 + ;; +"Preview") + ICON_PADDING_RIGHT=3 + ICON= + ;; +"PS Remote Play") + ICON_PADDING_RIGHT=3 + ICON= + ;; +"Spotify") + ICON_PADDING_RIGHT=2 + ICON= + ;; +"TextEdit") + ICON_PADDING_RIGHT=4 + ICON= + ;; +"Transmission") + ICON_PADDING_RIGHT=3 + ICON=󰶘 + ;; +"Firefox") + ICON_PADDING_RIGHT=3 + ICON= + ;; +*) + ICON_PADDING_RIGHT=2 + ICON= + ;; +esac + +sketchybar --set $NAME icon=$ICON icon.padding_right=$ICON_PADDING_RIGHT +sketchybar --set $NAME.name label="$INFO" diff --git a/private_dot_config/sketchybar/plugins/executable_volume.sh b/private_dot_config/sketchybar/plugins/executable_volume.sh new file mode 100644 index 0000000..b31d82d --- /dev/null +++ b/private_dot_config/sketchybar/plugins/executable_volume.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env zsh + +case ${INFO} in +0) + ICON="" + ICON_PADDING_RIGHT=21 + ;; +[0-9]) + ICON="" + ICON_PADDING_RIGHT=12 + ;; +*) + ICON="" + ICON_PADDING_RIGHT=6 + ;; +esac + +sketchybar --set $NAME icon=$ICON icon.padding_right=$ICON_PADDING_RIGHT label="$INFO%" diff --git a/private_dot_config/sketchybar/plugins/executable_weather.sh b/private_dot_config/sketchybar/plugins/executable_weather.sh new file mode 100644 index 0000000..5448a55 --- /dev/null +++ b/private_dot_config/sketchybar/plugins/executable_weather.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env zsh + +IP=$(curl -s https://ipinfo.io/ip) +LOCATION_JSON=$(curl -s https://ipinfo.io/$IP/json) + +LOCATION="$(echo $LOCATION_JSON | jq '.city' | tr -d '"')" +REGION="$(echo $LOCATION_JSON | jq '.region' | tr -d '"')" +COUNTRY="$(echo $LOCATION_JSON | jq '.country' | tr -d '"')" + +# Line below replaces spaces with + +LOCATION_ESCAPED="${LOCATION// /+}+${REGION// /+}" +WEATHER_JSON=$(curl -s "https://wttr.in/$LOCATION_ESCAPED?format=j1") + +# Fallback if empty +if [ -z $WEATHER_JSON ]; then + + sketchybar --set $NAME label=$LOCATION + sketchybar --set $NAME.moon icon= + + return +fi + +TEMPERATURE=$(echo $WEATHER_JSON | jq '.current_condition[0].temp_C' | tr -d '"') +WEATHER_DESCRIPTION=$(echo $WEATHER_JSON | jq '.current_condition[0].weatherDesc[0].value' | tr -d '"' | sed 's/\(.\{25\}\).*/\1.../') +MOON_PHASE=$(echo $WEATHER_JSON | jq '.weather[0].astronomy[0].moon_phase' | tr -d '"') + +case ${MOON_PHASE} in +"New Moon") + ICON= + ;; +"Waxing Crescent") + ICON= + ;; +"First Quarter") + ICON= + ;; +"Waxing Gibbous") + ICON= + ;; +"Full Moon") + ICON= + ;; +"Waning Gibbous") + ICON= + ;; +"Last Quarter") + ICON= + ;; +"Waning Crescent") + ICON= + ;; +esac + +sketchybar --set $NAME label="$LOCATION  $TEMPERATURE℃ $WEATHER_DESCRIPTION" +sketchybar --set $NAME.moon icon=$ICON