[swiftbar] Add swiftbar controls

This commit is contained in:
2026-01-12 18:03:01 -05:00
parent 94b5f324f7
commit fec4946e18
6 changed files with 195 additions and 12 deletions

View File

@ -20,10 +20,6 @@
<key>RunAtLoad</key>
<true/>
<!-- Optional: restart if it exits -->
<key>KeepAlive</key>
<true/>
<!-- Set a working directory explicitly (recommended) -->
<key>WorkingDirectory</key>
<string>/Users/colin.powell/src/github.com/hungryroot/hungryroot</string>

View File

@ -19,10 +19,6 @@
<key>RunAtLoad</key>
<true/>
<!-- Optional: restart if it exits -->
<key>KeepAlive</key>
<true/>
<!-- Set a working directory explicitly (recommended) -->
<key>WorkingDirectory</key>
<string>/Users/colin.powell/src/github.com/hungryroot/hungryroot</string>

View File

@ -20,10 +20,6 @@
<key>RunAtLoad</key>
<true/>
<!-- Optional: restart if it exits -->
<key>KeepAlive</key>
<true/>
<!-- Set a working directory explicitly (recommended) -->
<key>WorkingDirectory</key>
<string>/Users/colin.powell/src/github.com/hungryroot/hungryroot</string>

View File

@ -0,0 +1,54 @@
#!/bin/bash
set -euo pipefail
# --- CONFIG ---
MATCH="manage.py runserver"
PLIST="$HOME/Library/LaunchAgents/com.hungyroot.celery.plist"
ICON="🥕"
# --- Helpers ---
is_running() {
/bin/ps waux | /usr/bin/grep -F "$MATCH" | /usr/bin/grep -v grep >/dev/null 2>&1
}
# --- Menu bar title ---
if is_running; then
echo "$ICON 🟢"
else
echo "$ICON 🔴"
fi
echo "---"
# --- Actions ---
if is_running; then
echo "Stop | bash='$0' param1=stop terminal=false refresh=true"
echo "Restart | bash='$0' param1=restart terminal=false refresh=true"
else
echo "Start | bash='$0' param1=start terminal=false refresh=true"
fi
echo "---"
echo "Show matching processes | bash='$0' param1=ps terminal=true"
echo "Open plist | bash='/usr/bin/open' param1='$PLIST' terminal=false"
# --- Handler ---
ACTION="${1:-}"
case "$ACTION" in
start)
/bin/launchctl bootstrap "gui/$(id -u)" "$PLIST" 2>/dev/null || true
/bin/launchctl kickstart -k "gui/$(id -u)/$(/usr/bin/plutil -extract Label raw -o - "$PLIST")" 2>/dev/null || true
;;
stop)
# Kill only matching Celery runserver processes
/bin/ps waux | /usr/bin/grep -F "$MATCH" | /usr/bin/grep -v grep | /usr/bin/awk '{print $2}' | /usr/bin/xargs -r kill
;;
restart)
"$0" stop
sleep 0.5
"$0" start
;;
ps)
/bin/ps waux | /usr/bin/grep -F "$MATCH" | /usr/bin/grep -v grep || echo "(no matches)"
;;
esac

View File

@ -0,0 +1,64 @@
#!/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

@ -0,0 +1,77 @@
#!/bin/bash
set -euo pipefail
PLIST="$HOME/Library/LaunchAgents/com.hungryroot.django.plist"
ICON="🔌"
MATCH="manage.py runserver"
LABEL="$(/usr/bin/plutil -extract Label raw -o - "$PLIST" 2>/dev/null || true)"
UID_NUM="$(/usr/bin/id -u)"
DOMAIN="gui/$UID_NUM"
TARGET="$DOMAIN/$LABEL"
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}'
}
# --- Title ---
if is_running; then
echo "$ICON 🟢"
else
echo "$ICON 🔴"
fi
echo "---"
if is_running; then
echo "Stop | bash='$0' param1=stop terminal=false refresh=true"
echo "Restart | bash='$0' param1=restart terminal=false refresh=true"
else
echo "Start | bash='$0' param1=start terminal=false refresh=true"
fi
echo "---"
echo "Open http://0.0.0.0:8000 | href=http://0.0.0.0:8000"
echo "Debug | bash='$0' param1=debug terminal=true"
echo "Open plist | bash='/usr/bin/open' param1='$PLIST' terminal=false"
ACTION="${1:-}"
case "$ACTION" in
start)
[[ -n "${LABEL:-}" ]] || {
echo "ERROR: couldn't read Label from $PLIST" >&2
exit 1
}
/bin/launchctl bootstrap "$DOMAIN" "$PLIST" 2>/dev/null || true
/bin/launchctl kickstart -k "$TARGET" 2>/dev/null || true
;;
stop)
# THIS is the important part: unload the LaunchAgent so it wont restart.
[[ -n "${LABEL:-}" ]] || exit 0
/bin/launchctl bootout "$TARGET" 2>/dev/null || true
# Optional cleanup: kill any remaining process that matches
pids | /usr/bin/xargs -r kill -TERM 2>/dev/null || true
;;
restart)
"$0" stop
sleep 0.5
"$0" start
;;
debug)
echo "PLIST: $PLIST"
echo "LABEL: $LABEL"
echo "TARGET: $TARGET"
echo
echo "=== launchctl print (may fail in SwiftBar, still useful) ==="
/bin/launchctl print "$TARGET" 2>&1 || true
echo
echo "=== matching processes ==="
/bin/ps waux | /usr/bin/grep -F "$MATCH" | /usr/bin/grep -v grep || echo "(no matches)"
;;
esac