Skip to content

Instantly share code, notes, and snippets.

@mickaelperrin
Last active March 27, 2023 11:09
Show Gist options
  • Save mickaelperrin/4b72fa46dec0aa8935b170685dac507d to your computer and use it in GitHub Desktop.
Save mickaelperrin/4b72fa46dec0aa8935b170685dac507d to your computer and use it in GitHub Desktop.
Yabai configuration
#!/usr/bin/env sh
# _ _ _
# | | | | | |
# ___| | _| |__ __| |_ __ ___
# / __| |/ / '_ \ / _` | '__/ __|
# \__ \ <| | | | (_| | | | (__
# |___/_|\_\_| |_|\__,_|_| \___|
#
:: default : yabai -m config active_window_border_color 0x99DD0000
:: prefix @: yabai -m config active_window_border_color 0xFF00FF00
ctrl - s ; prefix
prefix < ctrl - s ; default
prefix < f : yabai -m window --toggle zoom-fullscreen; skhd --key 'ctrl - s'
prefix < s : yabai -m space --focus next; skhd --key 'ctrl - s'
prefix < d : yabai -m space --focus prev; skhd --key 'ctrl - s'
prefix < z : toggle_central_app
prefix < l : yabai -m window --resize right:100:0
prefix < h : yabai -m window --resize left:-100:0
prefix < j : yabai -m window --resize bottom:0:100
prefix < k : yabai -m window --resize top:0:-100
prefix < shift - l : yabai -m window --resize right:100:0
prefix < shift - h : yabai -m window --resize left:100:0
prefix < shift - j : yabai -m window --resize bottom:0:-100
prefix < shift - k : yabai -m window --resize top:0:100
ctrl + alt + cmd - r : launchctl kickstart -k "gui/${UID}/homebrew.mxcl.yabai"
alt - r : yabai -m space --rotate 90
#ctrl - space : export CURRENT_WINDOW=$(yabai -m query --windows --window | jq -r '"\(.app) - \(.title)"');yabai -m window --display 3; yabai -m window --focus $CURRENT_WINDOW;yabai -m window --toggle float; yabai -m window --grid 10:10:3:1:4:6;
# End of common section
# -----------------------------------------------------------------------------
#ctrl + alt - 0x0A : yabai -m window --space "web"
ctrl + alt - 0x12 : test $(yabai -m query --windows --window | jq '.display') -eq ${LAPTOP_MONITOR} && yabai -m window --space "Terminal 1" || test $(yabai -m query --windows --window | jq '.display') -eq ${RIGHT_MONITOR} && yabai -m window --space "Side-Projet 1" || yabai -m window --space "Projet 1"
ctrl + alt - 0x13 : test $(yabai -m query --windows --window | jq '.display') -eq ${LAPTOP_MONITOR} && yabai -m window --space "Terminal 2" || test $(yabai -m query --windows --window | jq '.display') -eq ${RIGHT_MONITOR} && yabai -m window --space "Side-Projet 2" || yabai -m window --space "Projet 2"
ctrl + alt - 0x14 : test $(yabai -m query --windows --window | jq '.display') -eq ${LAPTOP_MONITOR} && yabai -m window --space "Terminal 3" || test $(yabai -m query --windows --window | jq '.display') -eq ${RIGHT_MONITOR} && yabai -m window --space "Side-Projet 3" || yabai -m window --space "Projet 3"
ctrl + alt - 0x15 : test $(yabai -m query --windows --window | jq '.display') -eq ${LAPTOP_MONITOR} && yabai -m window --space "Terminal 4" || test $(yabai -m query --windows --window | jq '.display') -eq ${RIGHT_MONITOR} && yabai -m window --space "Side-Projet 4" || yabai -m window --space "Projet 4"
ctrl + alt - 0x17 : test $(yabai -m query --windows --window | jq '.display') -eq ${LAPTOP_MONITOR} && yabai -m window --space "Terminal 5" || test $(yabai -m query --windows --window | jq '.display') -eq ${RIGHT_MONITOR} && yabai -m window --space "Side-Projet 5" || yabai -m window --space "Projet 5"
#ctrl + alt - 0x16 : yabai -m window --space 7
#ctrl + alt - 0x1A : yabai -m window --space 8
ctrl + alt - 0x1C : yabai -m window --space "Messages"
ctrl + alt - 0x19 : test $(yabai -m query --windows --window | jq '.display') -eq ${LAPTOP_MONITOR} && yabai -m window --space "Terminal ansible" || yabai -m window --space "ansible"
ctrl + alt - 0x1D : test $(yabai -m query --windows --window | jq '.display') -eq ${LAPTOP_MONITOR} && yabai -m window --space "Terminal docker" || yabai -m window --space "docker"
ctrl + alt - 0x1B : yabai -m window --space "yeoman"
ctrl + alt - 0x18 : yabai -m window --space "dotfiles"
ctrl + alt - 0x33 : yabai -m window --space "git"
# variables are defined in ~/.zprofile.custom
ctrl + alt - z : yabai -m window --display ${CENTRAL_MONITOR}
ctrl + alt - a : yabai -m window --display ${LAPTOP_MONITOR}
ctrl + alt - 0x30 : yabai -m window --display ${LEFT_MONITOR}
ctrl + alt - e : yabai -m window --display ${RIGHT_MONITOR}
ctrl + alt - r : yabai -m window --display ${RIGHT_TOP_MONITOR}
cmd + alt - 0x0A : next_space_on_monitor $LEFT_MONITOR
cmd + alt - 0x12 : yabai -m space --focus "Projet 1" && yabai -m space --focus "Terminal 1" && yabai -m space --focus "Side-Projet 1"
cmd + alt - 0x13 : yabai -m space --focus "Projet 2" && yabai -m space --focus "Terminal 2" && yabai -m space --focus "Side-Projet 2"
cmd + alt - 0x14 : yabai -m space --focus "Projet 3" && yabai -m space --focus "Terminal 3" && yabai -m space --focus "Side-Projet 3"
cmd + alt - 0x15 : yabai -m space --focus "Projet 4" && yabai -m space --focus "Terminal 4" && yabai -m space --focus "Side-Projet 4"
cmd + alt - 0x17 : yabai -m space --focus "Projet 5" && yabai -m space --focus "Terminal 5" && yabai -m space --focus "Side-Projet 5"
#cmd + alt - 0x16 : yabai -m space --focus 7
#cmd + alt - 0x1A : yabai -m space --focus 8
cmd + alt - 0x16 : yabai -m space --focus "Messages" && yabai -m space --focus "GamingLaptop" && yabai -m space --focus "GamingCentral" && yabai -m space --focus "web"
cmd + alt - 0x1C : yabai -m space --focus "Messages"
cmd + alt - 0x19 : yabai -m space --focus "ansible" && yabai -m space --focus "Terminal ansible"
cmd + alt - 0x1D : yabai -m space --focus "docker" && yabai -m space --focus "Terminal docker"
cmd + alt - 0x1B : yabai -m space --focus "yeoman"
cmd + alt - 0x18 : yabai -m space --focus "dotfiles"
cmd + alt - 0x33 : yabai -m space --focus "git"
#!/usr/bin/env sh
# _ _
# | | (_)
# _ _ __ _| |__ __ _ _ _ __ ___
# | | | |/ _` | '_ \ / _` | | '__/ __|
# | |_| | (_| | |_) | (_| | | | | (__
# \__, |\__,_|_.__/ \__,_|_|_| \___|
# __/ |
# |___/
MONITORS=$(yabai -m query --displays | jq '.[].index')
debug() {
echo "$@" 1>&2;
}
delete_all_spaces() {
for monitor in ${MONITORS[@]}; do
local FOCUS_SPACE=$(yabai -m query --spaces --display $monitor | jq '.[0].index')
debug "Focusing space $FOCUS_SPACE"
yabai -m space --focus "$FOCUS_SPACE"
while [ $(yabai -m query --spaces --display $monitor | jq '. | length') -ne 1 ]; do
local SPACE_ID=$(yabai -m query --spaces --display $monitor | jq '.[-1].index')
debug "Deleting space $SPACE_ID"
yabai -m space --destroy "$SPACE_ID"
done
done
}
name_first_space() {
local SPACE_ID=$(get_first_space_of_monitor $1)
debug "Name space ($SPACE_ID): $2"
yabai -m space "$SPACE_ID" --label "$2"
}
name_space() {
local SPACE_ID=$(yabai -m query --spaces --display $1 | jq '[.[] | select (.label=="")] | .[0] | .index')
debug "Name space ($SPACE_ID): $2"
yabai -m space "$SPACE_ID" --label "$2"
}
get_first_space_of_monitor() {
yabai -m query --spaces --display $1 | jq '.[0].index'
}
create_space_on_monitor() {
local FIRST_SPACE=$(get_first_space_of_monitor $1)
debug "Create space after $FIRST_SPACE"
yabai -m space --create $FIRST_SPACE
name_space $1 "$2"
}
sudo yabai --load-sa
# global settings
yabai -m config debug_output on
yabai -m config mouse_follows_focus off
yabai -m config focus_follows_mouse off
yabai -m config window_placement second_child
yabai -m config window_topmost off
yabai -m config window_shadow on
yabai -m config window_opacity off
yabai -m config window_origin_display default
#yabai -m config window_opacity_duration 0.0
yabai -m config active_window_opacity 1.0
yabai -m config normal_window_opacity 0.99
yabai -m config window_border off
yabai -m config window_border_width 1
yabai -m config active_window_border_color 0xff775759
yabai -m config normal_window_border_color 0xff555555
yabai -m config insert_feedback_color 0xffd75f5f
yabai -m config split_ratio 0.51
yabai -m config auto_balance off
yabai -m config mouse_modifier fn
yabai -m config mouse_action1 move
yabai -m config mouse_action2 resize
# general space settings
yabai -m config layout bsp
yabai -m config top_padding 5
yabai -m config bottom_padding 5
yabai -m config left_padding 5
yabai -m config right_padding 5
yabai -m config window_gap 5
if [ -f $HOME/.zprofile.custom ]; then
. $HOME/.zprofile.custom
fi
# Recreate all spaces
# -----------------------------------------------------------
delete_all_spaces
# -----------------------------------------------------------
if [ "$NB_MONITORS" = "4" ];then
name_first_space $LAPTOP_MONITOR "Terminal 1"
create_space_on_monitor $LAPTOP_MONITOR "Terminal 2"
create_space_on_monitor $LAPTOP_MONITOR "Terminal 3"
create_space_on_monitor $LAPTOP_MONITOR "Terminal 4"
create_space_on_monitor $LAPTOP_MONITOR "Terminal 5"
create_space_on_monitor $LAPTOP_MONITOR "Terminal docker"
create_space_on_monitor $LAPTOP_MONITOR "Terminal ansible"
name_first_space $LEFT_MONITOR "web"
create_space_on_monitor $LEFT_MONITOR "Todo"
name_first_space $RIGHT_MONITOR "Side-Projet 1"
create_space_on_monitor $RIGHT_MONITOR "Side-Projet 2"
create_space_on_monitor $RIGHT_MONITOR "Side-Projet 3"
create_space_on_monitor $RIGHT_MONITOR "Side-Projet 4"
create_space_on_monitor $RIGHT_MONITOR "Side-Projet 5"
create_space_on_monitor $RIGHT_MONITOR "virtualisation"
create_space_on_monitor $RIGHT_MONITOR "Messages"
name_first_space $CENTRAL_MONITOR "Projet 1"
create_space_on_monitor $CENTRAL_MONITOR "Projet 2"
create_space_on_monitor $CENTRAL_MONITOR "Projet 3"
create_space_on_monitor $CENTRAL_MONITOR "Projet 4"
create_space_on_monitor $CENTRAL_MONITOR "Projet 5"
create_space_on_monitor $CENTRAL_MONITOR "dotfiles"
create_space_on_monitor $CENTRAL_MONITOR "docker"
create_space_on_monitor $CENTRAL_MONITOR "ansible"
create_space_on_monitor $CENTRAL_MONITOR "yeoman"
create_space_on_monitor $CENTRAL_MONITOR "git"
cat $HOME/Config/Dotfiles/3-custom.private/home/skhd/skhdrc.common > $HOME/.skhdrc
cat $HOME/Config/Dotfiles/3-custom.private/home/skhd/skhdrc.desktop >> $HOME/.skhdrc
# -----------------------------------------------------------
elif [ "$NB_MONITORS" = "2" ];then
name_first_space $LAPTOP_MONITOR "Terminal 1"
create_space_on_monitor $LAPTOP_MONITOR "Terminal 2"
create_space_on_monitor $LAPTOP_MONITOR "Terminal 3"
create_space_on_monitor $LAPTOP_MONITOR "Terminal 4"
create_space_on_monitor $LAPTOP_MONITOR "Terminal 5"
create_space_on_monitor $LAPTOP_MONITOR "Terminal docker"
create_space_on_monitor $LAPTOP_MONITOR "Terminal ansible"
name_first_space $CENTRAL_MONITOR "Projet 1"
create_space_on_monitor $CENTRAL_MONITOR "Projet 2"
create_space_on_monitor $CENTRAL_MONITOR "Projet 3"
create_space_on_monitor $CENTRAL_MONITOR "Projet 4"
create_space_on_monitor $CENTRAL_MONITOR "Projet 5"
create_space_on_monitor $CENTRAL_MONITOR "dotfiles"
create_space_on_monitor $CENTRAL_MONITOR "docker"
create_space_on_monitor $CENTRAL_MONITOR "ansible"
create_space_on_monitor $CENTRAL_MONITOR "yeoman"
create_space_on_monitor $CENTRAL_MONITOR "web"
create_space_on_monitor $CENTRAL_MONITOR "Todo"
create_space_on_monitor $CENTRAL_MONITOR "Messages" create_space_on_monitor $CENTRAL_MONITOR "git"
create_space_on_monitor $CENTRAL_MONITOR "virtualisation"
create_space_on_monitor $LAPTOP_MONITOR "git"
cat $HOME/Config/Dotfiles/3-custom.private/home/skhd/skhdrc.common > $HOME/.skhdrc
cat $HOME/Config/Dotfiles/3-custom.private/home/skhd/skhdrc.1external >> $HOME/.skhdrc
# -----------------------------------------------------------
else
name_first_space $LAPTOP_MONITOR "Terminal 1"
create_space_on_monitor $LAPTOP_MONITOR "Projet 1"
create_space_on_monitor $LAPTOP_MONITOR "Chrome 1"
create_space_on_monitor $LAPTOP_MONITOR "Terminal 2"
create_space_on_monitor $LAPTOP_MONITOR "Projet 2"
create_space_on_monitor $LAPTOP_MONITOR "Chrome 2"
create_space_on_monitor $LAPTOP_MONITOR "Terminal 3"
create_space_on_monitor $LAPTOP_MONITOR "Projet 3"
create_space_on_monitor $LAPTOP_MONITOR "Chrome 3"
create_space_on_monitor $LAPTOP_MONITOR "dotfiles"
create_space_on_monitor $LAPTOP_MONITOR "docker"
create_space_on_monitor $LAPTOP_MONITOR "ansible"
create_space_on_monitor $LAPTOP_MONITOR "yeoman"
create_space_on_monitor $LAPTOP_MONITOR "web"
create_space_on_monitor $LAPTOP_MONITOR "Todo"
create_space_on_monitor $LAPTOP_MONITOR "Messages"
create_space_on_monitor $LAPTOP_MONITOR "git"
create_space_on_monitor $LAPTOP_MONITOR "virtualisation"
cat $HOME/Config/Dotfiles/3-custom.private/home/skhd/skhdrc.common > $HOME/.skhdrc
cat $HOME/Config/Dotfiles/3-custom.private/home/skhd/skhdrc.macbook_only >> $HOME/.skhdrc
fi
# Main windows rules
# -----------------------------------------------------------
yabai -m rule --add app="^PhpStorm$" display=$CENTRAL_MONITOR
yabai -m rule --add app="^Google Chrome$" display=$RIGHT_MONITOR
yabai -m rule --add app="^PhpStorm$" title="^Dotfiles" space=dotfiles manage=on layer=normal
yabai -m rule --add app="^PhpStorm$" title="^Ansible.v5" space=ansible manage=on layer=normal
yabai -m rule --add app="^PhpStorm$" title="^Docker" space=docker manage=on layer=normal
yabai -m rule --add app="^PhpStorm$" title="^Yeoman" space=yeoman manage=on layer=normal
#yabai -m rule --add app="^PhpStorm$" title="" manage=off layer=normal
yabai -m rule --add app="^Dash$" manage=off grid=100:100:10:10:80:80 layer=normal display=$CENTRAL_MONITOR
yabai -m rule --add app="^(DisplayLink|Calculette|Dictionnaire|Informations système|Préférences Système|Mx Power Gadget|DisplayLinkUserAgent|1Password|Authy Desktop|BetterDummy|Kaleidoscope|JetBrains Toolbox)$" manage=off layer=above
yabai -m rule --add app="^ClickUp|Gmail for dkod$" space="Todo"
yabai -m rule --add app="^(Safari|Beam)$" space="web"
yabai -m rule --add app="^iTerm2$" display=$LAPTOP_MONITOR
yabai -m rule --add app="^iTerm2$" title="Config/Docker" space="Terminal docker"
yabai -m rule --add app="^iTerm2$" title="Config/Ansible" space="Terminal ansible"
yabai -m rule --add app="^UTM$" space=virtualisation
yabai -m rule --add app="^Tower$" space=git
yabai -m rule --add app="^PDF Expert$" space=Todo
yabai -m rule --add app="^(Discord|Messages|Musique|WhatsApp|ChatMate Pro for WhatsApp|Twitter)$" space=Messages
yabai -m rule --add app="^Aperçu$" title=".*\.pdf" space="Todo"
yabai -m rule --add app="^SideNotes$" manage=off
# Subwindows rules
# -----------------------------------------------------------
yabai -m rule --add app="^Finder$" title="(Co(pie|nnect)|Déplacer|Info|Pref)" manage=off layer=above
yabai -m rule --add app="^Safari$" title="^(Général|Onglets|Remplissage automatique|Mots de passe|Recherche|Sécurité|Confidentialité|Sites web|Extensions|Avancées)$" manage=off layer=above
yabai -m rule --add app="^Musique$" title="^Mini-lecteur$" manage=off layer=above grid=100:100:0:0:10:20 display=$RIGHT_MONITOR sticky=on
yabai -m rule --add app="^1Password" title!="^Accès rapide" manage=off layer=above grid=6:4:1:1:2:4 display=$CENTRAL_MONITOR
yabai -m rule --add app="^1Password" title="^Accès rapide" manage=off layer=above display=$CENTRAL_MONITOR
yabai -m rule --add app="^iterm2$" title=" logs$" display=$RIGHT_MONITOR
yabai -m rule --add app="^Discord$" title="Salon" manage=off layer=above sticky=on
yabai -m rule --add app="^PhpStorm$" title="^(Move)$" manage=off display=$CENTRAL_MONITOR
yabai -m rule --add app="^PhpStorm$" title="^Debug -" display=$LAPTOP_MONITOR
yabai -m rule --add app="^PhpStorm$" title="^(Preferences)$" manage=off grid=100:100:5:5:90:90 layer=normal display=$CENTRAL_MONITOR
yabai -m rule --add app="^PhpStorm$" title="^(CLI Interpreters|Find in Files)$" manage=off grid=100:100:10:10:80:80 layer=normal display=$CENTRAL_MONITOR
# Events
# -----------------------------------------------------------
yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"
# refocus when window is closed
yabai -m signal --add event=window_destroyed action="yabai -m query --windows --window &> /dev/null || yabai -m window --focus mouse"
yabai -m signal --add event=application_terminated action="yabai -m query --windows --window &> /dev/null || yabai -m window --focus mouse"
# Center windows
events=('application_launched')
apps=('Rappels' 'Préférences Système')
#read -r -d '' action <<- 'EOF'
# window="$(yabai -m query --windows --window)"
# display="$(yabai -m query --displays --window)"
# coords="$(jq \
# --argjson window "${window}" \
# --argjson display "${display}" \
# -nr '(($display.frame | .x + .w / 2) - ($window.frame.w / 2) | tostring)
# + ":"
# + (($display.frame | .y + .h / 2) - ($window.frame.h / 2) | tostring)')"
# yabai -m window --move "abs:${coords}"
#EOF
#(( ${#apps[@]} )) && app_query="app=\"^($(IFS=\|;echo "${apps[*]}"))\$\""
#for event in "${events[@]}"; do
# debug "action=$action"
# debug "Label: ${0}_signal_${event}"
# debug "app_query=$app_query"
# debug "app_query_result: $(eval \"${app_query}}\")"
# yabai -m signal --add label="${0}_signal_${event}" event="${event}" \
# $(eval "${app_query}}") action="${action}"
#done
#!/usr/bin/env sh
export PATH="$PATH:$HOME/.bin.go:/opt/homebrew/bin"
export CAMELLIA_DB_PATH=$HOME/.camellia.db
export LAPTOP_MONITOR=1
export LEFT_MONITOR=1
export CENTRAL_MONITOR=1
export RIGHT_MONITOR=1
export NB_MONITORS="$(yabai -m query --displays | jq '. | length')"
export LAPTOP_MONITOR=$(yabai -m query --displays | jq '.[] | select(.uuid|test("37D8832A-2D66-02CA-B9F7-8F30A301B230"))| .index')
if [ "$NB_MONITORS" = "4" ];then
if [ "1" = $(yabai -m query --displays | jq '[.[] | select(.uuid|test("25A1B2F9-D266-4414-A6AC-04F29083AF39"))] | length') ]; then #Maison
export RIGHT_MONITOR=$(yabai -m query --displays | jq '.[] | select(.uuid|test("5C3C4F45-1D73-4F7A-9FD2-30A6B092251")) | .index')
export CENTRAL_MONITOR=$(yabai -m query --displays | jq '.[] | select(.uuid|test("25A1B2F9-D266-4414-A6AC-04F29083AF39")) | .index')
export LEFT_MONITOR=$(yabai -m query --displays | jq '.[] | select(.uuid|test("49DFA891-BBE8-4DC9-8433-589682744F42")) | .index')
elif [ "1" = $(yabai -m query --displays | jq '[.[] | select(.uuid|test("24FE632B."))] | length') ]; then #VieuxEcrans
export LEFT_MONITOR=$(yabai -m query --displays | jq '.[] | select(.uuid|test("00FB39F5.")) | .index')
export CENTRAL_MONITOR=$(yabai -m query --displays | jq '.[] | select(.uuid|test("24FE632B.")) | .index')
export RIGHT_MONITOR=$(yabai -m query --displays | jq '.[] | select(.uuid|test("02C8F254.")) | .index')
fi
elif [ "$NB_MONITORS" = "2" ];then
export CENTRAL_MONITOR=$(yabai -m query --displays | jq '.[] | select(.uuid|test("37D8832A.")|not) | .index')
fi
function window_is() {
[ $(yabai -m query --windows --window $2 | jq ".\"is-$1\"") = "true" ] && return 0 || return 1
}
function tile_app() {
if window_is floating; then
yabai -m window --toggle float
fi
if window_is topmost; then
yabai -m window --toggle topmost
fi
}
function switch_central_app() {
echo "switch_central_app"
yabai -m window --focus mouse
CENTRAL_APP=$(yabai -m query --windows | jq '.[] | select(."is-topmost"==true)|.id')
echo "CENTRAL_APP: $CENTRAL_APP"
CURRENT_APP=$(yabai -m query --windows --window | jq '.id' )
if [ "$CENTRAL_APP" != "" ]; then
if window_is floating "${CENTRAL_APP}"; then
yabai -m window "${CENTRAL_APP}" --toggle float
fi
if window_is topmost "${CENTRAL_APP}"; then
yabai -m window "${CENTRAL_APP}" --toggle topmost
fi
fi
if [ "$CURRENT_APP" = "$CENTRAL_APP" ]; then
if window_is floating; then
yabai -m window --toggle float
fi
if window_is topmost; then
yabai -m window --toggle topmost
fi
else
if ! window_is floating; then
yabai -m window --toggle float --grid 100:100:5:5:90:90
fi
if ! window_is topmost; then
yabai -m window --toggle topmost
fi
fi
}
function toggle_central_app() {
SPACE_ON_CENTRAL_MONITOR=$(yabai -m query --spaces | jq ".[] | select(.\"is-visible\"==true) | select(.display==$CENTRAL_MONITOR) | .index")
echo "SPACE_ON_CENTRAL_MONITOR: $SPACE_ON_CENTRAL_MONITOR" >> /Users/mickaelperrin/debug.yabai.log
CENTRAL_APP=$(yabai -m query --windows | jq "[.[] | select(.frame.x==-455)|select(.space==$SPACE_ON_CENTRAL_MONITOR)|.id]|first")
CENTRAL_APP_NAME=$(yabai -m query --windows --window $CENTRAL_APP | jq '.title')
CENTRAL_APP_INDEX=$(yabai -m query --windows --space $SPACE_APP | jq "[.[].id] | sort_by(.) | to_entries | map(select(.value==$CENTRAL_APP)) | first | .key")
echo "CENTRAL_APP_NAME: $CENTRAL_APP_NAME" >> /Users/mickaelperrin/debug.yabai.log
echo "CENTRAL_APP: $CENTRAL_APP" >> /Users/mickaelperrin/debug.yabai.log
echo "CENTRAL_APP_INDEX: $CENTRAL_APP_INDEX" >> /Users/mickaelperrin/debug.yabai.log
echo >> /Users/mickaelperrin/debug.yabai.log
SPACE_APP=$(yabai -m query --windows --window $CENTRAL_APP | jq '.space')
APPS_INDEX=$(yabai -m query --windows --space $SPACE_APP | jq "[.[].id] | sort_by(.) | to_entries")
echo "APPS_INDEX:" >> /Users/mickaelperrin/debug.yabai.log
echo "$APPS_INDEX" >> /Users/mickaelperrin/debug.yabai.log
SPACE_NAME=$(yabai -m query --spaces --space $SPACE_NAME | jq '.label')
echo "SPACE_APP: $SPACE_APP" >> /Users/mickaelperrin/debug.yabai.log
echo "SPACE_NAME: $SPACE_NAME" >> /Users/mickaelperrin/debug.yabai.log
CURRENT_APP=$(yabai -m query --windows --window | jq '.id' )
echo >> /Users/mickaelperrin/debug.yabai.log
echo "CURRENT_APP: $CURRENT_APP" >> /Users/mickaelperrin/debug.yabai.log
if [ -z $CENTRAL_APP ]; then
NEXT_APP=$CURRENT_APP
else
NEXT_APP=$(yabai -m query --windows --space $SPACE_APP | jq "[.[].id] | sort_by(.) | to_entries | .[$(($CENTRAL_APP_INDEX - 1))].value")
fi
NEXT_APP_NAME=$(yabai -m query --windows --window $NEXT_APP | jq '.title')
echo >> /Users/mickaelperrin/debug.yabai.log
echo "NEXT_APP_NAME: $NEXT_APP_NAME" >> /Users/mickaelperrin/debug.yabai.log
echo "NEXT_APP: $NEXT_APP" >> /Users/mickaelperrin/debug.yabai.log
echo >> /Users/mickaelperrin/debug.yabai.log
echo "-------------------------------------------">> /Users/mickaelperrin/debug.yabai.log
echo >> /Users/mickaelperrin/debug.yabai.log
yabai -m window --focus $NEXT_APP
if ! window_is floating $NEXT_APP; then
yabai -m window --toggle float --grid 100:100:5:5:90:90
fi
if [ "$CENTRAL_APP" != "" ]; then
if window_is floating "${CENTRAL_APP}"; then
yabai -m window "${CENTRAL_APP}" --toggle float
fi
if window_is topmost "${CENTRAL_APP}"; then
yabai -m window "${CENTRAL_APP}" --toggle topmost
fi
fi
}
next_space_on_monitor() {
local MONITOR_INDEX=$1
echo "MONITOR_INDEX: $MONITOR_INDEX"
MONITOR_ID=$(/opt/homebrew/bin/yabai -m query --displays | /opt/homebrew/bin/jq ".[] | select(.index==$MONITOR_INDEX) | .id" )
echo "MONITOR_ID: $MONITOR_ID"
CURRENT_SPACE=$(/opt/homebrew/bin/yabai -m query --spaces | jq ".[] | select(.\"is-visible\"==true and .display==$MONITOR_INDEX) | .index")
echo "CURRENT_SPACE: $CURRENT_SPACE"
CURRENT_SPACE_INDEX=$(/opt/homebrew/bin/yabai -m query --displays | /opt/homebrew/bin/jq ".[] | select(.index==$MONITOR_INDEX) | .spaces | to_entries | map(select(.value==$CURRENT_SPACE)) | first | .key")
echo "CURRENT_SPACE_INDEX: $CURRENT_SPACE_INDEX"
TOTAL_SPACES=$(/opt/homebrew/bin/yabai -m query --displays |/opt/homebrew/bin/jq ".[] | select(.index==$MONITOR_INDEX) | .spaces | length" )
echo "TOTAL_SPACES: $TOTAL_SPACES"
NEXT_SPACE=$(/opt/homebrew/bin/yabai -m query --displays | /opt/homebrew/bin/jq ".[] | select(.index==$MONITOR_INDEX) | .spaces[$(($(($CURRENT_SPACE_INDEX + 1)) % $TOTAL_SPACES))]")
echo "NEXT_SPACE: $NEXT_SPACE"
/opt/homebrew/bin/yabai -m space --focus $NEXT_SPACE
}
next_space_on_current_monitor() {
CURRENT_SPACE=$(/opt/homebrew/bin/yabai -m query --spaces --space | /opt/homebrew/bin/jq .index)
echo "CURRENT_SPACE: $CURRENT_SPACE"
CURRENT_SPACE_INDEX=$(/opt/homebrew/bin/yabai -m query --displays --display | /opt/homebrew/bin/jq ".spaces | to_entries | map(select(.value==$CURRENT_SPACE)) | first | .key")
echo "CURRENT_SPACE_INDEX: $CURRENT_SPACE_INDEX"
TOTAL_SPACES=$(/opt/homebrew/bin/yabai -m query --displays --display |/opt/homebrew/bin/jq '.spaces | length' )
echo "TOTAL_SPACES: $TOTAL_SPACES"
NEXT_SPACE=$(/opt/homebrew/bin/yabai -m query --displays --display | /opt/homebrew/bin/jq ".spaces[$(($(($CURRENT_SPACE_INDEX + 1)) % $TOTAL_SPACES))]")
echo "NEXT_SPACE: $NEXT_SPACE"
/opt/homebrew/bin/yabai -m space --focus $NEXT_SPACE
}
@sitek94
Copy link

sitek94 commented Mar 26, 2023

Wow, this is great, thanks for sharing!

@mickaelperrin
Copy link
Author

I have updated the gist with some yabai related functions (to remplace native swipe left/right to change spaces) and my skhdrc file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment