#!/usr/bin/env bash
set -euo pipefail
is_blocked_all() { rfkill list | awk '/Soft blocked:/{c++;/yes/&&y++} END{exit !(c>0 && c==y)}'; }
print() {
  if is_blocked_all; then
    echo '{"text":"✈","class":"on","tooltip":"Airplane mode: ON (click to disable)"}'
  else
    echo '{"text":"✈","class":"off","tooltip":"Airplane mode: OFF (click to enable)"}'
  fi
}
case "${1:---print}" in
  --toggle)
    if is_blocked_all; then rfkill unblock all; else rfkill block all; fi
    ;;
  --print) : ;;
  *) echo "Usage: $0 [--toggle|--print]"; exit 1 ;;
esac
print

