Skip to content

Instantly share code, notes, and snippets.

@feilongfl
Last active June 7, 2025 02:17
Show Gist options
  • Save feilongfl/4da514e97a859f355c4c9b6acb4818d4 to your computer and use it in GitHub Desktop.
Save feilongfl/4da514e97a859f355c4c9b6acb4818d4 to your computer and use it in GitHub Desktop.
#!/bin/bash
# alacritty-toggle.sh — Toggle Alacritty dropdown terminal on macOS with yabai
echo "$(date) key hit" >> /tmp/alacritty-toggle.log
set -euo pipefail
APP="alacritty"
YABAI=/opt/homebrew/bin/yabai
JQ=/opt/homebrew/bin/jq
BC=/usr/bin/bc
# 1. Check if Alacritty is running
if ! pgrep -x "$APP" >/dev/null 2>&1; then
open -na "$APP"
exit 0
fi
# 2. Get Alacritty window ID
WIN_ID=$(
$YABAI -m query --windows |
$JQ -r '.[] | select(.app == "Alacritty") | .id' | head -n1
)
[ -z "$WIN_ID" ] && exit 1
# 3. Visibility state
IS_VISIBLE=$($YABAI -m query --windows --window "$WIN_ID" | $JQ -r '.["is-visible"]')
IS_MINIMIZED=$($YABAI -m query --windows --window "$WIN_ID" | $JQ -r '.["is-minimized"]')
if [[ "$IS_VISIBLE" == "true" && "$IS_MINIMIZED" == "false" ]]; then
$YABAI -m window "$WIN_ID" --minimize
# $YABAI -m window "$WIN_ID" --move abs:-5000:-5000
exit 0
fi
# 4. Show and center
$YABAI -m window "$WIN_ID" --deminimize 2>/dev/null || true
$YABAI -m window "$WIN_ID" --toggle float
$YABAI -m window "$WIN_ID" --toggle sticky
$YABAI -m window --focus "$WIN_ID"
$YABAI -m window "$WIN_ID" --move abs:10:0
$YABAI -m window "$WIN_ID" --resize abs:2540:1400
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment