[swiftbar] One swiftbar config to rule them all

This commit is contained in:
2026-01-12 18:30:40 -05:00
parent bdfde94b63
commit a5394cbe43
3 changed files with 103 additions and 66 deletions

View File

@ -1,64 +0,0 @@
#!/bin/bash
set -euo pipefail
# --- CONFIG ---
ICON="🐳"
# Use your preferred match; consider "colima start" if "-f" isn't always present
MATCH='colima start -f'
# If brew is not in PATH for SwiftBar, hardcode it:
BREW="/opt/homebrew/bin/brew"
[[ -x "$BREW" ]] || BREW="/usr/local/bin/brew"
is_running() {
/bin/ps waux | /usr/bin/grep -F "$MATCH" | /usr/bin/grep -v grep >/dev/null 2>&1
}
pids() {
/bin/ps waux | /usr/bin/grep -F "$MATCH" | /usr/bin/grep -v grep | /usr/bin/awk '{print $2}'
}
# --- Menu bar title ---
if is_running; then
echo "$ICON 🟢"
else
echo "$ICON 🔴"
fi
echo "---"
# --- Actions ---
if is_running; then
echo "Stop (brew services) | bash='$0' param1=stop terminal=false refresh=true"
echo "Restart | bash='$0' param1=restart terminal=false refresh=true"
else
echo "Start (brew services) | bash='$0' param1=start terminal=false refresh=true"
fi
echo "---"
echo "Debug (brew services info) | bash='$0' param1=info terminal=true"
echo "Show matching processes | bash='$0' param1=ps terminal=true"
ACTION="${1:-}"
case "$ACTION" in
start)
"$BREW" services start colima || true
;;
stop)
"$BREW" services stop colima || true
;;
restart)
"$BREW" services restart colima || true
;;
info)
echo "BREW: $BREW"
echo
"$BREW" services info colima 2>&1 || true
echo
echo "=== brew services list (filtered) ==="
"$BREW" services list 2>&1 | /usr/bin/grep -i colima || true
;;
ps)
/bin/ps waux | /usr/bin/grep -F "$MATCH" | /usr/bin/grep -v grep || echo "(no matches)"
;;
esac

View File

@ -1,7 +1,6 @@
#!/bin/bash #!/bin/bash
set -euo pipefail set -euo pipefail
PLIST="$HOME/Library/LaunchAgents/com.hungryroot.django.plist" PLIST="$HOME/Library/LaunchAgents/com.hungryroot.django.plist"
ICON="🔌" ICON="🔌"
MATCH="&& just django" MATCH="&& just django"
@ -36,7 +35,7 @@ else
fi fi
echo "---" echo "---"
echo "Open http://0.0.0.0:8000 | href=http://0.0.0.0:8000" echo "Open http://0.0.0.0:9000 | href=http://0.0.0.0:9000"
echo "Debug | bash='$0' param1=debug terminal=true" echo "Debug | bash='$0' param1=debug terminal=true"
echo "Open plist | bash='/usr/bin/open' param1='$PLIST' terminal=false" echo "Open plist | bash='/usr/bin/open' param1='$PLIST' terminal=false"

View File

@ -0,0 +1,102 @@
#!/bin/bash
set -euo pipefail
ICON="🐳"
PROJECT_DIR="$HOME/src/github.com/hungryroot/hungryroot"
JUST_CMD="docker-run"
# Containers that belong to this stack (from your docker ps)
STACK_CONTAINERS=("mysql" "nginx" "redis")
# Paths (SwiftBar PATH can be limited)
DOCKER="/opt/homebrew/bin/docker"
[[ -x "$DOCKER" ]] || DOCKER="/usr/local/bin/docker"
JUST="/opt/homebrew/bin/just"
[[ -x "$JUST" ]] || JUST="/usr/local/bin/just"
command -v docker >/dev/null 2>&1 && DOCKER="$(command -v docker)" || true
command -v just >/dev/null 2>&1 && JUST="$(command -v just)" || true
docker_ok() {
"$DOCKER" info >/dev/null 2>&1
}
any_running() {
local name
for name in "${STACK_CONTAINERS[@]}"; do
if "$DOCKER" ps --format '{{.Names}}' 2>/dev/null | /usr/bin/grep -Fxq "$name"; then
return 0
fi
done
return 1
}
running_list() {
local name out=()
for name in "${STACK_CONTAINERS[@]}"; do
if "$DOCKER" ps --format '{{.Names}}' 2>/dev/null | /usr/bin/grep -Fxq "$name"; then
out+=("$name")
fi
done
printf "%s\n" "${out[@]:-}"
}
# --- Menu bar title ---
if docker_ok && any_running; then
echo "$ICON 🟢"
else
echo "$ICON 🔴"
fi
echo "---"
echo "Open http://127.0.0.1:8000 | href=http://127.0.0.1:8000"
echo "Run: just $JUST_CMD | bash='$0' param1=up terminal=true refresh=true"
echo "Stop Hungryroot stack (mysql/nginx/redis) | bash='$0' param1=down terminal=true refresh=true"
echo "---"
echo "docker ps (filtered) | bash='$0' param1=ps terminal=true"
echo "Open project dir | bash='/usr/bin/open' param1='$PROJECT_DIR' terminal=false"
ACTION="${1:-}"
case "$ACTION" in
up)
echo "== Checking Docker =="
if ! docker_ok; then
echo "Docker engine not reachable."
echo "If you use Colima: run 'colima start' first."
exit 1
fi
echo "OK ✅"
echo
echo "== Running: just $JUST_CMD =="
cd "$PROJECT_DIR"
"$JUST" "$JUST_CMD"
;;
down)
echo "== Stopping Hungryroot stack containers =="
if ! docker_ok; then
echo "Docker engine not reachable."
exit 1
fi
RUNNING="$(running_list || true)"
if [[ -z "${RUNNING:-}" ]]; then
echo "(none of mysql/nginx/redis are running)"
exit 0
fi
echo "$RUNNING" | /usr/bin/xargs -n 10 "$DOCKER" stop
echo "Done ✅"
;;
ps)
if ! docker_ok; then
echo "Docker engine not reachable."
exit 1
fi
echo "== Running (stack) =="
running_list || true
echo
echo "== docker ps =="
"$DOCKER" ps --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}' |
/usr/bin/grep -E '^(NAMES|mysql|nginx|redis)\b' || true
;;
esac