From 7759bd2b36687221a08f4f0af48af2e478131db0 Mon Sep 17 00:00:00 2001 From: Random936 Date: Sat, 2 Nov 2024 12:45:42 -0700 Subject: [PATCH] Added sketchybar to darwin config --- config/darwin.nix | 15 ++- dotfiles/.aerospace.toml | 39 +++++--- .../.config/sketchybar/plugins/aerospace.sh | 10 ++ .../.config/sketchybar/plugins/battery.sh | 28 ++++++ dotfiles/.config/sketchybar/plugins/clock.sh | 8 ++ .../.config/sketchybar/plugins/front_app.sh | 10 ++ dotfiles/.config/sketchybar/plugins/space.sh | 7 ++ dotfiles/.config/sketchybar/plugins/volume.sh | 20 ++++ dotfiles/.config/sketchybar/sketchybarrc | 93 +++++++++++++++++++ home/modules/sketchybar.nix | 10 ++ 10 files changed, 227 insertions(+), 13 deletions(-) create mode 100755 dotfiles/.config/sketchybar/plugins/aerospace.sh create mode 100755 dotfiles/.config/sketchybar/plugins/battery.sh create mode 100755 dotfiles/.config/sketchybar/plugins/clock.sh create mode 100755 dotfiles/.config/sketchybar/plugins/front_app.sh create mode 100755 dotfiles/.config/sketchybar/plugins/space.sh create mode 100755 dotfiles/.config/sketchybar/plugins/volume.sh create mode 100755 dotfiles/.config/sketchybar/sketchybarrc create mode 100644 home/modules/sketchybar.nix diff --git a/config/darwin.nix b/config/darwin.nix index 1af6978..814c860 100644 --- a/config/darwin.nix +++ b/config/darwin.nix @@ -14,14 +14,17 @@ onActivation.cleanup = "zap"; taps = [ "nikitabobko/tap" + "FelixKratz/formulae" ]; brews = [ "wireguard-tools" "bitwarden-cli" + "sketchybar" "coreutils" "watch" ]; casks = [ + "font-hack-nerd-font" "scroll-reverser" "google-chrome" "instantview" @@ -52,8 +55,16 @@ }; # MacOS Changes - system.defaults.dock.autohide = true; - system.startup.chime = false; + system = { + startup.chime = false; + defaults = { + dock.autohide = true; + NSGlobalDomain = { + "com.apple.mouse.tapBehavior" = 1; + _HIHideMenuBar = true; + }; + }; + }; # Create /etc/zshrc that loads the nix-darwin environment. programs.zsh.enable = true; diff --git a/dotfiles/.aerospace.toml b/dotfiles/.aerospace.toml index 07a7ab1..d0fe097 100644 --- a/dotfiles/.aerospace.toml +++ b/dotfiles/.aerospace.toml @@ -1,18 +1,36 @@ -# Reference: https://github.com/i3/i3/blob/next/etc/config -# i3 doesn't have "normalizations" feature that why we disable them here. -# But the feature is very helpful. -# Normalizations eliminate all sorts of weird tree configurations that don't make sense. -# Give normalizations a chance and enable them back. +start-at-login = true +# Mouse follows focus when focused monitor changes +on-focused-monitor-changed = ['move-mouse monitor-lazy-center'] + +# Sketchybar Integration +after-startup-command = ['exec-and-forget sketchybar'] + +# Notify Sketchybar about workspace change +exec-on-workspace-change = [ +'/bin/bash', '-c', +'sketchybar --trigger aerospace_workspace_change FOCUSED_WORKSPACE=$AEROSPACE_FOCUSED_WORKSPACE' +] + +on-focus-changed = [ +'exec-and-forget sketchybar --trigger front_app_switched', +'exec-and-forget --trigger update_windows' +] + enable-normalization-flatten-containers = false enable-normalization-opposite-orientation-for-nested-containers = false -# Mouse follows focus when focused monitor changes -on-focused-monitor-changed = ['move-mouse monitor-lazy-center'] +[gaps] +inner.horizontal = 5 +inner.vertical = 5 +outer.top = 45 +outer.left = 5 +outer.bottom = 5 +outer.right = 5 [mode.main.binding] # See: https://nikitabobko.github.io/AeroSpace/goodness#open-a-new-window-with-applescript cmd-enter = '''exec-and-forget osascript -e 'tell application "iTerm2" to create window with default profile'''' -cmd-shift-e = 'exec-and-forget emacs' +cmd-shift-e = 'exec-and-forget open -n -a "Emacs"' cmd-shift-f = 'exec-and-forget open -n -a "Google Chrome"' cmd-shift-d = 'exec-and-forget open -n -a "Discord"' @@ -29,10 +47,9 @@ cmd-shift-l = 'move right' cmd-f = 'fullscreen' cmd-s = 'layout v_accordion' # 'layout stacking' in i3 -cmd-w = 'layout h_accordion' # 'layout tabbed' in i3 cmd-e = 'layout tiles horizontal vertical' # 'layout toggle split' in i3 - cmd-q = 'close' +cmd-semicolon = 'split horizontal' # split in horizontal orientation cmd-shift-space = 'layout floating tiling' # 'floating toggle' in i3 @@ -76,4 +93,4 @@ j = 'resize height +50' k = 'resize height -50' l = 'resize width +50' enter = 'mode main' -esc = 'mode main' \ No newline at end of file +esc = 'mode main' diff --git a/dotfiles/.config/sketchybar/plugins/aerospace.sh b/dotfiles/.config/sketchybar/plugins/aerospace.sh new file mode 100755 index 0000000..6114c3d --- /dev/null +++ b/dotfiles/.config/sketchybar/plugins/aerospace.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# make sure it's executable with: +# chmod +x ~/.config/sketchybar/plugins/aerospace.sh + +if [ "$1" = "$FOCUSED_WORKSPACE" ]; then + sketchybar --set $NAME background.drawing=on +else + sketchybar --set $NAME background.drawing=off +fi diff --git a/dotfiles/.config/sketchybar/plugins/battery.sh b/dotfiles/.config/sketchybar/plugins/battery.sh new file mode 100755 index 0000000..9dd9627 --- /dev/null +++ b/dotfiles/.config/sketchybar/plugins/battery.sh @@ -0,0 +1,28 @@ +#!/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/dotfiles/.config/sketchybar/plugins/clock.sh b/dotfiles/.config/sketchybar/plugins/clock.sh new file mode 100755 index 0000000..ea41b2d --- /dev/null +++ b/dotfiles/.config/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 '+%m/%d/%Y %H:%M')" + diff --git a/dotfiles/.config/sketchybar/plugins/front_app.sh b/dotfiles/.config/sketchybar/plugins/front_app.sh new file mode 100755 index 0000000..fb6d0b3 --- /dev/null +++ b/dotfiles/.config/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/dotfiles/.config/sketchybar/plugins/space.sh b/dotfiles/.config/sketchybar/plugins/space.sh new file mode 100755 index 0000000..b8602b5 --- /dev/null +++ b/dotfiles/.config/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/dotfiles/.config/sketchybar/plugins/volume.sh b/dotfiles/.config/sketchybar/plugins/volume.sh new file mode 100755 index 0000000..6e69a5d --- /dev/null +++ b/dotfiles/.config/sketchybar/plugins/volume.sh @@ -0,0 +1,20 @@ +#!/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" + + 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%" +fi diff --git a/dotfiles/.config/sketchybar/sketchybarrc b/dotfiles/.config/sketchybar/sketchybarrc new file mode 100755 index 0000000..4eb6d7e --- /dev/null +++ b/dotfiles/.config/sketchybar/sketchybarrc @@ -0,0 +1,93 @@ +# 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 + +bar=( + position=top + height=40 + blur_radius=30 + color=0x40000000 + sticky=on + topmost-window +) + +sketchybar --bar "${bar[@]}" + +##### 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="Hack Nerd Font:Bold:17.0" + label.font="Hack Nerd Font:Bold:14.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[@]}" + +##### Aerospace Workspace Integration ##### +sketchybar --add event aerospace_workspace_change + +for sid in $(aerospace list-workspaces --all); do + sketchybar --add item space.$sid left \ + --subscribe space.$sid aerospace_workspace_change \ + --set space.$sid \ + background.color=0x44ffffff \ + background.corner_radius=5 \ + background.height=25 \ + background.drawing=off \ + label="$sid" \ + click_script="aerospace workspace $sid" \ + script="$CONFIG_DIR/plugins/aerospace.sh $sid" +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 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 icon= script="$PLUGIN_DIR/clock.sh" \ + --add item volume right \ + --set volume script="$PLUGIN_DIR/volume.sh" \ + --subscribe volume volume_change \ + --add item battery right \ + --set battery update_freq=120 script="$PLUGIN_DIR/battery.sh" \ + --subscribe battery system_woke power_source_change + +##### Force all scripts to run the first time (never do this in a script) ##### +sketchybar --update + diff --git a/home/modules/sketchybar.nix b/home/modules/sketchybar.nix new file mode 100644 index 0000000..6fed615 --- /dev/null +++ b/home/modules/sketchybar.nix @@ -0,0 +1,10 @@ +{ ... }: { + home.file."../../dotfiles/.config/sketchybar/plugins".source = ../../dotfiles/.config/sketchybar/plugins; + home.file."../../dotfiles/.config/sketchybar/plugins/volume.sh".source = ../../dotfiles/.config/sketchybar/plugins/volume.sh; + home.file."../../dotfiles/.config/sketchybar/plugins/space.sh".source = ../../dotfiles/.config/sketchybar/plugins/space.sh; + home.file."../../dotfiles/.config/sketchybar/plugins/front_app.sh".source = ../../dotfiles/.config/sketchybar/plugins/front_app.sh; + home.file."../../dotfiles/.config/sketchybar/plugins/aerospace.sh".source = ../../dotfiles/.config/sketchybar/plugins/aerospace.sh; + home.file."../../dotfiles/.config/sketchybar/plugins/clock.sh".source = ../../dotfiles/.config/sketchybar/plugins/clock.sh; + home.file."../../dotfiles/.config/sketchybar/plugins/battery.sh".source = ../../dotfiles/.config/sketchybar/plugins/battery.sh; + home.file."../../dotfiles/.config/sketchybar/sketchybarrc".source = ../../dotfiles/.config/sketchybar/sketchybarrc; +}