From 89d280b7af272457fc599a626b389de2e8c9584a Mon Sep 17 00:00:00 2001 From: reo101 Date: Sat, 29 Jul 2023 17:45:58 +0300 Subject: [PATCH] feat(darwin): add `sketchybar` to `yabai` module --- modules/nix-darwin/yabai/default.nix | 22 ++- .../nix-darwin/yabai/sketchybar/default.nix | 164 ++++++++++++++++++ .../yabai/sketchybar/plugins/battery.sh | 34 ++++ .../yabai/sketchybar/plugins/clock.sh | 8 + .../yabai/sketchybar/plugins/front_app.sh | 8 + .../yabai/sketchybar/plugins/space.sh | 23 +++ .../yabai/sketchybar/plugins/theme.sh | 1 + .../yabai/sketchybar/plugins/volume.sh | 18 ++ .../yabai/sketchybar/plugins/wifi.sh | 8 + modules/nix-darwin/yabai/yabairc | 11 +- 10 files changed, 288 insertions(+), 9 deletions(-) create mode 100755 modules/nix-darwin/yabai/sketchybar/default.nix create mode 100755 modules/nix-darwin/yabai/sketchybar/plugins/battery.sh create mode 100755 modules/nix-darwin/yabai/sketchybar/plugins/clock.sh create mode 100755 modules/nix-darwin/yabai/sketchybar/plugins/front_app.sh create mode 100755 modules/nix-darwin/yabai/sketchybar/plugins/space.sh create mode 100755 modules/nix-darwin/yabai/sketchybar/plugins/theme.sh create mode 100755 modules/nix-darwin/yabai/sketchybar/plugins/volume.sh create mode 100755 modules/nix-darwin/yabai/sketchybar/plugins/wifi.sh diff --git a/modules/nix-darwin/yabai/default.nix b/modules/nix-darwin/yabai/default.nix index 0a66b81..a8480f4 100644 --- a/modules/nix-darwin/yabai/default.nix +++ b/modules/nix-darwin/yabai/default.nix @@ -29,10 +29,24 @@ in skhdConfig = (builtins.readFile ./skhdrc); }; - # sketchybar = { - # enable = true; - # package = pkgs.sketchybar; - # }; + sketchybar = { + enable = true; + package = pkgs.sketchybar; + extraPackages = with pkgs; [ + jq + ]; + config = import ./sketchybar; + }; + }; + + # For sketchybar + homebrew = { + taps = [ + "shaunsingh/SFMono-Nerd-Font-Ligaturized" + ]; + casks = [ + "font-sf-mono-nerd-font-ligaturized" + ]; }; }; diff --git a/modules/nix-darwin/yabai/sketchybar/default.nix b/modules/nix-darwin/yabai/sketchybar/default.nix new file mode 100755 index 0000000..346b15d --- /dev/null +++ b/modules/nix-darwin/yabai/sketchybar/default.nix @@ -0,0 +1,164 @@ +let + plugin_dir = ./plugins; +in +'' +PLUGIN_DIR="${plugin_dir}" + +##### Bar Appearance ##### +BACKGROUND_COLOR="0x502a2d3d" + +appearance=''$''\(defaults read -g AppleInterfaceStyle''\) + +if [[ ''$''\{appearance''\} != 'Dark' ]]; then + BACKGROUND_COLOR="0x50f5f0f5" +fi + +sketchybar --bar height="32" \ + blur_radius="25" \ + position="top" \ + sticky="on" \ + margin="10" \ + color="0x002a2d3d" \ + notch_offset="5" \ + corner_radius="12" \ + border_color="0x80c4a7e7" \ + border_width="0" + +##### Changing Defaults ##### +# We now change some default values that are applied to all further items +# For a full list of all available item properties see: +# https://felixkratz.github.io/SketchyBar/config/items + +sketchybar --default updates="when_shown" \ + icon.font="SF Pro Rounded:Bold:14.0" \ + icon.color="0xffc6ceef" \ + label.font="SF Pro Rounded:Bold:14.0" \ + label.color="0xffc6ceef" \ + padding_left="3" \ + padding_right="3" \ + label.padding_left="4" \ + label.padding_right="4" \ + icon.padding_left="4" \ + icon.padding_right="4" + +##### Adding Mission Control Space Indicators ##### +# Now we 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" "11" "12" "13" "14" "15" "16") + +for i in "''$''\{!SPACE_ICONS[@]''\}"; do + sid=$(($i+1)) + sketchybar --add space space.''$''\{sid''\} left \ + --set space.''$''\{sid''\} associated_space="''$''\{sid''\}" \ + icon="''$''\{SPACE_ICONS[i]''\}" \ + background.color="0x44ffffff" \ + background.corner_radius="7" \ + background.height="20" \ + background.drawing="on" \ + background.border_color="0x952a2d3d" \ + background.border_width="1" \ + label.drawing="off" \ + script="''$''\{PLUGIN_DIR''\}/space.sh" \ + click_script="yabai -m space --focus ''$''\{sid''\}" +done + +##### Adding Left Items ##### +# We add some regular items to the left side of the bar +# only the properties deviating from the current defaults need to be set + +sketchybar --add item space_separator left \ + --set space_separator icon="λ" \ + icon.color="0xffff946f" \ + padding_left="10" \ + padding_right="10" \ + label.drawing="off" \ + \ + --add item front_app left \ + --set front_app script="''$''\{PLUGIN_DIR''\}/front_app.sh" \ + icon.drawing="off" \ + background.color="''$''\{BACKGROUND_COLOR''\}" \ + background.corner_radius="7" \ + blur_radius="30" \ + background.border_color="0x80c4a7e7" \ + background.border_width="1" \ + --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 test right \ + --set test script="''$''\{PLUGIN_DIR''\}/theme.sh" \ + icon="􀝦" \ + background.height="30" \ + background.color="''$''\{BACKGROUND_COLOR''\}" \ + background.corner_radius="7" \ + icon.padding_left="10" \ + icon.padding_right="13" \ + blur_radius="30" \ + background.border_color="0x80c4a7e7" \ + background.border_width="1" \ + label.drawing="off" \ + click_script="~/.dotfiles/macos/wallpapers.zsh" \ + --add item clock right i \ + --set clock update_freq="10" \ + icon="􀐬" \ + background.color="''$''\{BACKGROUND_COLOR''\}" \ + background.corner_radius="7" \ + icon.padding_left="10" \ + label.padding_right="10" \ + blur_radius="30" \ + background.border_color="0x80c4a7e7" \ + background.border_width="1" \ + script="''$''\{PLUGIN_DIR''\}/clock.sh" \ + \ + --add item wifi right \ + --set wifi script="''$''\{PLUGIN_DIR''\}/wifi.sh" \ + icon="􀙇" \ + background.color="''$''\{BACKGROUND_COLOR''\}" \ + background.corner_radius="7" \ + icon.padding_left="10" \ + label.padding_right="10" \ + blur_radius="30" \ + background.border_color="0x80c4a7e7" \ + background.border_width="1" \ + --subscribe wifi wifi_change \ + \ + --add item volume right \ + --set volume script="''$''\{PLUGIN_DIR''\}/volume.sh" \ + background.color="''$''\{BACKGROUND_COLOR''\}" \ + background.corner_radius="7" \ + icon.padding_left="10" \ + label.padding_right="10" \ + blur_radius="30" \ + background.border_color="0x80c4a7e7" \ + background.border_width="1" \ + --subscribe volume volume_change \ + \ + --add item battery right \ + --set battery script="''$''\{PLUGIN_DIR''\}/battery.sh" \ + update_freq="120" \ + background.color="''$''\{BACKGROUND_COLOR''\}" \ + background.corner_radius="7" \ + icon.padding_left="10" \ + label.padding_right="10" \ + blur_radius="30" \ + background.border_color="0x80c4a7e7" \ + background.border_width="1" \ + --subscribe battery system_woke power_source_change \ + +##### Finalizing Setup ##### +# The below command is only needed at the end of the initial configuration to +# force all scripts to run the first time, it should never be run in an item script. + +sketchybar --update +'' diff --git a/modules/nix-darwin/yabai/sketchybar/plugins/battery.sh b/modules/nix-darwin/yabai/sketchybar/plugins/battery.sh new file mode 100755 index 0000000..5c729eb --- /dev/null +++ b/modules/nix-darwin/yabai/sketchybar/plugins/battery.sh @@ -0,0 +1,34 @@ +#!/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/modules/nix-darwin/yabai/sketchybar/plugins/clock.sh b/modules/nix-darwin/yabai/sketchybar/plugins/clock.sh new file mode 100755 index 0000000..54529f0 --- /dev/null +++ b/modules/nix-darwin/yabai/sketchybar/plugins/clock.sh @@ -0,0 +1,8 @@ +#!/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 '+%d/%m %H:%M')" + diff --git a/modules/nix-darwin/yabai/sketchybar/plugins/front_app.sh b/modules/nix-darwin/yabai/sketchybar/plugins/front_app.sh new file mode 100755 index 0000000..0525dd0 --- /dev/null +++ b/modules/nix-darwin/yabai/sketchybar/plugins/front_app.sh @@ -0,0 +1,8 @@ +#!/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 + +sketchybar --set ${NAME} label="${INFO}" diff --git a/modules/nix-darwin/yabai/sketchybar/plugins/space.sh b/modules/nix-darwin/yabai/sketchybar/plugins/space.sh new file mode 100755 index 0000000..05aa204 --- /dev/null +++ b/modules/nix-darwin/yabai/sketchybar/plugins/space.sh @@ -0,0 +1,23 @@ +#!/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 + +BACKGROUND_COLOR=0x502a2d3d +HIGHLIGHT_COLOR=0x90faafa6 + +appearance=$(defaults read -g AppleInterfaceStyle) + +if [[ ${appearance} != 'Dark' ]]; then + BACKGROUND_COLOR=0x50f5f0f5 +fi + + + +if [ "${SELECTED}" == "true" ]; then + sketchybar --set ${NAME} background.color=${HIGHLIGHT_COLOR} +else + sketchybar --set ${NAME} background.color=${BACKGROUND_COLOR} \ + blur_radius=30 +fi diff --git a/modules/nix-darwin/yabai/sketchybar/plugins/theme.sh b/modules/nix-darwin/yabai/sketchybar/plugins/theme.sh new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/modules/nix-darwin/yabai/sketchybar/plugins/theme.sh @@ -0,0 +1 @@ +#!/bin/sh diff --git a/modules/nix-darwin/yabai/sketchybar/plugins/volume.sh b/modules/nix-darwin/yabai/sketchybar/plugins/volume.sh new file mode 100755 index 0000000..fc6f102 --- /dev/null +++ b/modules/nix-darwin/yabai/sketchybar/plugins/volume.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# The volume_change event supplies a ${INFO} variable in which the current volume +# percentage is passed to the script. + +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}%" diff --git a/modules/nix-darwin/yabai/sketchybar/plugins/wifi.sh b/modules/nix-darwin/yabai/sketchybar/plugins/wifi.sh new file mode 100755 index 0000000..360533f --- /dev/null +++ b/modules/nix-darwin/yabai/sketchybar/plugins/wifi.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# The wifi_change event supplies a ${INFO} variable in which the current SSID +# is passed to the script. + +WIFI=${INFO:-"Not Connected"} + +sketchybar --set ${NAME} label="${WIFI}" diff --git a/modules/nix-darwin/yabai/yabairc b/modules/nix-darwin/yabai/yabairc index dabaa66..a91b044 100644 --- a/modules/nix-darwin/yabai/yabairc +++ b/modules/nix-darwin/yabai/yabairc @@ -6,8 +6,8 @@ launchctl unload -F /System/Library/LaunchAgents/com.apple.WindowManager.plist > sudo yabai --load-sa yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa" yabai -m signal --add event=window_focused action="sketchybar --trigger window_focus" -yabai -m signal --add event=display_added action="sleep 2 && ${HOME}/.config/yabai/create_spaces.sh" -yabai -m signal --add event=display_removed action="sleep 1 && ${HOME}/.config/yabai/create_spaces.sh" +# yabai -m signal --add event=display_added action="sleep 2 && ${HOME}/.config/yabai/create_spaces.sh" +# yabai -m signal --add event=display_removed action="sleep 1 && ${HOME}/.config/yabai/create_spaces.sh" yabai -m signal --add event=window_created action="sketchybar --trigger windows_on_spaces" yabai -m signal --add event=window_destroyed action="sketchybar --trigger windows_on_spaces" yabai -m signal --add event=window_destroyed action="yabai -m query --windows --window &> /dev/null || yabai -m window --focus mouse" @@ -16,7 +16,7 @@ yabai -m signal --add event=application_terminated action="yabai -m query --wind # { # DESIRED_SPACES_PER_DISPLAY=4 # CURRENT_SPACES="$(yabai -m query --displays | jq -r '.[].spaces | @sh')" -# +# # DELTA=0 # while read -r line # do @@ -37,7 +37,7 @@ yabai -m signal --add event=application_terminated action="yabai -m query --wind # fi # DELTA=$((${DELTA}+${MISSING_SPACES})) # done <<< "${CURRENT_SPACES}" -# +# # sketchybar --trigger space_change --trigger windows_on_spaces # } @@ -53,6 +53,7 @@ yabai -m config "external_bar" "all:49:0" \ "window_opacity_duration" "0.15" \ "active_window_opacity" "1.0" \ "normal_window_opacity" "0.95" \ + "window_border_blur" "off" \ "window_border_width" "2" \ "window_border_hidpi" "off" \ "window_border_radius" "11" \ @@ -77,7 +78,7 @@ yabai -m config "external_bar" "all:49:0" \ yabai -m rule --add app="^(LuLu|Vimac|Calculator|Software Update|Dictionary|VLC|System Preferences|System Settings|zoom.us|Photo Booth|Archive Utility|Python|LibreOffice|App Store|Steam|Alfred|Activity Monitor)$" manage=off yabai -m rule --add label="Finder" app="^Finder$" title="(Co(py|nnect)|Move|Info|Pref)" manage=off yabai -m rule --add label="Safari" app="^Safari$" title="^(General|(Tab|Password|Website|Extension)s|AutoFill|Se(arch|curity)|Privacy|Advance)$" manage=off -yabai -m rule --add label="About This Mac" app="System Information" title="About This Mac" manage=off +yabai -m rule --add label="System Information" app="System Information" title="System Information" manage=off yabai -m rule --add label="Select file to save to" app="^Inkscape$" title="Select file to save to" manage=off yabai -m config layout bsp