Files
dotfiles/swiftbar/.config/swfitbar/colima-toggle.3s.sh

65 lines
1.5 KiB
Bash
Executable File

#!/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