From b6a6d067c2431c83d77b89fad1d61ee82bf63803 Mon Sep 17 00:00:00 2001 From: winston Date: Fri, 24 Feb 2023 22:02:18 +0100 Subject: [PATCH] feat(darwin): sketchybar re-init --- home/apps/sketchybar.nix | 25 +++++++++-- home/apps/sketchybar/plugins/colordummy.sh | 26 +++++++---- home/apps/sketchybar/plugins/music.sh | 28 +++++------- home/apps/sketchybar/sketchybarrc | 15 +++++-- home/default.nix | 2 + machines/sashimi/wm.nix | 52 ++++++++++------------ 6 files changed, 87 insertions(+), 61 deletions(-) diff --git a/home/apps/sketchybar.nix b/home/apps/sketchybar.nix index 0215222..05934ce 100644 --- a/home/apps/sketchybar.nix +++ b/home/apps/sketchybar.nix @@ -1,26 +1,43 @@ { config, + flakePath, lib, + pkgs, ... -}: { +}: let + inherit (pkgs.stdenv.hostPlatform) isDarwin; + sketchybarPkg = pkgs.unstable.sketchybar; +in { home = lib.mkIf isDarwin { - packages = [pkgs.unstable.sketchybar]; + packages = [sketchybarPkg]; }; launchd = lib.mkIf isDarwin { agents.sketchybar = { enable = true; config = { - ProgramArguments = ["${lib.getExe pkgs.unstable.sketchybar}"]; + ProgramArguments = ["${lib.getExe sketchybarPkg}"]; KeepAlive = true; RunAtLoad = true; ProcessType = "Interactive"; Nice = -20; + StandardErrorPath = "${config.xdg.cacheHome}/sketchybar.log"; + StandardOutPath = "${config.xdg.cacheHome}/sketchybar.log"; + EnvironmentVariables = { + LANG = "en_US.UTF-8"; + PATH = "${lib.makeBinPath [ + sketchybarPkg + pkgs.bash + pkgs.bc + pkgs.coreutils + pkgs.unstable.yabai + ]}:/usr/bin"; + }; }; }; }; xdg.configFile = lib.mkIf isDarwin { "sketchybar" = { - source = config.lib.file.mkOutOfStoreSymlink ./sketchybar; + source = config.lib.file.mkOutOfStoreSymlink "${flakePath}/home/apps/sketchybar"; recursive = true; }; }; diff --git a/home/apps/sketchybar/plugins/colordummy.sh b/home/apps/sketchybar/plugins/colordummy.sh index d218661..ffbecbf 100755 --- a/home/apps/sketchybar/plugins/colordummy.sh +++ b/home/apps/sketchybar/plugins/colordummy.sh @@ -1,5 +1,7 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash # vim:fdm=marker +# dont' warn about unused variables: +# shellcheck disable=SC2034 # color definitions {{{ # mocha {{{ @@ -123,7 +125,7 @@ LIGHT_THEME="latte" DARK_THEME="mocha" # check whether or not macOS is in dark mode -if [[ $(defaults read -g AppleInterfaceStyle) != 'Dark' ]]; then +if [[ $(defaults read -g AppleInterfaceStyle 2>/dev/null) != 'Dark' ]]; then theme=$LIGHT_THEME else theme=$DARK_THEME @@ -133,7 +135,7 @@ function color() { alpha=${2:-1} color="$1" - printf -v parsed "%.0f" "$(bc -l <<< "255*${alpha}")" + printf -v parsed "%.0f" "$(bc -l <<<"255*${alpha}")" printf -v alpha "%02x" "$parsed" selected_color="${theme}_${color}" echo "0x${alpha}${!selected_color}" @@ -141,22 +143,28 @@ function color() { sketchybar \ --bar \ - color="$(color crust)" \ + 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 clock \ + --set music \ icon.color="$(color pink)" \ label.color="$(color pink)" \ --set "Mullvad VPN" \ - alias.color="$(color pink)" \ - --set "Little Snitch Agent" \ - alias.color="$(color pink)" \ + alias.color="$(color peach)" \ --set "Control Centre,Battery" \ - alias.color="$(color pink)" + 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 colours as well yabai -m config active_window_border_color "$(color pink)" diff --git a/home/apps/sketchybar/plugins/music.sh b/home/apps/sketchybar/plugins/music.sh index 1dcc961..92437c5 100755 --- a/home/apps/sketchybar/plugins/music.sh +++ b/home/apps/sketchybar/plugins/music.sh @@ -1,27 +1,23 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash if pgrep -xq Music; then - STATE=$(osascript -e 'tell application "Music" to player state as string' 2>/dev/null || echo "") - TRACK=$(osascript -e 'tell application "Music" to name of current track as string' 2>/dev/null || echo "") - ARTIST=$(osascript -e 'tell application "Music" to album artist of current track as string' 2>/dev/null || echo "") + 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 [ "$ARTIST" = "" ] || [ "$ARTIST" = "Various Artists" ]; then - ARTIST=$(osascript -e 'tell application "Music" to artist of current track as string' 2>/dev/null || echo "") + 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 - ICON="" + if [[ "$STATE" = "playing" ]]; then LABEL="$ARTIST - $TRACK" else - ICON="" - if [ "$TRACK" = "" ] || [ "$ARTIST" = "" ]; then - LABEL="paused" - else - LABEL="$ARTIST - $TRACK" - fi + LABEL="" fi - sketchybar --set "$NAME" icon="$ICON" label="$LABEL" --add event "${NAME}-changed" + 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" icon="" label="" --add event "${NAME}-changed" + sketchybar --set "$NAME" label="" fi diff --git a/home/apps/sketchybar/sketchybarrc b/home/apps/sketchybar/sketchybarrc index 6305535..3ab45ab 100755 --- a/home/apps/sketchybar/sketchybarrc +++ b/home/apps/sketchybar/sketchybarrc @@ -6,15 +6,20 @@ PLUGIN_DIR="$HOME"/.config/sketchybar/plugins sketchybar --bar \ height=32 \ position=top \ - padding_left=0 \ - padding_right=0 \ + padding_left=5 \ + padding_right=5 \ + margin=5 \ + corner_radius=10 \ + border_width=2 \ hidden=off \ - topmost=on + 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 sketchybar -m --add event theme_changed AppleInterfaceThemeChangedNotification +sketchybar -m --add event music_changed com.apple.Music.playerInfo sketchybar \ --add item colordummy center \ --set colordummy \ @@ -64,9 +69,11 @@ for i in "${!SPACE_ICONS[@]}"; do done sketchybar \ - --add item music center \ + --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" \ diff --git a/home/default.nix b/home/default.nix index 25577a3..8d5e460 100644 --- a/home/default.nix +++ b/home/default.nix @@ -20,6 +20,7 @@ in { ./apps/neovim.nix ./apps/newsboat.nix ./apps/rice.nix + ./apps/sketchybar.nix ./apps/vscode.nix ./apps/wezterm.nix ./apps/zsh.nix @@ -49,6 +50,7 @@ in { nur.repos.nekowinston.org-stats (nerdfonts.override {fonts = ["NerdFontsSymbolsOnly"];}) + victor-mono unstable.wezterm ] ++ lib.optionals isLinux [ diff --git a/machines/sashimi/wm.nix b/machines/sashimi/wm.nix index 43b1d66..c4881d0 100644 --- a/machines/sashimi/wm.nix +++ b/machines/sashimi/wm.nix @@ -6,7 +6,31 @@ }: { services.yabai = { enable = true; + enableScriptingAddition = true; package = pkgs.unstable.yabai; + config = { + auto_balance = "off"; + focus_follows_mouse = "off"; + layout = "bsp"; + mouse_drop_action = "swap"; + mouse_follows_focus = "off"; + mouse_modifier = "off"; + window_animation_duration = "0.1"; + window_border = "on"; + window_border_blur = "on"; + window_border_width = "2"; + window_gap = "5"; + left_padding = "5"; + right_padding = "5"; + top_padding = "5"; + bottom_padding = "5"; + window_origin_display = "default"; + window_placement = "second_child"; + window_shadow = "float"; + active_window_border_color = "0xfff5c2e7"; + normal_window_border_color = "0xffcba6f7"; + external_bar = "all:32:0"; + }; extraConfig = let rule = "yabai -m rule --add"; ignored = app: builtins.concatStringsSep "\n" (map (e: ''${rule} app="${e}" manage=off sticky=off layer=above border=off'') app); @@ -23,26 +47,6 @@ ${rule} manage=off border=off app="CleanShot" ${rule} manage=off sticky=on app="OBS Studio" ''; - config = { - auto_balance = "off"; - focus_follows_mouse = "off"; - layout = "bsp"; - mouse_drop_action = "swap"; - mouse_follows_focus = "off"; - mouse_modifier = "off"; - window_animation_duration = "0.1"; - window_border = "on"; - window_border_blur = "on"; - window_border_width = "2"; - # this actually looks like hot trash - # window_border_radius = "0"; - window_gap = "0"; - window_origin_display = "default"; - window_placement = "second_child"; - window_shadow = "float"; - active_window_border_color = "0xfff5c2e7"; - normal_window_border_color = "0xffcba6f7"; - }; }; services.skhd = { @@ -56,19 +60,11 @@ cmd + ctrl - j : ${yabai} -m window --focus south cmd + ctrl - k : ${yabai} -m window --focus north cmd + ctrl - l : ${yabai} -m window --focus east - cmd + ctrl - left : ${yabai} -m window --focus west - cmd + ctrl - down : ${yabai} -m window --focus south - cmd + ctrl - up : ${yabai} -m window --focus north - cmd + ctrl - right : ${yabai} -m window --focus east # move window cmd + shift - h : ${yabai} -m window --warp west cmd + shift - j : ${yabai} -m window --warp south cmd + shift - k : ${yabai} -m window --warp north cmd + shift - l : ${yabai} -m window --warp east - cmd + shift - left : ${yabai} -m window --warp west - cmd + shift - down : ${yabai} -m window --warp south - cmd + shift - up : ${yabai} -m window --warp north - cmd + shift - right : ${yabai} -m window --warp east # toggle sticky/floating cmd + shift - s: ${yabai} -m window --toggle sticky --toggle float --toggle topmost cmd + shift - d: ${yabai} -m window --toggle float