Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sketchybar #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions sketchybar/colors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env sh

# Color Palette
BLACK=0xff181926
WHITE=0xffcad3f5
RED=0xffed8796
GREEN=0xffa6da95
BLUE=0xff8aadf4
YELLOW=0xffeed49f
ORANGE=0xfff5a97f
MAGENTA=0xffc6a0f6
GREY=0xff939ab7
TRANSPARENT=0x00000000
16 changes: 16 additions & 0 deletions sketchybar/icons.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh

# Uses SF Symbols.

APPLE_ICN=􀣺
SUN_ICN=􀆮
MOON_ICN=􀆺
WIFI_ICN=􀙇
NETWORK_ICN=􀤆
SPEED_ICN=􀍾
BATTERY_100=􀛨
BATTERY_75=􀺸
BATTERY_50=􀺶
BATTERY_25=􀛩
BATTERY_0=􀛪
BATTERY_CHARGING=􀢋
7 changes: 7 additions & 0 deletions sketchybar/items/apple.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#### Apple Logo ####
sketchybar -m \
--add item apple.logo left \
--set apple.logo icon=$APPLE_ICN \
icon.font="$FONT:Heavy:16.0" \
label.drawing=off \
icon.padding_right=17 \
4 changes: 4 additions & 0 deletions sketchybar/items/battery.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sketchybar --add item battery right \
--set battery script="$PLUGIN_DIR/battery.sh" \
update_freq=10 \
--subscribe battery system_woke
3 changes: 3 additions & 0 deletions sketchybar/items/clock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sketchybar --add item clock right \
--set clock update_freq=1 \
script="$PLUGIN_DIR/clock.sh" \
34 changes: 34 additions & 0 deletions sketchybar/items/cpu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env sh

sketchybar --add item cpu.top right \
--set cpu.top label.font="$FONT:Medium:7" \
label=CPU \
icon.drawing=off \
width=0 \
y_offset=6 \
background.padding_right=10 \
\
--add item cpu.percent right \
--set cpu.percent label.font="$FONT:Bold:12" \
label=CPU \
y_offset=-4 \
width=40 \
icon.drawing=off \
update_freq=2 \
background.padding_right=10 \
\
--add graph cpu.sys right 100 \
--set cpu.sys width=0 \
graph.color=$RED \
graph.fill_color=$RED \
label.drawing=off \
icon.drawing=off \
background.padding_right=10 \
\
--add graph cpu.user right 100 \
--set cpu.user graph.color=$BLUE \
update_freq=2 \
label.drawing=off \
icon.drawing=off \
background.padding_right=10 \
script="$PLUGIN_DIR/cpu.sh"
4 changes: 4 additions & 0 deletions sketchybar/items/darkside.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sketchybar --add item appearance right \
--set appearance script="$PLUGIN_DIR/darkmode.sh" \
click_script="$PLUGIN_DIR/darkmode_click.sh" \
update_freq=1
21 changes: 21 additions & 0 deletions sketchybar/items/spaces.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
SPACE_ICONS=("1" "2" "3" "4" "5" "6" "7" "8" "9" "10")

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]} \
icon.padding_left=8 \
icon.padding_right=8 \
background.padding_left=5 \
background.padding_right=5 \
background.color=0x44ffffff \
background.corner_radius=5 \
background.height=22 \
background.drawing=off \
label.drawing=off \
script="$PLUGIN_DIR/space.sh" \
click_script="yabai -m space --focus $sid" \
icon.font="$FONT:Medium:15.0"
done
19 changes: 19 additions & 0 deletions sketchybar/items/wifi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
source "$PLUGIN_DIR/wifi.sh"

sketchybar --add item wifi.control right \
\
--set wifi.control icon=$WIFI_ICN \
label="${SSID}" \
click_script="$POPUP_CLICK_SCRIPT" \
popup.background.color=0x70000000 \
popup.blur_radius=50 \
popup.background.corner_radius=5 \
\
--add item wifi.ssid popup.wifi.control \
--set wifi.ssid icon=$NETWORK_ICN \
label="${SSID}" \
\
--add item wifi.speed popup.wifi.control \
--set wifi.speed icon=$SPEED_ICN \
script="$PLUGIN_DIR/wifi_click.sh" \
update_freq=10 \
8 changes: 8 additions & 0 deletions sketchybar/items/window_title.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env sh

sketchybar --add item space_separator left \
--add item window_title left \
--set window_title script="$PLUGIN_DIR/window_title.sh" \
icon.drawing=off \
label.font="$FONT:Semibold:15.0" \
--subscribe window_title front_app_switched
5 changes: 5 additions & 0 deletions sketchybar/items/yabai.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sketchybar -m --add item yabai_mode left \
--set yabai_mode update_freq=3 \
--set yabai_mode script="$PLUGIN_DIR/yabai_mode.sh" \
--set yabai_mode click_script="$PLUGIN_DIR/yabai_mode_click.sh" \
--subscribe yabai_mode space_change
28 changes: 28 additions & 0 deletions sketchybar/plugins/battery.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env sh

source $HOME/.config/sketchybar/icons.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=$BATTERY_100
;;
[6-8][0-9]) ICON=$BATTERY_75
;;
[3-5][0-9]) ICON=$BATTERY_50
;;
[1-2][0-9]) ICON=$BATTERY_25
;;
*) ICON="$BATTERY_10"
esac

if [[ $CHARGING != "" ]]; then
ICON=$BATTERY_CHARGING
fi

sketchybar --set $NAME icon="$ICON" label="${PERCENTAGE}%"
3 changes: 3 additions & 0 deletions sketchybar/plugins/clock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

sketchybar --set $NAME label="$(date '+%h %d - %H:%M:%S')"
29 changes: 29 additions & 0 deletions sketchybar/plugins/cpu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env sh

source "$HOME/.config/sketchybar/colors.sh"

CORE_COUNT=$(sysctl -n machdep.cpu.thread_count)
CPU_INFO=$(ps -eo pcpu,user)
CPU_SYS=$(echo "$CPU_INFO" | grep -v $(whoami) | sed "s/[^ 0-9\.]//g" | awk "{sum+=\$1} END {print sum/(100.0 * $CORE_COUNT)}")
CPU_USER=$(echo "$CPU_INFO" | grep $(whoami) | sed "s/[^ 0-9\.]//g" | awk "{sum+=\$1} END {print sum/(100.0 * $CORE_COUNT)}")

TOPPROC=$(ps axo "%cpu,ucomm" | sort -nr | tail +1 | head -n1 | awk '{printf "%.0f%% %s\n", $1, $2}' | sed -e 's/com.apple.//g')
CPUP=$(echo $TOPPROC | sed -nr 's/([^\%]+).*/\1/p')

CPU_PERCENT="$(echo "$CPU_SYS $CPU_USER" | awk '{printf "%.0f\n", ($1 + $2)*100}')"

COLOR=$WHITE
case "$CPU_PERCENT" in
[1-2][0-9]) COLOR=$YELLOW
;;
[3-6][0-9]) COLOR=$ORANGE
;;
[7-9][0-9]|100) COLOR=$RED
;;
esac

sketchybar --set cpu.percent label=$CPU_PERCENT% \
label.color=$COLOR \
--set cpu.top label="$TOPPROC" \
--push cpu.sys $CPU_SYS \
--push cpu.user $CPU_USER
12 changes: 12 additions & 0 deletions sketchybar/plugins/darkmode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

source $HOME/.config/sketchybar/icons.sh

if [[ $(defaults read -g AppleInterfaceStyle 2>/dev/null) == "Dark" ]]
then
sketchybar -m --set appearance icon="$SUN_ICN"

else
sketchybar -m --set appearance icon="$MOON_ICN"
fi

5 changes: 5 additions & 0 deletions sketchybar/plugins/darkmode_click.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

osascript -e 'tell app "System Events" to tell appearance preferences to set dark mode to not dark mode'

./darkmode.sh
3 changes: 3 additions & 0 deletions sketchybar/plugins/space.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

sketchybar --set $NAME background.drawing=$SELECTED
9 changes: 9 additions & 0 deletions sketchybar/plugins/wifi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env sh

CURRENT_WIFI="$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I)"
SSID="$(echo "$CURRENT_WIFI" | grep -o "SSID: .*" | sed 's/^SSID: //')"
CURR_TX="$(echo "$CURRENT_WIFI" | grep -o "lastTxRate: .*" | sed 's/^lastTxRate: //')"

POPUP_OFF="sketchybar --set wifi.control popup.drawing=off"
POPUP_CLICK_SCRIPT="sketchybar --set \$NAME popup.drawing=toggle"

7 changes: 7 additions & 0 deletions sketchybar/plugins/wifi_click.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env sh

export CURRENT_WIFI="$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I)"
export SSID="$(echo "$CURRENT_WIFI" | grep -o "SSID: .*" | sed 's/^SSID: //')"
export CURR_TX="$(echo "$CURRENT_WIFI" | grep -o "lastTxRate: .*" | sed 's/^lastTxRate: //')"

sketchybar --set $NAME label="${CURR_TX}Mbps"
3 changes: 3 additions & 0 deletions sketchybar/plugins/window_title.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

sketchybar --set $NAME label="$INFO"
16 changes: 16 additions & 0 deletions sketchybar/plugins/yabai_mode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

space_number=$(yabai -m query --spaces --space | jq -r .index)
yabai_mode=$(yabai -m query --spaces --space | jq -r .type)

case "$yabai_mode" in
bsp)
sketchybar -m --set yabai_mode label="􀏝"
;;
stack)
sketchybar -m --set yabai_mode label="􀏭"
;;
float)
sketchybar -m --set yabai_mode label="􀢌"
;;
esac
16 changes: 16 additions & 0 deletions sketchybar/plugins/yabai_mode_click.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

space_number=$(yabai -m query --spaces --space | jq -r .index)
yabai_mode=$(yabai -m query --spaces --space | jq -r .type)

case "$yabai_mode" in
bsp)
yabai -m space --layout stack && sketchybar -m --set yabai_mode label="􀢌"
;;
stack)
yabai -m space --layout float && sketchybar -m --set yabai_mode label="􀏭"
;;
float)
yabai -m space --layout bsp && sketchybar -m --set yabai_mode label="􀏝"
;;
esac
52 changes: 52 additions & 0 deletions sketchybar/sketchybarrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env sh

PLUGIN_DIR="$HOME/.config/sketchybar/plugins"
ITEM_DIR="$HOME/.config/sketchybar/items"

# run helper program
# TODO: UNCOMMENT WHEN DYNAMIC ISLAND HAS BEEN FIXED
# ISLANDHELPER=git.crissnb.islandhelper
# killall islandhelper
# $HOME/.config/sketchybar/plugins/Dynamic-Island-Sketchybar/helper/islandhelper $ISLANDHELPER &


source $HOME/.config/sketchybar/colors.sh
source $HOME/.config/sketchybar/icons.sh
# TODO: UNCOMMENT WHEN DYNAMIC ISLAND HAS BEEN FIXED
# source "$PLUGIN_DIR/Dynamic-Island-Sketchybar/config.sh"

export FONT="IBM Plex Mono"
export NERD_FONT="JetBrainsMono Nerd Font"

sketchybar --bar height=30 \
blur_radius=100 \
position=top \
padding_left=10 \
padding_right=10 \
color=0x15000000 \
shadow=on

sketchybar --default updates=when_shown \
drawing=on \
icon.font="$NERD_FONT:Regular:14.0" \
icon.color=0xffffffff \
label.font="$FONT:Medium:14.0" \
label.color=0xffffffff \
label.padding_left=4 \
label.padding_right=4 \
icon.padding_left=4 \
icon.padding_right=4

source $ITEM_DIR/apple.sh
source $ITEM_DIR/spaces.sh
source $ITEM_DIR/window_title.sh
source $ITEM_DIR/clock.sh
source $ITEM_DIR/battery.sh
source $ITEM_DIR/cpu.sh
source $ITEM_DIR/wifi.sh
# TODO: UNCOMMENT WHEN DYNAMIC ISLAND HAS BEEN FIXED
# source "$PLUGIN_DIR/Dynamic-Island-Sketchybar/item.sh"

sketchybar --update

echo "sketchybar configuration loaded.."