feat(darwin): sketchybar re-init

This commit is contained in:
winston 2023-02-24 22:02:18 +01:00
parent 90c6b50efb
commit b6a6d067c2
Signed by: winston
GPG key ID: 3786770EDBC2B481
6 changed files with 87 additions and 61 deletions

View file

@ -1,26 +1,43 @@
{ {
config, config,
flakePath,
lib, lib,
pkgs,
... ...
}: { }: let
inherit (pkgs.stdenv.hostPlatform) isDarwin;
sketchybarPkg = pkgs.unstable.sketchybar;
in {
home = lib.mkIf isDarwin { home = lib.mkIf isDarwin {
packages = [pkgs.unstable.sketchybar]; packages = [sketchybarPkg];
}; };
launchd = lib.mkIf isDarwin { launchd = lib.mkIf isDarwin {
agents.sketchybar = { agents.sketchybar = {
enable = true; enable = true;
config = { config = {
ProgramArguments = ["${lib.getExe pkgs.unstable.sketchybar}"]; ProgramArguments = ["${lib.getExe sketchybarPkg}"];
KeepAlive = true; KeepAlive = true;
RunAtLoad = true; RunAtLoad = true;
ProcessType = "Interactive"; ProcessType = "Interactive";
Nice = -20; 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 { xdg.configFile = lib.mkIf isDarwin {
"sketchybar" = { "sketchybar" = {
source = config.lib.file.mkOutOfStoreSymlink ./sketchybar; source = config.lib.file.mkOutOfStoreSymlink "${flakePath}/home/apps/sketchybar";
recursive = true; recursive = true;
}; };
}; };

View file

@ -1,5 +1,7 @@
#!/usr/bin/env sh #!/usr/bin/env bash
# vim:fdm=marker # vim:fdm=marker
# dont' warn about unused variables:
# shellcheck disable=SC2034
# color definitions {{{ # color definitions {{{
# mocha {{{ # mocha {{{
@ -123,7 +125,7 @@ LIGHT_THEME="latte"
DARK_THEME="mocha" DARK_THEME="mocha"
# check whether or not macOS is in dark mode # 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 theme=$LIGHT_THEME
else else
theme=$DARK_THEME theme=$DARK_THEME
@ -133,7 +135,7 @@ function color() {
alpha=${2:-1} alpha=${2:-1}
color="$1" color="$1"
printf -v parsed "%.0f" "$(bc -l <<< "255*${alpha}")" printf -v parsed "%.0f" "$(bc -l <<<"255*${alpha}")"
printf -v alpha "%02x" "$parsed" printf -v alpha "%02x" "$parsed"
selected_color="${theme}_${color}" selected_color="${theme}_${color}"
echo "0x${alpha}${!selected_color}" echo "0x${alpha}${!selected_color}"
@ -141,22 +143,28 @@ function color() {
sketchybar \ sketchybar \
--bar \ --bar \
color="$(color crust)" \ color="$(color base)" \
border_color="$(color crust)" \
--default \ --default \
icon.color="$(color pink)" \ icon.color="$(color pink)" \
label.color="$(color pink)" \ label.color="$(color pink)" \
--set /space/ \ --set /space/ \
icon.color="$(color mauve 0.5)" \ icon.color="$(color mauve 0.5)" \
icon.highlight_color="$(color pink)" \ icon.highlight_color="$(color pink)" \
--set clock \ --set music \
icon.color="$(color pink)" \ icon.color="$(color pink)" \
label.color="$(color pink)" \ label.color="$(color pink)" \
--set "Mullvad VPN" \ --set "Mullvad VPN" \
alias.color="$(color pink)" \ alias.color="$(color peach)" \
--set "Little Snitch Agent" \
alias.color="$(color pink)" \
--set "Control Centre,Battery" \ --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 # set the yabai colours as well
yabai -m config active_window_border_color "$(color pink)" yabai -m config active_window_border_color "$(color pink)"

View file

@ -1,27 +1,23 @@
#!/usr/bin/env sh #!/usr/bin/env bash
if pgrep -xq Music; then if pgrep -xq Music; then
STATE=$(osascript -e 'tell application "Music" to player state 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 || echo "") 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 || echo "") 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 # fall back to artist, if album artist is unavailable, or generic
if [ "$ARTIST" = "" ] || [ "$ARTIST" = "Various Artists" ]; then if [[ -z "$ARTIST" ]] || [[ "$ARTIST" = "Various Artists" ]]; then
ARTIST=$(osascript -e 'tell application "Music" to artist of current track as string' 2>/dev/null || echo "") ARTIST=$(osascript -e 'tell application "Music" to artist of current track as string' 2>/dev/null)
fi fi
if [ "$STATE" = "playing" ]; then if [[ "$STATE" = "playing" ]]; then
ICON=""
LABEL="$ARTIST - $TRACK" LABEL="$ARTIST - $TRACK"
else else
ICON="" LABEL=""
if [ "$TRACK" = "" ] || [ "$ARTIST" = "" ]; then
LABEL="paused"
else
LABEL="$ARTIST - $TRACK"
fi
fi 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 else
sketchybar --set "$NAME" icon="" label="" --add event "${NAME}-changed" sketchybar --set "$NAME" label=""
fi fi

View file

@ -6,15 +6,20 @@ PLUGIN_DIR="$HOME"/.config/sketchybar/plugins
sketchybar --bar \ sketchybar --bar \
height=32 \ height=32 \
position=top \ position=top \
padding_left=0 \ padding_left=5 \
padding_right=0 \ padding_right=5 \
margin=5 \
corner_radius=10 \
border_width=2 \
hidden=off \ hidden=off \
topmost=on topmost=off \
y_offset=2
# colors are managed separately in the colordummy, # colors are managed separately in the colordummy,
# which listens to theme_changed events, # which listens to theme_changed events,
# to swap between Catppuccin Mocha and Latte # to swap between Catppuccin Mocha and Latte
sketchybar -m --add event theme_changed AppleInterfaceThemeChangedNotification sketchybar -m --add event theme_changed AppleInterfaceThemeChangedNotification
sketchybar -m --add event music_changed com.apple.Music.playerInfo
sketchybar \ sketchybar \
--add item colordummy center \ --add item colordummy center \
--set colordummy \ --set colordummy \
@ -64,9 +69,11 @@ for i in "${!SPACE_ICONS[@]}"; do
done done
sketchybar \ sketchybar \
--add item music center \ --add item music left \
--set music \ --set music \
script="$PLUGIN_DIR/music.sh" \ script="$PLUGIN_DIR/music.sh" \
label.y_offset=-1 \
--subscribe music music_changed \
--add item clock right \ --add item clock right \
--set clock \ --set clock \
script="$PLUGIN_DIR/clock.sh" \ script="$PLUGIN_DIR/clock.sh" \

View file

@ -20,6 +20,7 @@ in {
./apps/neovim.nix ./apps/neovim.nix
./apps/newsboat.nix ./apps/newsboat.nix
./apps/rice.nix ./apps/rice.nix
./apps/sketchybar.nix
./apps/vscode.nix ./apps/vscode.nix
./apps/wezterm.nix ./apps/wezterm.nix
./apps/zsh.nix ./apps/zsh.nix
@ -49,6 +50,7 @@ in {
nur.repos.nekowinston.org-stats nur.repos.nekowinston.org-stats
(nerdfonts.override {fonts = ["NerdFontsSymbolsOnly"];}) (nerdfonts.override {fonts = ["NerdFontsSymbolsOnly"];})
victor-mono
unstable.wezterm unstable.wezterm
] ]
++ lib.optionals isLinux [ ++ lib.optionals isLinux [

View file

@ -6,7 +6,31 @@
}: { }: {
services.yabai = { services.yabai = {
enable = true; enable = true;
enableScriptingAddition = true;
package = pkgs.unstable.yabai; 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 extraConfig = let
rule = "yabai -m rule --add"; rule = "yabai -m rule --add";
ignored = app: builtins.concatStringsSep "\n" (map (e: ''${rule} app="${e}" manage=off sticky=off layer=above border=off'') app); 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 border=off app="CleanShot"
${rule} manage=off sticky=on app="OBS Studio" ${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 = { services.skhd = {
@ -56,19 +60,11 @@
cmd + ctrl - j : ${yabai} -m window --focus south cmd + ctrl - j : ${yabai} -m window --focus south
cmd + ctrl - k : ${yabai} -m window --focus north cmd + ctrl - k : ${yabai} -m window --focus north
cmd + ctrl - l : ${yabai} -m window --focus east 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 # move window
cmd + shift - h : ${yabai} -m window --warp west cmd + shift - h : ${yabai} -m window --warp west
cmd + shift - j : ${yabai} -m window --warp south cmd + shift - j : ${yabai} -m window --warp south
cmd + shift - k : ${yabai} -m window --warp north cmd + shift - k : ${yabai} -m window --warp north
cmd + shift - l : ${yabai} -m window --warp east 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 # toggle sticky/floating
cmd + shift - s: ${yabai} -m window --toggle sticky --toggle float --toggle topmost cmd + shift - s: ${yabai} -m window --toggle sticky --toggle float --toggle topmost
cmd + shift - d: ${yabai} -m window --toggle float cmd + shift - d: ${yabai} -m window --toggle float