#!/usr/bin/env bash
set -euo pipefail
status() { nmcli -t -f WIFI g | awk -F: '{print $1}'; }  # enabled/disabled
print() {
  s="$(status)"
  if [ "$s" = "enabled" ]; then
    echo '{"text":"","class":"on","tooltip":"Wi-Fi: enabled (click to toggle)"}'
  else
    echo '{"text":"","class":"off","tooltip":"Wi-Fi: disabled (click to toggle)"}'
  fi
}
case "${1:---print}" in
  --toggle) [ "$(status)" = "enabled" ] && nmcli radio wifi off || nmcli radio wifi on ;;
  --print) : ;;
  *) echo "Usage: $0 [--toggle|--print]"; exit 1 ;;
esac
print

