diff --git a/home/apps/sketchybar/plugins/clock.nu b/home/apps/sketchybar/plugins/clock.nu new file mode 100755 index 0000000..9814dbc --- /dev/null +++ b/home/apps/sketchybar/plugins/clock.nu @@ -0,0 +1,3 @@ +#!/usr/bin/env nu + +sketchybar --set $env.NAME $"label=(date now | format date '%H:%M')" diff --git a/home/apps/sketchybar/plugins/clock.sh b/home/apps/sketchybar/plugins/clock.sh deleted file mode 100755 index 146517b..0000000 --- a/home/apps/sketchybar/plugins/clock.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh - -sketchybar --set "$NAME" label="$(date '+%H:%M')" diff --git a/home/apps/sketchybar/plugins/colordummy.nu b/home/apps/sketchybar/plugins/colordummy.nu new file mode 100755 index 0000000..5799dcd --- /dev/null +++ b/home/apps/sketchybar/plugins/colordummy.nu @@ -0,0 +1,117 @@ +#!/usr/bin/env nu +# vim:fdm=marker + +# color definitions {{{ +const variants = { + dark: { + fg: 0xffffff + bg: 0x1c2127 + gray: 0xc5cbd3 + bgGray: 0x404854 + fgGray: 0xd3d8de + core: 0x111418 + blue: 0x8abbff + green: 0x72ca9b + orange: 0xfbb360 + red: 0xfa999c + vermilion: 0xff9980 + rose: 0xff66a1 + violet: 0xd69fd6 + indigo: 0xbdadff + cerulean: 0x68c1ee + turquoise: 0x7ae1d8 + forest: 0x62d96b + lime: 0xd4f17e + gold: 0xfbd065 + sepia: 0xd0b090 + } + light: { + fg: 0x111418 + bg: 0xf6f7f9 + gray: 0x5f6b7c + bgGray: 0xd3d8de + fgGray: 0x404854 + core: 0xffffff + blue: 0x2d72d2 + green: 0x238551 + orange: 0xc87619 + red: 0xcd4246 + vermilion: 0xd33d17 + rose: 0xdb2c6f + violet: 0x9d3f9d + indigo: 0x7961db + cerulean: 0x147eb3 + turquoise: 0x00a396 + forest: 0x29a634 + lime: 0x8eb125 + gold: 0xd1980b + sepia: 0x946638 + } +} +# }}} + +# check whether or not macOS is in dark mode +let theme = if ((defaults read -g AppleInterfaceStyle err>/dev/null) != "Dark") { + "light" +} else { + "dark" +} + +def color [name: string, alpha: float = 1.0] { + let color = ($variants) | get -i $theme | get -i $name | default null + let alpha = [0.0 ([$alpha 1.0] | math min)] | math max + | $in * 255 + | math round + | bits shl 24 -n 4 + + if $color == null { + error make { + msg: "Error formatting color" + label: { + text: "Color name not found" + span: (metadata $name).span + } + help: $"Expected one of: ($variants | get $theme | columns | str join ', ')" + } + } + + $alpha bit-or $color + | fmt + | get lowerhex + | str replace "0x" "" + | fill --alignment "right" --character "0" --width 8 + | "0x" + $in +} + +(sketchybar + --bar + $"color=(color bg)" + border_color=(color rose) + --default + $"icon.color=(color rose)" + $"label.color=(color rose)" + --set /space/ + $"icon.color=(color violet 0.5)" + $"icon.highlight_color=(color rose)" + --set window_title + $"icon.color=(color rose)" + $"label.color=(color gray)" + --set music + $"icon.color=(color rose)" + $"label.color=(color rose)" + --set "Mullvad VPN" + $"alias.color=(color orange)" + --set "Control Centre,Battery" + $"alias.color=(color gold)" + --set "Little Snitch Agent" + $"alias.color=(color green)" + --set "iStat Menus Status" + $"alias.color=(color blue)" + --set clock + $"icon.color=(color violet)" + $"label.color=(color violet)") + +# set the yabai colors as well +# yabai -m config active_window_border_color "$(color pink)" +# yabai -m config normal_window_border_color "$(color surface0)" +# yabai -m config insert_feedback_color "$(color red)" diff --git a/home/apps/sketchybar/plugins/colordummy.sh b/home/apps/sketchybar/plugins/colordummy.sh deleted file mode 100755 index 2f333e8..0000000 --- a/home/apps/sketchybar/plugins/colordummy.sh +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/env bash -# vim:fdm=marker -# don't warn about unused variables: -# shellcheck disable=SC2034 - -# color definitions {{{ -# mocha {{{ -mocha_rosewater="f5e0dc" -mocha_flamingo="f2cdcd" -mocha_pink="f5c2e7" -mocha_mauve="cba6f7" -mocha_red="f38ba8" -mocha_maroon="eba0ac" -mocha_peach="fab387" -mocha_yellow="f9e2af" -mocha_green="a6e3a1" -mocha_teal="94e2d5" -mocha_sky="89dceb" -mocha_sapphire="74c7ec" -mocha_blue="89b4fa" -mocha_lavender="b4befe" -mocha_text="cdd6f4" -mocha_subtext1="bac2de" -mocha_subtext0="a6adc8" -mocha_overlay2="9399b2" -mocha_overlay1="7f849c" -mocha_overlay0="6c7086" -mocha_surface2="585b70" -mocha_surface1="45475a" -mocha_surface0="313244" -mocha_base="1e1e2e" -mocha_mantle="181825" -mocha_crust="11111b" -## }}} - -## macchiato {{{ -macchiato_rosewater="f4dbd6" -macchiato_flamingo="f0c6c6" -macchiato_pink="f5bde6" -macchiato_mauve="c6a0f6" -macchiato_red="ed8796" -macchiato_maroon="ee99a0" -macchiato_peach="f5a97f" -macchiato_yellow="eed49f" -macchiato_green="a6da95" -macchiato_teal="8bd5ca" -macchiato_sky="91d7e3" -macchiato_sapphire="7dc4e4" -macchiato_blue="8aadf4" -macchiato_lavender="b7bdf8" -macchiato_text="cad3f5" -macchiato_subtext1="b8c0e0" -macchiato_subtext0="a5adcb" -macchiato_overlay2="939ab7" -macchiato_overlay1="8087a2" -macchiato_overlay0="6e738d" -macchiato_surface2="5b6078" -macchiato_surface1="494d64" -macchiato_surface0="363a4f" -macchiato_base="24273a" -macchiato_mantle="1e2030" -macchiato_crust="181926" -## }}} - -# frappe {{{ -frappe_rosewater="f2d5cf" -frappe_flamingo="eebebe" -frappe_pink="f4b8e4" -frappe_mauve="ca9ee6" -frappe_red="e78284" -frappe_maroon="ea999c" -frappe_peach="ef9f76" -frappe_yellow="e5c890" -frappe_green="a6d189" -frappe_teal="81c8be" -frappe_sky="99d1db" -frappe_sapphire="85c1dc" -frappe_blue="8caaee" -frappe_lavender="babbf1" -frappe_text="c6d0f5" -frappe_subtext1="b5bfe2" -frappe_subtext0="a5adce" -frappe_overlay2="949cbb" -frappe_overlay1="838ba7" -frappe_overlay0="737994" -frappe_surface2="626880" -frappe_surface1="51576d" -frappe_surface0="414559" -frappe_base="303446" -frappe_mantle="292c3c" -frappe_crust="232634" -## }}} - -## latte {{{ -latte_rosewater="dc8a78" -latte_flamingo="dd7878" -latte_pink="ea76cb" -latte_mauve="8839ef" -latte_red="d20f39" -latte_maroon="e64553" -latte_peach="fe640b" -latte_yellow="df8e1d" -latte_green="40a02b" -latte_teal="179299" -latte_sky="04a5e5" -latte_sapphire="209fb5" -latte_blue="1e66f5" -latte_lavender="7287fd" -latte_text="4c4f69" -latte_subtext1="5c5f77" -latte_subtext0="6c6f85" -latte_overlay2="7c7f93" -latte_overlay1="8c8fa1" -latte_overlay0="9ca0b0" -latte_surface2="acb0be" -latte_surface1="bcc0cc" -latte_surface0="ccd0da" -latte_crust="dce0e8" -latte_mantle="e6e9ef" -latte_base="eff2f5" -## }}} -# }}} - -LIGHT_THEME="latte" -DARK_THEME="mocha" - -# check whether or not macOS is in dark mode -if [[ $(defaults read -g AppleInterfaceStyle 2>/dev/null) != 'Dark' ]]; then - theme=$LIGHT_THEME -else - theme=$DARK_THEME -fi - -function color() { - alpha=${2:-1} - color="$1" - - printf -v parsed "%.0f" "$(bc -l <<<"255*${alpha}")" - printf -v alpha "%02x" "$parsed" - selected_color="${theme}_${color}" - echo "0x${alpha}${!selected_color}" -} - -sketchybar \ - --bar \ - color="$(color base)" \ - border_color="$(color crust)" \ - --default \ - icon.color="$(color pink)" \ - label.color="$(color pink)" \ - --set /space/ \ - icon.color="$(color mauve 0.5)" \ - icon.highlight_color="$(color pink)" \ - --set music \ - icon.color="$(color pink)" \ - label.color="$(color pink)" \ - --set "Mullvad VPN" \ - alias.color="$(color peach)" \ - --set "Control Centre,Battery" \ - alias.color="$(color yellow)" \ - --set "Little Snitch Agent" \ - alias.color="$(color green)" \ - --set "iStat Menus Status" \ - alias.color="$(color blue)" \ - --set clock \ - icon.color="$(color mauve)" \ - label.color="$(color mauve)" - -# set the yabai colors as well -yabai -m config active_window_border_color "$(color pink)" -yabai -m config normal_window_border_color "$(color surface0)" -yabai -m config insert_feedback_color "$(color red)" diff --git a/home/apps/sketchybar/plugins/music.nu b/home/apps/sketchybar/plugins/music.nu new file mode 100755 index 0000000..2c1f77c --- /dev/null +++ b/home/apps/sketchybar/plugins/music.nu @@ -0,0 +1,25 @@ +#!/usr/bin/env nu + +if (pgrep -x Music | is-not-empty) { + let result = osascript -l JavaScript -e " + var music = Application("Music"); + JSON.stringify({ + albumArtist: music.currentTrack.albumArtist(), + artist: music.currentTrack.artist(), + state: music.playerState(), + track: music.currentTrack.name(), + });" | from json + + let artist = if (($result.albumArtist | is-empty) or ($result.albumArtist == "Various Artists")) { + $result.artist + } else $result.albumArtist + + let label = if ($result.state == "playing") { + $"($artist) - ($result.track)" + } else "" + + (sketchybar + --set $env.NAME $"label=($label)" + icon.font="Symbols Nerd Font:2048-em:18.0" + label.font="Berkeley Mono:Bold:16.0" y_offset="3") +} else (sketchybar --set $env.NAME label="") diff --git a/home/apps/sketchybar/plugins/music.sh b/home/apps/sketchybar/plugins/music.sh deleted file mode 100755 index 92437c5..0000000 --- a/home/apps/sketchybar/plugins/music.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -if pgrep -xq Music; then - STATE=$(osascript -e 'tell application "Music" to player state as string' 2>/dev/null) - TRACK=$(osascript -e 'tell application "Music" to name of current track as string' 2>/dev/null) - ARTIST=$(osascript -e 'tell application "Music" to album artist of current track as string' 2>/dev/null) - - # fall back to artist, if album artist is unavailable, or generic - if [[ -z "$ARTIST" ]] || [[ "$ARTIST" = "Various Artists" ]]; then - ARTIST=$(osascript -e 'tell application "Music" to artist of current track as string' 2>/dev/null) - fi - - if [[ "$STATE" = "playing" ]]; then - LABEL="$ARTIST - $TRACK" - else - LABEL="" - fi - sketchybar --set "$NAME" label="$LABEL" \ - icon.font="Symbols Nerd Font:2048-em:18.0" \ - label.font="Victor Mono:Italic:16.0" y_offset="3" -else - sketchybar --set "$NAME" label="" -fi diff --git a/home/apps/sketchybar/plugins/space.nu b/home/apps/sketchybar/plugins/space.nu new file mode 100755 index 0000000..c41c0b6 --- /dev/null +++ b/home/apps/sketchybar/plugins/space.nu @@ -0,0 +1,3 @@ +#!/usr/bin/env nu + +sketchybar --set $env.NAME $"icon.highlight=($env.SELECTED)" $"background.drawing=($env.SELECTED)" diff --git a/home/apps/sketchybar/plugins/space.sh b/home/apps/sketchybar/plugins/space.sh deleted file mode 100755 index 72e2d82..0000000 --- a/home/apps/sketchybar/plugins/space.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh - -sketchybar --set "$NAME" icon.highlight="$SELECTED" background.drawing="$SELECTED" diff --git a/home/apps/sketchybar/plugins/window_title.nu b/home/apps/sketchybar/plugins/window_title.nu new file mode 100755 index 0000000..f81e3e6 --- /dev/null +++ b/home/apps/sketchybar/plugins/window_title.nu @@ -0,0 +1,58 @@ +#!/usr/bin/env nu + +let icon = match ($env | get -i INFO) { + # IDEs + "CLion" | "GoLand" | "PhpStorm" | "PyCharm" | RustRover | "WebStorm" | "Xcode" => " ", + "Neovide" => " ", + + # developer + "Docker" => " ", + + # terminals + "Kitty" | "iTerm" | "Terminal" | "WezTerm" => " ", + + # browsers + "Chromium" | "Firefox" | "Safari" | "qutebrowser" => " ", + + # system + "App Store" => " ", + "Books" => " ", + "Finder" => "󰀶 ", + "Music" => "󰝚 ", + "Podcasts" => " ", + "Photos" => " ", + "Preview" => " ", + "System Preferences" => " ", + + # chat + "Discord" => "󰙯 ", + "Mattermost" => " ", + "Slack" => " ", + + # creativity + "Affinity Designer" => "󰃣 ", + "Affinity Photo" => "󰃣 ", + "Affinity Publisher" => "󰈙 ", + "Blender" => "󰂫 ", + "Final Cut" => " ", + "Garageband" => "󰋄 ", + "Logic Pro X" => "󰋄 ", + "iMovie" => " ", + + # password managers + "GPG Keychain" | "KeePassXC" | "LastPass" | "1Password" => "󰌋 ", + + # other + "Audible" => "󰋋 ", + "Pocket Casts" => " ", + "Setapp" => " ", + "Spotify" => " ", + "Steam" => " ", + + _ => "󰘔 ", +} + +(sketchybar + --set $env.NAME $"label=($env | get -i INFO | default '')" $"icon=($icon)" + icon.font="Symbols Nerd Font:2048-em:18.0" + label.font="Berkeley Mono:Bold:16.0" y_offset="3") diff --git a/home/apps/sketchybar/plugins/window_title.sh b/home/apps/sketchybar/plugins/window_title.sh deleted file mode 100755 index cbbc72b..0000000 --- a/home/apps/sketchybar/plugins/window_title.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env bash - -case "$INFO" in - # IDEs - "CLion") ;& - "GoLand") ;& - "PhpStorm") ;& - "PyCharm") ;& - "WebStorm") ;& - "Lapce") ;& - "Xcode") ICON=" ";; - "Neovide") ICON=" ";; - - # developer - "Docker") ICON=" ";; - - # terminals - "Kitty") ;& - "iTerm") ;& - "Terminal") ;& - "WezTerm") ICON=" ";; - - # browsers - "Chromium") ICON="󰊯 ";; - "Firefox") ICON=" ";; - "Safari") ICON="󰀹 ";; - "qutebrowser") ICON=" ";; - - # system - "App Store") ICON=" ";; - "Books") ICON=" ";; - "Finder") ICON="󰀶 ";; - "Music") ICON="󰝚 ";; - "Podcasts") ICON=" ";; - "Photos") ICON=" ";; - "Preview") ICON=" ";; - "System Preferences") ICON=" ";; - - # chat - "Discord") ICON="󰙯 ";; - "Mattermost") ICON=" ";; - "Slack") ICON=" ";; - - # creativity - "Affinity Designer") ICON="󰃣 ";; - "Affinity Photo") ICON="󰃣 ";; - "Affinity Publisher") ICON="󰈙 ";; - "Blender") ICON="󰂫 ";; - "Final Cut") ICON=" ";; - "Garageband") ICON="󰋄 ";; - "Logic Pro X") ICON="󰋄 ";; - "iMovie") ICON=" ";; - - # password managers - "GPG Keychain") ;& - "KeePassXC") ;& - "LastPass") ;& - "1Password") ICON="󰌋 ";; - - # other - "Audible") ICON="󰋋 ";; - "Pocket Casts") ICON=" ";; - "Setapp") ICON=" ";; - "Spotify") ICON=" ";; - "Steam") ICON=" ";; - *) ICON="󰘔 ";; -esac - -sketchybar --set "$NAME" label="$INFO" icon="$ICON" diff --git a/home/apps/sketchybar/sketchybarrc b/home/apps/sketchybar/sketchybarrc index 3ab45ab..9841582 100755 --- a/home/apps/sketchybar/sketchybarrc +++ b/home/apps/sketchybar/sketchybarrc @@ -1,95 +1,94 @@ -#!/usr/bin/env bash +#!/usr/bin/env nu # vim:fileencoding=utf-8:foldmethod=marker -PLUGIN_DIR="$HOME"/.config/sketchybar/plugins +let pluginDir = $env.HOME | path join ".config/sketchybar/plugins" ## bar appearance {{{ -sketchybar --bar \ - height=32 \ - position=top \ - padding_left=5 \ - padding_right=5 \ - margin=5 \ - corner_radius=10 \ - border_width=2 \ - hidden=off \ - topmost=off \ - y_offset=2 +(sketchybar --bar + height=32 + position=top + padding_left=5 + padding_right=5 + margin=5 + corner_radius=10 + border_width=2 + hidden=off + topmost=off + y_offset=2) -# colors are managed separately in the colordummy, -# which listens to theme_changed events, -# to swap between Catppuccin Mocha and Latte +# colors are managed separately in the colordummy. +# listens to theme_changed events, to swap between dark and light mode sketchybar -m --add event theme_changed AppleInterfaceThemeChangedNotification -sketchybar -m --add event music_changed com.apple.Music.playerInfo -sketchybar \ - --add item colordummy center \ - --set colordummy \ - drawing=off \ - script="$PLUGIN_DIR/colordummy.sh" \ +(sketchybar + --add item colordummy center + --set colordummy + drawing=off + $"script=($pluginDir)/colordummy.nu" --subscribe colordummy theme_changed +) ##### Changing Defaults ##### -sketchybar --default \ - updates=when_shown \ - drawing=on \ - icon.font="Symbols Nerd Font:2048-em:18.0" \ - label.font="SF Pro:Regular:16.0" \ - label.padding_left=2 \ - label.padding_right=2 \ - icon.padding_left=2 \ +(sketchybar --default + updates=when_shown + drawing=on + icon.font="Symbols Nerd Font:2048-em:18.0" + label.font="SF Pro:Regular:16.0" + label.padding_left=2 + label.padding_right=2 + icon.padding_left=2 icon.padding_right=2 +) # }}} ## left side of the bar {{{ # spaces for yabai wm -SPACE_ICONS=( - "Ⅰ" - "Ⅱ" - "Ⅲ" - "Ⅳ" - "Ⅴ" - "Ⅵ" - "Ⅶ" - "Ⅷ" - "Ⅸ" - "Ⅹ" -) -for i in "${!SPACE_ICONS[@]}"; do - sketchybar \ - --add space "space.$i" left \ - --set "space.$i" associated_space=$((i + 1)) \ - icon="${SPACE_ICONS[i]}" \ - icon.padding_left=8 \ - icon.padding_right=8 \ - background.padding_left=1 \ - background.padding_right=1 \ - background.height=32 \ - label.drawing=off \ - script="$PLUGIN_DIR/space.sh" \ - click_script="yabai -m space --focus $((i + 1))" -done +for $el in ["Ⅰ" "Ⅱ" "Ⅲ" "Ⅳ" "Ⅴ" "Ⅵ" "Ⅶ" "Ⅷ" "Ⅸ" "Ⅹ"] --numbered { + let i = $el.index + 1 -sketchybar \ - --add item music left \ - --set music \ - script="$PLUGIN_DIR/music.sh" \ - label.y_offset=-1 \ - --subscribe music music_changed \ - --add item clock right \ - --set clock \ - script="$PLUGIN_DIR/clock.sh" \ - update_freq=10 \ - background.padding_right=4 \ - --add alias "iStat Menus Status" right \ - icon.padding_left=0 \ - icon.padding_right=0 \ - --add alias "Little Snitch Agent" right \ - icon.padding_left=0 \ - icon.padding_right=0 \ - --add alias "Control Centre,Battery" right \ - icon.padding_left=0 \ - icon.padding_right=0 \ - --add alias "Mullvad VPN" right \ - icon.padding_left=0 \ + (sketchybar + --add space $"space.($i)" left + --set $"space.($i)" $"associated_space=($i)" + $"icon=($el.item)" + icon.padding_left=8 + icon.padding_right=8 + background.padding_left=1 + background.padding_right=1 + background.height=32 + label.drawing=off + $"script=($pluginDir)/space.nu" + $"click_script=yabai -m space --focus ($i)") +} + +sketchybar -m --add event music_changed com.apple.Music.playerInfo + +(sketchybar + --add item window_title left + --set window_title + $"script=($pluginDir)/window_title.nu" + label.y_offset=-1 + icon.y_offset=-1 + --subscribe window_title front_app_switched + --add item music left + --set music + $"script=($pluginDir)/music.nu" + label.y_offset=-1 + --subscribe music music_changed + --add item clock right + --set clock + $"script=($pluginDir)/clock.nu" + update_freq=10 + background.padding_right=4 + --add alias "iStat Menus Status" right + icon.padding_left=0 icon.padding_right=0 + --add alias "Little Snitch Agent" right + icon.padding_left=0 + icon.padding_right=0 + --add alias "Control Centre,Battery" right + icon.padding_left=0 + icon.padding_right=0 + --add alias "Mullvad VPN" right + icon.padding_left=0 + icon.padding_right=0 +) sketchybar --update diff --git a/home/default.nix b/home/default.nix index 157470a..64ad222 100644 --- a/home/default.nix +++ b/home/default.nix @@ -1,5 +1,6 @@ { config, + flakePath, lib, pkgs, ... @@ -52,6 +53,10 @@ in }; home.mac-wallpaper = ./wallpapers/dhm_1610.png; + xdg.configFile.sketchybar = { + recursive = true; + source = config.lib.file.mkOutOfStoreSymlink "${flakePath}/home/apps/sketchybar"; + }; programs = { home-manager.enable = true; diff --git a/machines/common/darwin/default.nix b/machines/common/darwin/default.nix index 7e4b8fc..dd8d4f9 100644 --- a/machines/common/darwin/default.nix +++ b/machines/common/darwin/default.nix @@ -15,6 +15,10 @@ nix.linux-builder.enable = true; services = { + sketchybar = { + enable = true; + extraPackages = with pkgs; [ nushell ]; + }; yabai = { enable = true; enableScriptingAddition = true;