colima-toggle.3s.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. set -euo pipefail
  3. # --- CONFIG ---
  4. ICON="🐳"
  5. # Use your preferred match; consider "colima start" if "-f" isn't always present
  6. MATCH='colima start -f'
  7. # If brew is not in PATH for SwiftBar, hardcode it:
  8. BREW="/opt/homebrew/bin/brew"
  9. [[ -x "$BREW" ]] || BREW="/usr/local/bin/brew"
  10. is_running() {
  11. /bin/ps waux | /usr/bin/grep -F "$MATCH" | /usr/bin/grep -v grep >/dev/null 2>&1
  12. }
  13. pids() {
  14. /bin/ps waux | /usr/bin/grep -F "$MATCH" | /usr/bin/grep -v grep | /usr/bin/awk '{print $2}'
  15. }
  16. # --- Menu bar title ---
  17. if is_running; then
  18. echo "$ICON 🟢"
  19. else
  20. echo "$ICON 🔴"
  21. fi
  22. echo "---"
  23. # --- Actions ---
  24. if is_running; then
  25. echo "Stop (brew services) | bash='$0' param1=stop terminal=false refresh=true"
  26. echo "Restart | bash='$0' param1=restart terminal=false refresh=true"
  27. else
  28. echo "Start (brew services) | bash='$0' param1=start terminal=false refresh=true"
  29. fi
  30. echo "---"
  31. echo "Debug (brew services info) | bash='$0' param1=info terminal=true"
  32. echo "Show matching processes | bash='$0' param1=ps terminal=true"
  33. ACTION="${1:-}"
  34. case "$ACTION" in
  35. start)
  36. "$BREW" services start colima || true
  37. ;;
  38. stop)
  39. "$BREW" services stop colima || true
  40. ;;
  41. restart)
  42. "$BREW" services restart colima || true
  43. ;;
  44. info)
  45. echo "BREW: $BREW"
  46. echo
  47. "$BREW" services info colima 2>&1 || true
  48. echo
  49. echo "=== brew services list (filtered) ==="
  50. "$BREW" services list 2>&1 | /usr/bin/grep -i colima || true
  51. ;;
  52. ps)
  53. /bin/ps waux | /usr/bin/grep -F "$MATCH" | /usr/bin/grep -v grep || echo "(no matches)"
  54. ;;
  55. esac