diff --git a/modules/home/sketchybar/default.nix b/modules/home/sketchybar/default.nix new file mode 100644 index 0000000..c1fd3bf --- /dev/null +++ b/modules/home/sketchybar/default.nix @@ -0,0 +1,49 @@ +{ pkgs, ... }: +{ + home.packages = with pkgs; [ + sketchybar + sketchybar-app-font + lua + readline + switchaudio-osx + nowplaying-cli + # sf-symbols + # font-sf-mono + # font-sf-pro + ]; + home.file = { + ".config/sketchybar/sketchybarrc" = { + executable = true; + text = builtins.readFile ./sketchybarrc; + }; + # PLUGINS + ".config/sketchybar/plugins/battery.sh" = { + executable = true; + text = builtins.readFile ./plugins/battery.sh; + }; + ".config/sketchybar/plugins/clock.sh" = { + executable = true; + text = builtins.readFile ./plugins/clock.sh; + }; + ".config/sketchybar/plugins/front_app.sh" = { + executable = true; + text = builtins.readFile ./plugins/front_app.sh; + }; + ".config/sketchybar/plugins/memory.sh" = { + executable = true; + text = builtins.readFile ./plugins/memory.sh; + }; + ".config/sketchybar/plugins/nowplaying.sh" = { + executable = true; + text = builtins.readFile ./plugins/nowplaying.sh; + }; + ".config/sketchybar/plugins/space.sh" = { + executable = true; + text = builtins.readFile ./plugins/space.sh; + }; + ".config/sketchybar/plugins/volume.sh" = { + executable = true; + text = builtins.readFile ./plugins/volume.sh; + }; + }; +} diff --git a/modules/home/sketchybar/plugins/battery.sh b/modules/home/sketchybar/plugins/battery.sh new file mode 100755 index 0000000..c7b2490 --- /dev/null +++ b/modules/home/sketchybar/plugins/battery.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +PERCENTAGE="$(pmset -g batt | grep -Eo "...%" | awk '{print $1}')" +CHARGING="$(pmset -g batt | grep 'AC Power')" + +# The item invoking this script (name $NAME) will get its icon and label +# updated with the current battery status + +if [[ "$CHARGING" != "" ]]; then + STATE="CHAR:" +else + STATE="BATT:" +fi + +sketchybar --set "$NAME" label="$STATE $PERCENTAGE" diff --git a/modules/home/sketchybar/plugins/clock.sh b/modules/home/sketchybar/plugins/clock.sh new file mode 100755 index 0000000..043323a --- /dev/null +++ b/modules/home/sketchybar/plugins/clock.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# 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 + +sketchybar --set "$NAME" label="$(date '+%Z'): $(date '+%H:%M')" diff --git a/modules/home/sketchybar/plugins/front_app.sh b/modules/home/sketchybar/plugins/front_app.sh new file mode 100755 index 0000000..fb6d0b3 --- /dev/null +++ b/modules/home/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/modules/home/sketchybar/plugins/memory.sh b/modules/home/sketchybar/plugins/memory.sh new file mode 100755 index 0000000..0e10b13 --- /dev/null +++ b/modules/home/sketchybar/plugins/memory.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +hw_pagesize="$(sysctl -n hw.pagesize)" +mem_total="$(($(sysctl -n hw.memsize) / 1024 / 1024))" +mem_total_gb="$(($(sysctl -n hw.memsize) / 1024 / 1024 / 1024))" +pages_app="$(($(sysctl -n vm.page_pageable_internal_count) - $(sysctl -n vm.page_purgeable_count)))" +pages_wired="$(vm_stat | awk '/ wired/ { print $4 }')" +pages_compressed="$(vm_stat | awk '/ occupied/ { printf $5 }')" +pages_compressed="${pages_compressed:-0}" +mem_used="$(((${pages_app} + ${pages_wired//./} + ${pages_compressed//./}) * hw_pagesize / 1024 / 1024))" +mem_used_gb="$((${mem_used} / 1024))" + +sketchybar --set "$NAME" label="RAM: $mem_used_gb GiB/$mem_total_gb GiB" diff --git a/modules/home/sketchybar/plugins/nowplaying.sh b/modules/home/sketchybar/plugins/nowplaying.sh new file mode 100755 index 0000000..f4b2161 --- /dev/null +++ b/modules/home/sketchybar/plugins/nowplaying.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +sketchybar --set "$NAME" label="$(nowplaying-cli get title) - $(nowplaying-cli get artist)" diff --git a/modules/home/sketchybar/plugins/space.sh b/modules/home/sketchybar/plugins/space.sh new file mode 100755 index 0000000..b8602b5 --- /dev/null +++ b/modules/home/sketchybar/plugins/space.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# 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" diff --git a/modules/home/sketchybar/plugins/volume.sh b/modules/home/sketchybar/plugins/volume.sh new file mode 100755 index 0000000..a9f414d --- /dev/null +++ b/modules/home/sketchybar/plugins/volume.sh @@ -0,0 +1,26 @@ +#!/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" + + CURRENT="$(SwitchAudioSource -c)" + + #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="$CURRENT: $VOLUME%" + sketchybar --set "$NAME" label="VOL: $CURRENT: $VOLUME%" +fi diff --git a/modules/home/sketchybar/sketchybarrc b/modules/home/sketchybar/sketchybarrc new file mode 100755 index 0000000..87f929a --- /dev/null +++ b/modules/home/sketchybar/sketchybarrc @@ -0,0 +1,96 @@ +# 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="$CONFIG_DIR/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=40 blur_radius=16 color=0x40000000 + +##### Changing Defaults ##### +# We now change some default values, which are applied to all further items. +# For a full list of all available item properties see: +# https://felixkratz.github.io/SketchyBar/config/items + +default=( + padding_left=5 + padding_right=5 + icon.font="scientifica:regular:12.0" + label.font="scientifica:regular:12.0" + icon.color=0xffffffff + label.color=0xffffffff + icon.padding_left=4 + icon.padding_right=4 + label.padding_left=4 + label.padding_right=4 +) +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=( + space="$sid" + icon="${SPACE_ICONS[i]}" + icon.padding_left=7 + icon.padding_right=7 + background.color=0x40ffffff + background.corner_radius=5 + background.height=25 + 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 nowplaying left \ + --set nowplaying update_freq=2 script="$PLUGIN_DIR/nowplaying.sh" \ + --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 + +##### Adding Right Items ##### +# In the same way as the left items we can add items to the right side. +# Additional position (e.g. center) are available, see: +# https://felixkratz.github.io/SketchyBar/config/items#adding-items-to-sketchybar + +# Some items refresh on a fixed cycle, e.g. the clock runs its script once +# every 10s. Other items respond to events they subscribe to, e.g. the +# volume.sh script is only executed once an actual change in system audio +# volume is registered. More info about the event system can be found here: +# https://felixkratz.github.io/SketchyBar/config/events + +sketchybar --add item clock right \ + --set clock update_freq=10 script="$PLUGIN_DIR/clock.sh" \ + --add item battery right \ + --set battery update_freq=120 script="$PLUGIN_DIR/battery.sh" \ + --subscribe battery system_woke power_source_change \ + --add item volume right \ + --set volume script="$PLUGIN_DIR/volume.sh" \ + --subscribe volume volume_change \ + --add item memory right \ + --set memory script="$PLUGIN_DIR/memory.sh" \ + --set memory update_freq=120 \ + +##### Force all scripts to run the first time (never do this in a script) ##### +sketchybar --update